mediapipe u3dplugin使用记录

吐槽:首次遇到这么难的编程,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

使用GSAP(GreenSock Animation Platform)可以轻松实现小球的不规则移动。下面是一些示例代码: 首先,您需要在Flex项目中添加GSAP库。可以通过以下方式将库添加到您的项目中: ``` <mx:Script> <![CDATA[ import com.greensock.TweenMax; import com.greensock.easing.*; ]]> </mx:Script> ``` 接下来,您需要创建一个小球并将其添加到舞台上。可以使用以下代码创建一个小球: ``` <fx:Declarations> <s:Ellipse id="ball" width="50" height="50"> <s:fill> <s:SolidColor color="#FF0000"/> </s:fill> </s:Ellipse> </fx:Declarations> <s:Group id="container" width="100%" height="100%"> <s:Group id="ballContainer" width="100%" height="100%"> <s:Group width="100%" height="100%" clipAndEnableScrolling="false"> <s:Group id="movementPath"> <!-- Define the movement path of the ball here --> </s:Group> <s:Group id="ballGroup" x="0" y="0" width="100%" height="100%"> <s:Group id="ballStart" x="0" y="0" width="100%" height="100%"> <s:layout> <s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/> </s:layout> <s:Label text="Click to Start Movement" click="startMovement()"/> </s:Group> <s:Group id="ballEnd" x="0" y="0" width="100%" height="100%"> <s:layout> <s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/> </s:layout> <s:Label text="Movement Completed" visible="false"/> </s:Group> <s:Group id="ballPath" x="0" y="0" width="100%" height="100%" visible="false"> <s:layout> <s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/> </s:layout> {ball} </s:Group> </s:Group> </s:Group> </s:Group> </s:Group> ``` 在上面的代码中,我们在Flex项目中创建了一个小球,并将其添加到舞台上。我们还创建了一个包含球的容器组和一个用于定义球运动路径的组。 现在,我们需要定义球的运动路径。我们可以使用GSAP的PathPlugin来定义不规则路径。以下是一个示例路径: ``` <mx:Script> <![CDATA[ import com.greensock.plugins.*; TweenPlugin.activate([BezierPlugin, BezierThroughPlugin, MorphSVGPlugin, MotionBlurPlugin, Physics2DPlugin, PhysicsPropsPlugin, ScrambleTextPlugin, ScrollToPlugin, TextPlugin]); private function startMovement():void { ballStart.visible = false; ballEnd.visible = false; ballPath.visible = true; var path:SVGPath = new SVGPath(); path.draw("M 0,0 L 0,200 C 0,200 100,300 300,300 C 500,300 600,200 600,200 L 600,0 Z"); var ballPathTween:TweenMax = TweenMax.to(ball, 5, { bezier: { curviness: 1.5, values: path.getBezier(50), autoRotate: true }, ease: Linear.easeNone, onComplete: movementComplete }); } private function movementComplete():void { ballEnd.visible = true; } ]]> </mx:Script> ``` 在上面的代码中,我们使用SVGPath对象定义了一个不规则路径。然后,我们使用TweenMax对象创建一个球的动画,将其沿着路径移动,并在完成后调用movementComplete()函数。 现在,当用户单击“Click to Start Movement”按钮时,球将开始沿着不规则路径移动,直到到达路径的末端。完成后,球将停止并显示“Movement Completed”标签。 希望这可以帮助您实现不规则移动的小球。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值