说明
- 官网地址:
https://mediapipe.dev/index.html
https://google.github.io/mediapipe/
- GitHub地址
https://github.com/google/mediapipe.git
安装流程
我的环境是macOS,其他系统按照官方文档都比较简单;
官方安装地址:
https://google.github.io/mediapipe/getting_started/install.html
安装步骤如下:
- 安装Homebrew和Xcode
Homebrewke可以用官方和国内两个地址下载:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
或
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
Xcode通过App Store
xcode-select --install.
- Bazelisk
brew install bazelisk
- 下载mediapipe
git clone https://github.com/google/mediapipe.git
cd mediapipe
- 安装 OpenCV 和 FFmpeg
brew install opencv@3
brew uninstall --ignore-dependencies glog
- 安装Python 3
brew install python
sudo ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python
python --version
---> Python 3.7.4
pip3 install --user six
- 下载Android SDK和NDK
用自带的脚本运行十分好用,xxx我用的是mediapipe的根目录,放在一起好管理;
chmod 777 ./setup_android_sdk_and_ndk.sh
bash ./setup_android_sdk_and_ndk.sh xxx/Android/Sdk xxx/Android/Ndk r21
- 打包apk
我需要用人像分离所以,打的人像分离的包
bazel build -c opt --config=android_arm64 mediapipe/examples/android/src/java/com/google/mediapipe/apps/selfiesegmentationgpu:selfiesegmentationgpu
- 打包aar给项目用
新建打包目录
mkdir mediapipe/examples/android/src/java/com/google/mediapipe/apps/build_aar
vim mediapipe/examples/android/src/java/com/google/mediapipe/apps/build_aar/BUILD
粘贴下面内容(还是用selfiesegmentation):
load("//mediapipe/java/com/google/mediapipe:mediapipe_aar.bzl", "mediapipe_aar")
mediapipe_aar(
name = "mp_mediapipe_selfie_segmentation",
calculators = ["//mediapipe/graphs/selfie_segmentation:selfie_segmentation_gpu_deps"]
)
执行
bazel build -c opt --strip=ALWAYS \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--fat_apk_cpu=arm64-v8a,armeabi-v7a \
--legacy_whole_archive=0 \
--features=-legacy_whole_archive \
--copt=-fvisibility=hidden \
--copt=-ffunction-sections \
--copt=-fdata-sections \
--copt=-fstack-protector \
--copt=-Oz \
--copt=-fomit-frame-pointer \
--copt=-DABSL_MIN_LOG_LEVEL=2 \
--linkopt=-Wl,--gc-sections,--strip-all \
//mediapipe/examples/android/src/java/com/google/mediapipe/apps/build_aar:mp_mediapipe_selfie_segmentation