mediapipe实战1:安装mediaPipe

本文介绍如何在Windows Subsystem for Linux (WSL) 环境中安装MediaPipe,并解决过程中遇到的问题,如错误提示及依赖缺失。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景

项目需要用到人脸识别,手势识别,供应商报价那么高,用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

官方文档: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

安装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. 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. 激动的心,颤抖的手,现在报错了:
ERROR: cannot load '@rules_foreign_cc//:workspace_definitions.bzl': no such file

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

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

sudo apt-get install python3-numpy

成功

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值