0

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?

2 Answers2

0

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
Milad Yousefi
  • 191
  • 2
  • 9
  • I ran the setup_opencv.sh file but now it's throwing another error: "The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt. Please visit http://www.java.com for information on installing Java." I have installed jdk and have already set all the paths – Kanza Sheikh Feb 26 '21 at 13:05
  • 1
    I'm getting the same exception; I'm on a Mac, and I suspect that's the problem. Apt is for linux. I'm working through the setup_opencv.sh file manually, starting from the 'rm -rf /tmp/build_opencsv'. So far it's working, w/the exception that the cmake line needs the characters ' ..' at the end of it. Also, apparently ignore the lines having to do with ldconfig. However, there's some editing of WORKSPACE and third_party/opencv_* that I can't map to macos. tl;dr: if you're on a Mac, the setup_opencv.sh script is not gonna work for you out of the box. Maybe the authors can help. – AbGator Feb 27 '21 at 05:35
  • 1
    I had better luck following the mac instructions at https://google.github.io/mediapipe/getting_started/install.html - I had to resolve some homebrew problems (non-homebrew openssl installation, and permission problems a la https://github.com/Homebrew/brew/issues/3228). Once I did that, I had to edit the WORKSPACE file so that the path of the opencv_macos local repository was "/usr/local/Cellar/opencv@3" (where homebrew puts it). Hope that helps. – AbGator Feb 27 '21 at 06:07
  • I followed the mac installation instructions for mediapipe and now it's working! Got an error having to do with protoc version after this though, which I solved by using 'brew uninstall --ignore-dependencies protobuf' and after this it was smooth sailing. Thank you so much, sir!! I had been at this problem for days and it is finally working! – Kanza Sheikh Mar 01 '21 at 03:54
  • While we are at it, can I also ask if you know a way to get the hand coordinates extracted in a txt format? I am running the hand tracking part and need it to train a model. – Kanza Sheikh Mar 01 '21 at 04:06
0

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
Thirsty4K
  • 68
  • 8