编译
https://icode.best/i/47225845422144
关键点位置
https://www.stubbornhuang.com/1916/
dll
https://www.stubbornhuang.com/1919/
https://github.com/HW140701/GoogleMediapipePackageDll
版本:mediapipe 0.10.18 最新版
python 3.10.2
vs 2022社区版
bazel bazel-7.4.0-windows-x86_64 最新版
opencv opencv-3.4.10-vc14_vc15
1.1 下载
下载地址: MSYS2
1.2 安装
(1) 使用默认安装目录安装,安装在目录 c:msys64, 则添加目录 C:msys64usrbin 到系统 Path 环境变量中;
(2) 安装完成后,打开MSYS,执行下面两步更新数据:
pacman -Syu
pacman -Su
(3)安装其他工具包:
pacman -S git patch unzip
2.1 安装
下载地址:Python
安装时选择最下面的 添加到Path环境变量
2.2 安装相关包
使用以下命令安装numpy和six这两个包
pip install numpy
pip install six
2022也行
可以安装Visual Studio 2019 或者更新版本。 安装Visual Studio时,“单个组件”里注意要勾选Windows 10 SDK。
Visual Studio 2019 下载地址: Visual Studio 2019
下载社区版则可。
安装:
在单个组件栏下看看是否有勾选 Windows 10 SDK, 选哪个都行,只要勾选了就可以
4.1 安装
下载地址: Bazel
下载页面有 Pre-release 版 和 Release 版,建议使用 Release 版,写此文章时最新的Release版本为 4.2.2,下载页面拉到最下面可以找到此版本
下载完成后,建议把 bazel-4.2.2-windows-x86_64.exe 重命名为 bazel.exe,然后放入一个文件夹中,并把这个文件夹添加到系统Path环境变量中。
例如我放到 C:bazel 这个目录,则把 C:bazel 添加到系统Path环境变量中。
环境变量设置完后, 在cmd中使用 bazel version 查看版本,能查到版本信息则表示安装成功
4.2 设置 Bazel 环境变量
BAZEL_VS
BAZEL_VC
BAZEL_VC_FULL_VERSION
BAZEL_WINSDK_FULL_VERSION
4.2.1 BAZEL_VS
VS安装目录
(1)如果安装的Visual Studio Community 2019, 则设置 C:Program Files (x86)Microsoft Visual Studio2019Community
(2)如果安装的Visual Studio Enterprise 2019, 则设置 C:Program Files (x86)Microsoft Visual Studio2019Enterprise
(3)其他。 版本依照此规则填写,根据你实际安装的版本和目录来填写
4.2.2 BAZEL_VC
与BAZEL_VS类似,只是后面加一个 VC
4.2.3 BAZEL_VC_FULL_VERSION
填写此文件夹下的目录名
C:Program Files (x86)Microsoft Visual Studio2019CommunityVCToolsMSVC 在这里插入图片描述
4.2.4 BAZEL_WINSDK_FULL_VERSION
有如下几种方法查找:
(1)安装VS时勾选的 Windows 10 SDK 版本;
(2)控制面板 -> 程序 -> 程序与功能,里面找到 Windows Software Development Kit,版本号如下图所示这里,不过版本号最后一位应该填写 0, 比如这里版本号是 10.0.19041.685,则应填写成 10.0.19041.0 , 有多个版本的情况下,填写其中一个则可
在这里插入图片描述
(3)在目录 C:Program Files (x86)Windows Kits10bin 下查看
在这里插入图片描述
下载地址: OpenCV
目前MediaPipe使用的OpenCV版本为3.4.10,找到Windows版本下载安装即可
使用git指令下载:
git clone https://github.com/google/mediapipe.git
下载完后,打开 WORKSPACE 文件,修改 windows_opencv 的目录
new_local_repository 修改opencv路径
cd mediapipe
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C:/Python310/python.exe" mediapipe/examples/desktop/hello_world
其中 PYTHON_BIN_PATH=“C:/Users/vm/AppData/Local/Programs/Python/Python310/ python.exe” 为Python的安装目录,根据自己Python安装目录填
set GLOG_logtostderr=1
bazel-binmediapipeexamplesdesktophello_worldhello_world.exe
结果是几行helloworld
原因:获取不到真实的python版本
解决:打开错误提示的文件C:UsersAdministrator_bazel_Administrator3vmcl3ouexternalorg_tensorflowthird_partypypython_repo.bzl
把python3改为python
version = ctx.os.environ.get("HERMETIC_PYTHON_VERSION", "")
后面加一句 version = "Python 3.10.2"
bazel clean --expunge
编译helloworld
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C:/Python312/python.exe" mediapipe/examples/desktop/hello_world
测试hello_world运行
set GLOG_logtostderr=1
bazel-binmediapipeexamplesdesktophello_worldhello_world.exe
至此,已能正常运行helloworld
*hand_tracking
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C:/Python312/python.exe" mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu
set GLOG_logtostderr=1
bazel-binmediapipeexamplesdesktophand_trackinghand_tracking_cpu.exe --calculator_graph_config_file=mediapipegraphshand_trackinghand_tracking_desktop_live.pbtxt
*face_detection
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C:/Python312/python.exe" mediapipe/examples/desktop/face_detection:face_detection_cpu
set GLOG_logtostderr=1
bazel-binmediapipeexamplesdesktopface_detectionface_detection_cpu.exe --calculator_graph_config_file=mediapipegraphsface_detectionface_detection_desktop_live.pbtxt
*object_detection
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C:/Python312/python.exe" mediapipe/examples/desktop/object_detection:object_detection_cpu
set GLOG_logtostderr=1
bazel-binmediapipeexamplesdesktopobject_detectionobject_detection_cpu.exe --calculator_graph_config_file=mediapipegraphsobject_detectionobject_detection_desktop_live.pbtxt
*object_tracking
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C:/Python312/python.exe" mediapipe/examples/desktop/object_tracking:object_tracking_cpu
set GLOG_logtostderr=1
bazel-binmediapipeexamplesdesktopobject_trackingobject_tracking_cpu.exe --calculator_graph_config_file=mediapipegraphstrackingobject_detection_tracking_desktop_live.pbtxt
*iris_tracking
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C:/Python312/python.exe" mediapipe/examples/desktop/iris_tracking:iris_tracking_cpu
set GLOG_logtostderr=1
bazel-binmediapipeexamplesdesktopiris_trackingiris_tracking_cpu.exe --calculator_graph_config_file=mediapipegraphsiris_trackingiris_tracking_cpu.pbtxt
*hair_segmentation
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C:/Python312/python.exe" mediapipe/examples/desktop/hair_segmentation:hair_segmentation_cpu
set GLOG_logtostderr=1
bazel-binmediapipeexamplesdesktophair_segmentationhair_segmentation_cpu.exe --calculator_graph_config_file=mediapipegraphshair_segmentationhair_segmentation_desktop_live.pbtxt
*另一组 编译命令
bazel build -c opt --action_env PYTHON_BIN_PATH="C:/Python312/python.exe" --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/selfie_segmentation:selfie_segmentation_cpu
运行命令
摄像头
bazel-binmediapipeexamplesdesktopselfie_segmentationselfie_segmentation_cpu --calculator_graph_config_file=mediapipegraphsselfie_segmentationselfie_segmentation_cpu.pbtxt
或者输入视频
bazel-binmediapipeexamplesdesktopselfie_segmentationselfie_segmentation_cpu --calculator_graph_config_file=mediapipegraphsselfie_segmentationselfie_segmentation_cpu.pbtxt --input_video_path=D:dataWtestImgvideotestWen02.mp4 --output_video_path=bazel-binmediapipeexamplesdesktopselfie_segmentationtestWen02_out.mp4
[ WARN:0] terminating async callback
errors:
Calculator::Open() for node
Can't find file: mediapipe/modules/palm_detection/palm_detection_full.tflite
拷贝tflite文件:c:mediapipemediapipebazel-outx64_windows-optbinmediapipemodules目录下的tflite文件,需要复制到c:mediapipemediapipemodules\
或下载tflite文件:https://github.com/google-ai-edge/mediapipe/blob/master/docs/solutions/models.md
(下载需美国ip)
http://139.196.53.116/ml/index.php/archives/1487/
*release
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C:/Python312/python.exe" mediapipe/examples/desktop/holistic_tracking_dll:MediapipeHolisticTracking --verbose_failures
*debug
bazel build -c dbg --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C:/Python312/python.exe" mediapipe/examples/desktop/holistic_tracking_dll:MediapipeHolisticTracking --verbose_failures
bazel clean --expunge
Python 3.12.1
============
Error in fail: Failed to execute overlay script: 'C:/Python312/python.exe C:/users/54861/_bazel_54861/3vmcl3ou/external/llvm-raw/utils/bazel/overlay_directories.py --src C:/users/54861/_bazel_54861/3vmcl3ou/external/llvm-raw --overlay C:/users/54861/_bazel_54861/3vmcl3ou/external/llvm-raw/utils/bazel/llvm-project-overlay --target .'
启用 Windows 开发者模式
如果你无法或不希望使用管理员权限,可以启用 Windows 的开发者模式,这样普通用户也可以创建符号链接。
打开 设置。
依次转到 更新和安全 > 开发者选项。
在“开发者模式”下,启用“开发者模式”并确认。
重启计算机。
再次运行你的命令。
===============
Error: interpreter_path 要用absolute path
C:/users/54861/_bazel_54861/3vmcl3ou/external/local_execution_config_python/BUILD
py_runtime(
name = "py2_runtime",
interpreter_path = "C:/Python312/python.exe", # 绝对路径 interpreter_path = native.path_to_absolute("path/to/interpreter")
files = [],
)
py_runtime(
name = "py3_runtime",
interpreter_path = "C:/Python312/python.exe", # 绝对路径 interpreter_path = native.path_to_absolute("path/to/interpreter")
files = [],
)
==========================
ERROR: C:/users/54861/_bazel_54861/3vmcl3ou/external/org_tensorflow/tensorflow/lite/kernels/BUILD:863:11: Compiling tensorflow/lite/kernels/stablehlo_reduce_window.cc failed: (Exit 2): cl.exe failed: error executing CppCompile command (from target @@org_tensorflow//tensorflow/lite/kernels:builtin_op_kernels) C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.38.33130binHostX64x64cl.exe ... (remaining 1 argument skipped)
bazel build --verbose_failures @@org_tensorflow//tensorflow/lite/kernels:builtin_op_kernels
根据网站https://github.com/tensorflow/tensorflow/issues/64376 以下操作
C:Users54861_bazel_548613vmcl3ouexternalorg_tensorflowtensorflowlitekernelsstablehlo_reduce_window.cc 替换下载的stablehlo_reduce_window.txt
==========================================
ERROR: C:/mediapipe/mediapipe/examples/desktop/holistic_tracking_dll/BUILD:27:10: Compiling mediapipe/examples/desktop/holistic_tracking_dll/GestureRecognition.cpp failed: (Exit 2): cl.exe failed: error executing CppCompile command (from target //mediapipe/examples/desktop/holistic_tracking_dll:MediapipeHolisticTracking)
mediapipe/examples/desktop/holistic_tracking_dll/GestureRecognition.cpp(19): error C2065: ��thumb_vec1��: δ�����ı�ʶ��
在GestureRecognition.h中,有一个循环包含,即#include "GestureRecognition.h",这会导致编译器无法正确解析头文件。应该删除这个循环包含。
所有中文注释后面回车前面加个空格
========================
mediapipe/examples/desktop/holistic_tracking_dll/ArmUpAndDownRecognition.cpp(28): error C2181: û��ƥ�� if �ķǷ� else
所有中文注释后面回车前面加个空格
========================================
mediapipe/examples/desktop/holistic_tracking_dll/HolisticTrackingDetect.cpp(381): error C2065:
所有中文注释后面回车前面加个空格
================================
编译成功后执行失败:
初始化模型成功
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
W0000 00:00:1731578341.276134 3884 inference_feedback_manager.cc:114] Feedback manager requires a model with a single signature inference. Disabling support for feedback tensors.
Mediapipe_Holistic_Tracking_Detect_Frame_Direct执行失败
一些可以发掘的编译设置
https://blog.csdn.net/qq_58611650/article/details/125847990
https://www.cnblogs.com/WenJXUST/p/16337724.html
https://blog.csdn.net/magic_ll/article/details/125845885