mediapipe icon indicating copy to clipboard operation
mediapipe copied to clipboard

Error when building facemesh example on M1 mac

Open Nibosi0501 opened this issue 1 year ago • 7 comments

OS Platform and Distribution

M1 MacBook Air, macOS Monterey

Compiler version

Apple clang version 13.1.6 (clang-1316.0.21.2.3)

Programming Language and version

C++

Installed using virtualenv? pip? Conda?(if python)

on m1 mac

MediaPipe version

Latest version as at 26 April 2024.

Bazel version

7.1.1

XCode and Tulsi versions (if iOS)

13.3.1

Android SDK and NDK versions (if android)

No response

Android AAR (if android)

None

OpenCV version (if running on desktop)

4

Describe the problem

Face_mesh cannot be built.

Complete Logs

when I run the command

bazel run --define MEDIAPIPE_DISABLE_GPU=1 \
    mediapipe/examples/desktop/face_mesh:face_mesh_cpu

It comes error

mediapipe/examples/desktop/face_mesh:face_mesh_cpu
WARNING: /Users/k22137kk/mediapipe/mediapipe/framework/BUILD:69:24: in cc_library rule //mediapipe/framework:calculator_cc_proto: target '//mediapipe/framework:calculator_cc_proto' depends on deprecated target '@com_google_protobuf//:cc_wkt_protos': Only for backward compatibility. Do not use.
WARNING: /Users/k22137kk/mediapipe/mediapipe/framework/tool/BUILD:200:24: in cc_library rule //mediapipe/framework/tool:field_data_cc_proto: target '//mediapipe/framework/tool:field_data_cc_proto' depends on deprecated target '@com_google_protobuf//:cc_wkt_protos': Only for backward compatibility. Do not use.
INFO: Analyzed target //mediapipe/examples/desktop/face_mesh:face_mesh_cpu (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /Users/k22137kk/mediapipe/mediapipe/util/BUILD:165:11: Compiling mediapipe/util/annotation_renderer.cc failed: (Exit 1): wrapped_clang_pp failed: error executing command (from target //mediapipe/util:annotation_renderer) external/local_config_cc/wrapped_clang_pp '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -O0 -DDEBUG '-std=c++11' ... (remaining 71 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from mediapipe/util/annotation_renderer.cc:15:
In file included from ./mediapipe/util/annotation_renderer.h:20:
./mediapipe/framework/port/opencv_core_inc.h:18:10: fatal error: 'opencv2/core/version.hpp' file not found
#include <opencv2/core/version.hpp>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Error in child process '/usr/bin/xcrun'. 1
Target //mediapipe/examples/desktop/face_mesh:face_mesh_cpu failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.925s, Critical Path: 0.80s
INFO: 94 processes: 90 internal, 4 darwin-sandbox.
FAILED: Build did NOT complete successfully
ERROR: Build failed. Not running target

Nibosi0501 avatar Apr 25 '24 17:04 Nibosi0501

Change your opencv path in the .build file

FunnyWii avatar Apr 26 '24 02:04 FunnyWii

What specific paths should be used?

Current WORKSPACE

new_local_repository(
    name = "macos_opencv",
    build_file = "@//third_party:opencv_macos.BUILD",
    # For local MacOS builds, the path should point to an opencv@3 installation.
    # If you edit the path here, you will also need to update the corresponding
    # prefix in "opencv_macos.BUILD".
    # path = "/usr/local",  # e.g. /usr/local/Cellar for HomeBrew
    path = "/opt/homebrew",
)

new_local_repository(
    name = "macos_ffmpeg",
    build_file = "@//third_party:ffmpeg_macos.BUILD",
    #path = "/usr/local/opt/ffmpeg",
    path = "/opt/homebrew/opt/ffmpeg",
)

Nibosi0501 avatar Apr 26 '24 03:04 Nibosi0501

No idea about MACOS OpenCV Path, but according to you err msg, the opencv header file is not found.

FunnyWii avatar Apr 26 '24 03:04 FunnyWii

Is there a command-like way to find the OpenCV path? OpenCV was included with Homebrew.

Nibosi0501 avatar Apr 26 '24 03:04 Nibosi0501

$ brew --prefix opencv
/opt/homebrew/opt/opencv

Nibosi0501 avatar Apr 26 '24 04:04 Nibosi0501

Hi @Nibosi0501,

To resolve the issue, please ensure that the path to OpenCV is added correctly in the Workspace. You need to do changes here: https://github.com/google/mediapipe/blob/master/WORKSPACE#L382

and https://github.com/google/mediapipe/blob/master/WORKSPACE#L391.

If this still an issue, you can modify the path in the macos_opencv repository. Change the path to point to your Homebrew directory, specifically if it contains opencv@3 within the homebrew/opt directory. Avoid adding /opt/opencv@3 and also adjust the ffmpeg path to point to /opt/homebrew/opt/ffmpeg, as shown in the attached screenshot below.

Screenshot 2024-04-30 at 12 51 27 PM

Thank you!!

kuaashish avatar Apr 30 '24 07:04 kuaashish

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar May 08 '24 01:05 github-actions[bot]

This issue was closed due to lack of activity after being marked stale for past 7 days.

github-actions[bot] avatar May 15 '24 01:05 github-actions[bot]