'Getting error while running mediapipe on macOS; Building C++ command-line example apps

I am trying to use mediapipe for a university project and have installed it, even successfully ran the Hello World! in C++ example app but when I am trying to build the C++ command-line example, it is giving me errors.

I ran this:

bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu

and the result I got is this:

DEBUG: /private/var/tmp/_bazel_kanzashaikh/c191ae13e9137350b50f6a19ce94bf21/external/rules_foreign_cc/workspace_definitions.bzl:15:10: WARNING: This branch is deprecated and no longer recieving updates. Please update to main or choose a specific commit to pin in your workspace. INFO: Build option --compilation_mode has changed, discarding analysis cache. ERROR: Error fetching repository: java.io.IOException: The repository's path is "/usr/local/opt/opencv@3" (absolute: "/usr/local/opt/opencv@3") but this directory does not exist. ERROR: /Users/kanzashaikh/development/mediapipe/third_party/BUILD:178:6: //third_party:opencv_binary depends on @macos_opencv//:opencv in repository @macos_opencv which failed to fetch. no such package '@macos_opencv//': The repository's path is "/usr/local/opt/opencv@3" (absolute: "/usr/local/opt/opencv@3") but this directory does not exist. ERROR: Analysis of target '//mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu' failed; build aborted: Analysis failed INFO: Elapsed time: 0.194s INFO: 0 processes. FAILED: Build did NOT complete successfully (0 packages loaded, 237 targets co nfigured)

How do I solve it?



Solution 1:[1]

before building desktop examples, you should setup opencv. also for android examples you should setup android sdk and ndk. there is a builtin script for setting up opencv and you can execute it. for setting up opencv:

bash setup_opencv.sh

and for android sdk and ndk:

bash setup_android_sdk_and_ndk.sh

Solution 2:[2]

I am assuming you are running a M1 machine, as Homebrew is now installing Intel binaries under /usr/local and ARM ones under /opt/homebrew.

In your case, when building, bazel is looking for opencv@3 package at /usr/local/opt/opencv@3 and immediately throws an error as the package is located at /opt/homebrew/opt/opencv@3.

Thus, you have two choices:

  1. Open WORKSPACE file from your bazel project and modify the path for each package accordingly
  2. Make a symbolic link to /opt/homebrew/opt in /usr/local by running: sudo ln -s /opt/homebrew/opt opt

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Milad Yousefi
Solution 2