-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for desktop examples on MacOS (Apple Silicon M1=arm64/ x86_64/ i386) #2591
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
|
||
2. Build all available examples under mediapipe/examples/desktop: | ||
```bash | ||
bash build_macos_desktop_examples.sh --cpu x86_64 -b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super helpful I finally got helloworld to build on my m1 but any help with:
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_detection:face_detection_cpu failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.591s, Critical Path: 1.41s
INFO: 175 processes: 131 internal, 44 darwin-sandbox.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgebhard try modifiy the third_party/opencv_macos.BUILD :
--- a/third_party/opencv_macos.BUILD
+++ b/third_party/opencv_macos.BUILD
@@ -19,8 +19,8 @@ cc_library(
"lib/libopencv_videoio.dylib",
],
),
- hdrs = glob(["include/opencv2/**/*.h*"]),
- includes = ["include/"],
+ hdrs = glob(["include/opencv4/opencv2/**/*.h*"]),
+ includes = ["include/opencv4/"],
linkstatic = 1,
visibility = ["//visibility:public"],
)
@walkoncross Thanks a ton for this! Hopefully it gets merged soon. NOTE: My original solution doesn't work because Bazel doesn't allow selects for repository paths, but the following solution works: In new_local_repository(
name = "macos_opencv",
build_file = "@//third_party:opencv_macos.BUILD",
path = "/usr/local/opt/opencv@3",
)
new_local_repository(
name = "macos_arm64_opencv",
build_file = "@//third_party:opencv_macos.BUILD",
path = "/opt/homebrew/opt/opencv@3",
)
new_local_repository(
name = "macos_ffmpeg",
build_file = "@//third_party:ffmpeg_macos.BUILD",
path = "/usr/local/opt/ffmpeg@4",
)
new_local_repository(
name = "macos_arm64_ffmpeg",
build_file = "@//third_party:ffmpeg_macos.BUILD",
path = "/opt/homebrew/opt/ffmpeg@4",
) Then, in alias(
name = "opencv_binary",
actual = select({
"//mediapipe:android_x86": "@android_opencv//:libopencv_x86",
"//mediapipe:android_x86_64": "@android_opencv//:libopencv_x86_64",
"//mediapipe:android_armeabi": "@android_opencv//:libopencv_armeabi-v7a",
"//mediapipe:android_arm": "@android_opencv//:libopencv_armeabi-v7a",
"//mediapipe:android_arm64": "@android_opencv//:libopencv_arm64-v8a",
"//mediapipe:ios": "@ios_opencv//:opencv",
"//mediapipe:macos_x86_64": "@macos_opencv//:opencv",
"//mediapipe:macos_arm64": "@macos_arm64_opencv//:opencv",
"//mediapipe:windows": "@windows_opencv//:opencv",
"//conditions:default": "@linux_opencv//:opencv",
}),
)
cc_library(
name = "libffmpeg",
visibility = ["//visibility:public"],
deps = select({
"//mediapipe:android_x86": [],
"//mediapipe:android_x86_64": [],
"//mediapipe:android_armeabi": [],
"//mediapipe:android_arm": [],
"//mediapipe:android_arm64": [],
"//mediapipe:ios": [],
"//mediapipe:macos_x86_64": [
"@macos_ffmpeg//:libffmpeg",
],
"//mediapipe:macos_arm64": [
"@macos_arm64_ffmpeg//:libffmpeg",
],
"//conditions:default": [
"@linux_ffmpeg//:libffmpeg",
],
}),
) Anyway, that lets you build easily on x86 or arm64 macOS without having to edit any build files, which should hopefully make it easier for the project to provide official macOS arm64 wheels. That said, with the changes in this PR (and my edits above) I can install mediapipe with
If I update the OpenCV source version to 3.4.16 I can get past it (see this OpenCV issue: opencv/opencv#18541), but then I run into the same bizarre |
Would be great if mediapipe releases M1 packages officially. I managed to create a fully automated script to build version Here the repository with the build: https://github.com/cansik/mediapipe-silicon |
Fantastic, thanks for putting this together! Will vastly simplify the setup and install process for anything that depends on mediapipe. For my use-case (extracting the x/y coordinates of face regions for cognitive face processing research), I can't realistically expect colleagues to set up and troubleshoot a compiler environment just to run a script, so having pre-built wheels is extremely useful. |
Thank you for your contribution! We have integrated the required changes from your PR. We now support M1 for iOS and Android builds (Python support is available via Rosetta). |
to ‘macos_x86_64’;