当前位置:   article > 正文

mediapipe实战1:安装mediaPipe_mediapipe官方文档

mediapipe官方文档

背景

项目需要用到人脸识别,手势识别,供应商报价那么高,用media试一下。

环境安装

wsl安装

目前window不支持安卓应用,所以使用了windows的Linux子系统。国内首先换源,推荐阿里或者清华的。
Ubuntu20.04:

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security multiverse
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

官方文档:https://docs.microsoft.com/en-us/windows/wsl/install

第一次用踩了一些坑。

  1. 启动时提示:WslRegisterDistribution failed with error
    解决方法:安装更新包:https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

  2. 启动时提示:参考的对象类型不支持尝试的操作
    解决方法:cmd执行 netsh winsock reset

互传文件

windows所有的磁盘自动挂载在 /mnt/下面,可以很方便的直接用cp命令拷文件。

安装bazel

官方文档:https://docs.bazel.build/versions/main/install-ubuntu.html#install-on-ubuntu

选择二进制安装包安装,国内下载比较慢,推荐两个网站:

文件用: https://tool.mintimate.cn/gh/
仓库用:https://www.gitclone.com/

直接运行下载好的文件即可

安装mediapipe

官方文档:https://google.github.io/mediapipe/getting_started/install.html#installing-on-windows-subsystem-for-linux-wsl

# 安装必要的安装包
sudo apt-get update && sudo apt-get install -y build-essential git python zip adb openjdk-8-jdk
# 克隆仓库,贼慢,建议使用https://www.gitclone.com/
git clone https://github.com/google/mediapipe.git

  • 1
  • 2
  • 3
  • 4
  • 5

安装opencv等必要库

有多个选择,推荐第一种:

  1. 直接apt安装
sudo apt-get install libopencv-core-dev libopencv-highgui-dev \
                       libopencv-calib3d-dev libopencv-features2d-dev \
                       libopencv-imgproc-dev libopencv-video-dev
  • 1
  • 2
  • 3
  1. mediapipe提供了安装脚本setup_opencv.sh直接执行即可

测试

运行一下helloword:

export GLOG_logtostderr=1
bazel run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world:hello_world
#  MEDIAPIPE_DISABLE_GPU=1 表示不支持gpu
  • 1
  • 2
  • 3
  1. 激动的心,颤抖的手,现在报错了:
ERROR: cannot load '@rules_foreign_cc//:workspace_definitions.bzl': no such file
  • 1

修改WORKSPACE文件内容:

http_archive(
    name = "rules_foreign_cc",
    sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
    strip_prefix = "rules_foreign_cc-0.9.0",
    url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
)

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  1. 编译还是报错。应该是一些依赖的版本对不上了。

  2. 于是选择将mediaPipe仓库回退版本到v0.8.10修改.bazelversion文件内指定的bazel版本,为系统安装的bazel版本。重新执行命令,中间有些文件需要从git下载,笔者网络不是很好,中断了多次!可以尝试科学或者多试几次。

  3. 还是报错了缺少python环境,一个字:装!

sudo apt-get install python3-numpy
  • 1

成功

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/906085
推荐阅读
相关标签
  

闽ICP备14008679号