吐槽:首次遇到这么难的编程,80%时间花在了网络传输上,不过且行且珍惜,生活还得继续

mediapipeplugin 地址:https://github.com/homuler/MediapipeUnityPlugin
安装指示页:https://github.com/homuler/MediaPipeUnityPlugin/wiki/Installation-Guide

最新版(截止20221008)只需要3步骤即可编译windows版本(可能需要科学上网):

1)安装docker

2)将docker切换为windows

3)在cmd命令行中运行build container指令(需要切换工作目录到工程根目录):

docker build -t mediapipe_unity:windows . -f docker/windows/x86_64/Dockerfile

4)在cmd中运行命令,同时切换到container(容器)中:

docker run --cpus=16 --memory=32g --mount type=bind,src=%CD%\Packages,dst=C:\mediapipe\Packages --mount type=bind,src=%CD%\Assets,dst=C:\mediapipe\Assets -it mediapipe_unity:windows

注意:不能修改dst目录(这是需要映射到容器中去的目录),否则会报错:hcsshim::System::Start: failure in a Windows system call: The virtual machine or container exited unexpectedly. (0xc0370106).

5)在容器中运行编译指令:

python build.py build --desktop cpu --opencv cmake -vv
Rem or if you'd like to link OpenCV dynamically
python build.py build --desktop cpu -vv

以下时老版本安装记录,可以做经验:

1. 安装docker

再安装wsl2, 完了之后,提示 WSL2安装不完整,原因是没有安装unbutu ,需要去微软商店下载安装,但是太慢。改成dns 4.2.2.1 4.2.2.2
https://docs.microsoft.com/zh-cn/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package

下载之后运行发现是缺少linux核心库,提示错误:WslRegisterDistribution failed with error: 0x800701bc
造成该问题的原因是WSL版本由原来的WSL1升级到WSL2后,内核没有升级,前往微软WSL官网下载安装适用于 x64 计算机的最新 WSL2 Linux 内核更新包即可。

下载链接:https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

另外wsl2官方文件推荐地址是:The default kernel used can be found at https://github.com/microsoft/WSL2-Linux-Kernel


docker build -t mediapipe_unity:windows . -f docker/windows/x86_64/Dockerfile
出现 no linux/AMD86_64 manifest 错误就是没有把docker切换到windows环境


设置代理之后,依然会出现 installing p7zip这一步卡住十多个小时,
好在docker文件还有提示,可以这样操作: This command may hang and in that case, "C:\ProgramData\Docker\tmp\hcs*\Files\$Recycle.Bin\" should be removed manually.
原因是docker有bug,会死循环访问缓存(老外的观察能力还是好的)issue地址:https://github.com/docker/for-win/issues/8910

科大镜像:https://docker.mirrors.ustc.edu.cn/
网易:https://hub-mirror.c.163.com/
阿里云:https://<你的ID>.mirror.aliyuncs.com
七牛云加速器:https://reg-mirror.qiniu.com

常用的镜像加速地址:(国内的保存镜像的仓库,很快)
  http://aad0405c.m.daocloud.io
  https://registry.docker-cn.com
  http://hub-mirror.c.163.com
  https://3laho3y3.mirror.aliyuncs.com
  http://f1361db2.m.daocloud.io
  https://mirror.ccs.tencentyun.com

Docker中国区官方镜像:
https://registry.docker-cn.com

配置格式:

{
  "experimental": false,
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"],
  "data-root": "H:/dockerdata"
}


镜像好像不如科学上网,科学上网不如直接设置curl代理,设置代理不如直接手动下载每一个包,再放到本地服务器安装。
设置curl代理时不能用127.0.0.1 ip,因为这是docker自己的localhost机器ip,需要用具体的IP地址。


安装过程中遇到下载bazel时候提示,通过science上网也不行:curl: (35) schannel: failed to receive handshake, SSL/TLS connection failed
解决办法:单独下载文件,放到内网web服务器。


建立一个bat文件启动一个windows docker,下面三行放在一个bat文件中
Rem Run with `Packages` directory mounted to the container
Rem Specify `--cpus` and `--memory` options according to your machine.
docker run --cpus=2 --memory=6g --mount type=bind,src=%CD%\Packages,dst=C:\mediapipe\Packages --mount type=bind,src=%CD%\Assets,dst=C:\mediapipe\Assets -it mediapipe_unity:windows

对于android环境,需要下载一个bazel代码:
(For Android, Experimental) Apply a patch to bazel.

:bell: You can also make use of Linux containers to build libraries for Android.

Rem Run inside the container

git clone https://github.com/bazelbuild/bazel.git C:\bazel
cd C:\bazel
git checkout 4.2.1
git apply ..\mediapipe\third_party\bazel_android_fixes.diff
bazel --output_user_root=C:\_bzl build //src:bazel.exe
cp bazel-bin\src\bazel.exe C:\bin
cd C:\mediapipe

开始编译windows桌面程序(Run build command inside the container)
python build.py build --desktop cpu --opencv cmake -vv
Rem or if you'd like to link OpenCV dynamically
python build.py build --desktop cpu --include_opencv_libs -vv


此警告是否会影响最后的识别api?答:无影响
Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/XNNPACK/archive/28407b24f0
4694a1353ffca91248e89bc250eb5b.zip failed: class com.google.devtools.build.lib.bazel.repository.downloader.Unrecoverable
HttpException GET returned 404 Not Found


运行项目,还没进去就提示:com.unity.collab-proxy-1.15.1  lacks valid authentication
于是来到这个目录下,直接删掉Library\PackageCache\com.unity.collab-proxy文件夹。
同样问题: com.unity.toolchain.macos-x86_64-linux-x86_64 也有问题
这样下次重启的话还是会有这个问题。
需要找到项目根目录/Packages/manifest.json,删掉相应的行即可。

最终经过一些列网络传输等待,打开了mediapipe plugin工程。

编译linux版本(在经过了几天的尝试之后,由于网络传输原因不得不放弃本地编译,放到了HK服务器编译)

2. 在远程ubuntu下编译
首先安装docker
docker在ubuntu下安装:
首先删除老版本:sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release

添加Docker’s official GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
修改安装参数:echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
正式安装:sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

如果以上不能正常安装,可以用一键式指令安装:curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

Rem You may skip applying a patch depending on your machine settings.
Rem See https://serverfault.com/questions/1052963/pacman-doesnt-work-in-docker-image for more details.
git apply docker/linux/x86_64/pacman.patch
docker build -t mediapipe_unity:linux . -f docker/linux/x86_64/Dockerfile

# Run with `Packages` directory mounted to the container
docker run --mount type=bind,src=$PWD/Packages,dst=/home/mediapipe/Packages --mount type=bind,src=$PWD/Assets,dst=/home/mediapipe/Assets -it mediapipe_unity:latest

# Build native libraries for Desktop CPU.
# Note that you need to specify `--opencv cmake`, because OpenCV is not installed to the container.
python build.py build --desktop cpu --opencv cmake -v

# Build native libraries for Desktop GPU and Android
python build.py build --desktop gpu --android arm64 --opencv cmake -v

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐