rajkundu / libmp-example

Use Mediapipe with CMake: Example LibMP Usage Application
Apache License 2.0
20 stars 3 forks source link

LibMP is not detecting any faces. #7

Closed pedroarroyo closed 1 year ago

pedroarroyo commented 1 year ago

Running the project with no changes except setting the path to point to the rajkundu/mediapipe folder, it looks like the Process() method succeeds but we are not getting any faces detected even though there is clearly a face in view of the camera. The comment indicates this might be caused by the packet being invalid. Does this mean the data format? Would the next thing to check be if the packet data format defined in main.cpp matches the one defined in mediapipe?

if (lm_packet_ptr.get() == nullptr || mediapipe::LibMP::PacketIsEmpty(lm_packet_ptr.get())) {
    return normalized_landmarks; // return empty vector if no output packets or packet is invalid
}
rajkundu commented 1 year ago

Personally, I have never had issues with this particular part of the code; I added the above error handling in anticipation of possible errors, but not because I've actually encountered these types of errors myself. So, I would first recommend double or even triple-checking that all your input data is exactly in the format MediaPipe expects. I have only tested with RGB, 8 bits/channel (uint8_t) data. Did you double-check your data pre-processing? E.g., I once passed in BGR data just to see what would happen, and similar to your case, the graph ran without errors but returned 0 detected faces. Could something similar be going on in your case?

pedroarroyo commented 1 year ago

Hi, @rajkundu.

Thank you very much for the quick reply. I believe the issue seems to be related to the fact that the libmp example project and the mediapipe project are pointing to different versions of opencv on Linux. When I build I get the following warning:

[build] /usr/bin/ld: warning: libopencv_core.so.3.4, needed by /home/radxa/Dev/rajkundu/mediapipe/bazel-bin/mediapipe/examples/desktop/libmp/libmp.so, may conflict with libopencv_core.so.408

Would you know offhand what the best way of editing the build files in both projects so that they both point to the same opencv libraries? Ideally I would like them to point to whatever is installed in /usr/local, but I suppose the path can be arbitrary.

I've made the following edit in the CMakeLists.txt for the libmp example. Does this seem correct? What would be the corresponding edit in the mediapipe project?

elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
    set(LibMP_OpenCV_DIR "/usr/local")
#   set(LibMP_OpenCV_DIR "${MEDIAPIPE_DIR}/bazel-${MEDIAPIPE_DIRNAME}/external/linux_opencv")

Thanks again.

pedroarroyo commented 1 year ago

Hi,

In case this is helpful to anyone else.....

It looks like everything is working in Linux (Ubuntu 20.04) after building and installing latest OpenCV (4.* branch) and editing the WORKSPACE file in mediapipe so it can reference the installation in usr/local. The example doesn't seem to work with anything lower. I tried 3.4 as installed by the mediapipe setup_opencv script all the way up to 4.2 without success.

Works great now though. Closing the issue.