当前位置:   article > 正文

MediaPipe框架- 安装_mediapipe安装

mediapipe安装

Installation

安装

Note: To interoperate with OpenCV, OpenCV 3.x to 4.1 are preferred. OpenCV 2.x currently works but interoperability support may be deprecated in the future.

注意:为了与OpenCV进行互操作,首选OpenCV 3.x到4.1。OpenCV 2.x目前可以工作,但互操作性支持将来可能会被弃用。

Note: If you plan to use TensorFlow calculators and example apps, there is a known issue with gcc and g++ version 6.3 and 7.3. We recommend installing gcc and g++ version 8.x.

注意:如果您计划使用TensorFlow计算器和示例应用程序,那么gcc和g++版本6.3和7.3存在已知问题。我们建议安装gcc和g++版本8.x。

Note: To make Mediapipe work with TensorFlow, please set Python 3.7 as the default Python version and install the Python "six" library by running pip3 install --user six.

注意:为了使Mediapipe与TensorFlow协同工作,请将Python 3.7设置为默认的Python版本,并通过运行pip3 install --user six来安装Python“six”库。

Installing on Debian and Ubuntu

在Debian和Ubuntu上安装

1.Install Bazelisk.

1.安装Bazelisk。

Follow the official Bazel documentation to install Bazelisk.

​按照官方Bazel文档安装Bazelik。

2.Checkout MediaPipe repository.

2.切换到MediaPipe存储库。

  1. $ cd $HOME
  2. $ git clone --depth 1 https://github.com/google/mediapipe.git
  3. # Change directory into MediaPipe root directory
  4. $ cd mediapipe

3.Install OpenCV and FFmpeg.

3.安装OpenCV和FFmpeg。

Option 1. Use package manager tool to install the pre-compiled OpenCV libraries. FFmpeg will be installed via libopencv-video-dev.

选项1。使用包管理器工具安装预编译的OpenCV库。FFmpeg将通过libopencv-video-dev安装。

OSOpenCV
Debian 9 (stretch)2.4
Debian 10 (buster)3.2
Debian 11 (bullseye)4.5
Ubuntu 16.04 LTS2.4
Ubuntu 18.04 LTS3.2
Ubuntu 20.04 LTS4.2
Ubuntu 20.04 LTS4.2
Ubuntu 21.044.5

  1. $ sudo apt-get install -y \
  2.     libopencv-core-dev \
  3.     libopencv-highgui-dev \
  4.     libopencv-calib3d-dev \
  5.     libopencv-features2d-dev \
  6.     libopencv-imgproc-dev \
  7.     libopencv-video-dev

Note. On Debian 11/Ubuntu 21.04 when OpenCV 4.5 is installed with libopencv-video-devlibopencv-contrib-dev should also be installed.

Note.在Debian 11/Ubuntu 21.04上,当OpenCV 4.5与libopencv video-dev一起安装时,也应该安装libopencv-controb-dev。

$ sudo apt-get install -y libopencv-contrib-dev

MediaPipe's opencv_linux.BUILD and WORKSPACE are already configured for OpenCV 2/3 and should work correctly on any architecture:

​MediaPipe的opencv_linu.BUILD和WORKSPACE已经为OpenCV 2/3配置,应该可以在任何体系结构上正确工作:

  1. # WORKSPACE
  2. new_local_repository(
  3.   name = "linux_opencv",
  4.   build_file = "@//third_party:opencv_linux.BUILD",
  5.   path = "/usr",
  6. )
  7. # opencv_linux.BUILD for OpenCV 2/3 installed from Debian package
  8. cc_library(
  9.   name = "opencv",
  10.   linkopts = [
  11.     "-l:libopencv_core.so",
  12.     "-l:libopencv_calib3d.so",
  13.     "-l:libopencv_features2d.so",
  14.     "-l:libopencv_highgui.so",
  15.     "-l:libopencv_imgcodecs.so",
  16.     "-l:libopencv_imgproc.so",
  17.     "-l:libopencv_video.so",
  18.     "-l:libopencv_videoio.so",
  19.   ],
  20. )

For OpenCV 4 you need to modify opencv_linux.BUILD taking into account current architecture:

​对于OpenCV 4,需要修改opencv_linux.BUILD,在考虑当前体系结构的情况下构建:

  1. # WORKSPACE
  2. new_local_repository(
  3.   name = "linux_opencv",
  4.   build_file = "@//third_party:opencv_linux.BUILD",
  5.   path = "/usr",
  6. )
  7. # opencv_linux.BUILD for OpenCV 4 installed from Debian package
  8. cc_library(
  9.   name = "opencv",
  10.   hdrs = glob([
  11.     # Uncomment according to your multiarch value (gcc -print-multiarch):
  12.     #  "include/aarch64-linux-gnu/opencv4/opencv2/cvconfig.h",
  13.     #  "include/arm-linux-gnueabihf/opencv4/opencv2/cvconfig.h",
  14.     #  "include/x86_64-linux-gnu/opencv4/opencv2/cvconfig.h",
  15.     "include/opencv4/opencv2/**/*.h*",
  16.   ]),
  17.   includes = [
  18.     # Uncomment according to your multiarch value (gcc -print-multiarch):
  19.     #  "include/aarch64-linux-gnu/opencv4/",
  20.     #  "include/arm-linux-gnueabihf/opencv4/",
  21.     #  "include/x86_64-linux-gnu/opencv4/",
  22.     "include/opencv4/",
  23.   ],
  24.   linkopts = [
  25.     "-l:libopencv_core.so",
  26.     "-l:libopencv_calib3d.so",
  27.     "-l:libopencv_features2d.so",
  28.     "-l:libopencv_highgui.so",
  29.     "-l:libopencv_imgcodecs.so",
  30.     "-l:libopencv_imgproc.so",
  31.     "-l:libopencv_video.so",
  32.     "-l:libopencv_videoio.so",
  33.   ],
  34. )

Option 2. Run setup_opencv.sh to automatically build OpenCV from source and modify MediaPipe's OpenCV config. This option will do all steps defined in Option 3 automatically.

​选项2。运行setup_opencv.sh从源代码自动构建opencv,并修改MediaPipe的opencv配置。此选项将自动执行选项3中定义的所有步骤。

Option 3. Follow OpenCV's documentation to manually build OpenCV from source code.

​选项3。按照OpenCV的文档从源代码手动构建OpenCV。

You may need to modify WORKSPACE and opencv_linux.BUILD to point MediaPipe to your own OpenCV libraries. Assume OpenCV would be installed to /usr/local/ which is recommended by default.

​可能需要修改WORKSPACE和opencv_linux.BUILD将MediaPipe指向自己的OpenCV库。假设OpenCV将安装到/usr/local/,这是默认情况下推荐的。

OpenCV 2/3 setup:

OpenCV 2/3设置:

  1. # WORKSPACE
  2. new_local_repository(
  3.   name = "linux_opencv",
  4.   build_file = "@//third_party:opencv_linux.BUILD",
  5.   path = "/usr/local",
  6. )
  7. # opencv_linux.BUILD for OpenCV 2/3 installed to /usr/local
  8. cc_library(
  9.   name = "opencv",
  10.   linkopts = [
  11.     "-L/usr/local/lib",
  12.     "-l:libopencv_core.so",
  13.     "-l:libopencv_calib3d.so",
  14.     "-l:libopencv_features2d.so",
  15.     "-l:libopencv_highgui.so",
  16.     "-l:libopencv_imgcodecs.so",
  17.     "-l:libopencv_imgproc.so",
  18.     "-l:libopencv_video.so",
  19.     "-l:libopencv_videoio.so",
  20.   ],
  21. )

OpenCV 4 setup:

OpenCV 4设置:

  1. # WORKSPACE
  2. new_local_repository(
  3.   name = "linux_opencv",
  4.   build_file = "@//third_party:opencv_linux.BUILD",
  5.   path = "/usr/local",
  6. )
  7. # opencv_linux.BUILD for OpenCV 4 installed to /usr/local
  8. cc_library(
  9.   name = "opencv",
  10.   hdrs = glob([
  11.     "include/opencv4/opencv2/**/*.h*",
  12.   ]),
  13.   includes = [
  14.     "include/opencv4/",
  15.   ],
  16.   linkopts = [
  17.     "-L/usr/local/lib",
  18.     "-l:libopencv_core.so",
  19.     "-l:libopencv_calib3d.so",
  20.     "-l:libopencv_features2d.so",
  21.     "-l:libopencv_highgui.so",
  22.     "-l:libopencv_imgcodecs.so",
  23.     "-l:libopencv_imgproc.so",
  24.     "-l:libopencv_video.so",
  25.     "-l:libopencv_videoio.so",
  26.   ],
  27. )

Current FFmpeg setup is defined in ffmpeg_linux.BUILD and should work for any architecture:

​当前的FFmpeg设置在ffmpeg_linux.BUILD中定义。并应适用于任何体系结构:

  1. # WORKSPACE
  2. new_local_repository(
  3.   name = "linux_ffmpeg",
  4.   build_file = "@//third_party:ffmpeg_linux.BUILD",
  5.   path = "/usr"
  6. )
  7. # ffmpeg_linux.BUILD for FFmpeg installed from Debian package
  8. cc_library(
  9.   name = "libffmpeg",
  10.   linkopts = [
  11.     "-l:libavcodec.so",
  12.     "-l:libavformat.so",
  13.     "-l:libavutil.so",
  14.   ],
  15. )

4.For running desktop examples on Linux only (not on OS X) with GPU acceleration.

4.用于仅在Linux上(而不是在OS X上)使用GPU加速运行桌面示例。

  1. # Requires a GPU with EGL driver support.
  2. # Can use mesa GPU libraries for desktop, (or Nvidia/AMD equivalent).
  3. sudo apt-get install mesa-common-dev libegl1-mesa-dev libgles2-mesa-dev
  4. # To compile with GPU support, replace
  5. --define MEDIAPIPE_DISABLE_GPU=1
  6. # with
  7. --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11
  8. # when building GPU examples.

5.Run the Hello World! in C++ example.

​5.运行Hello World!在C++示例中。

  1. $ export GLOG_logtostderr=1
  2. # if you are running on Linux desktop with CPU only
  3. $ bazel run --define MEDIAPIPE_DISABLE_GPU=1 \
  4.     mediapipe/examples/desktop/hello_world:hello_world
  5. # If you are running on Linux desktop with GPU support enabled (via mesa drivers)
  6. $ bazel run --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 \
  7.     mediapipe/examples/desktop/hello_world:hello_world
  8. # Should print:
  9. # Hello World!
  10. # Hello World!
  11. # Hello World!
  12. # Hello World!
  13. # Hello World!
  14. # Hello World!
  15. # Hello World!
  16. # Hello World!
  17. # Hello World!
  18. # Hello World!

If you run into a build error, please read Troubleshooting to find the solutions of several common build issues.

​如果遇到生成错误,请阅读“疑难解答”以找到几个常见生成问题的解决方案。

Installing on CentOS

在CentOS上安装

Disclaimer: Running MediaPipe on CentOS is experimental.

免责声明:在CentOS上运行MediaPipe是实验性的。

1.Install Bazelisk.

1.安装Bazelisk。

Follow the official Bazel documentation to install Bazelisk.

​按照官方Bazel文档安装Bazelik。

2.Checkout MediaPipe repository.

2.切换MediaPipe存储库。

  1. $ git clone --depth 1 https://github.com/google/mediapipe.git
  2. # Change directory into MediaPipe root directory
  3. $ cd mediapipe

3.Install OpenCV.

3.安装OpenCV。

Option 1. Use package manager tool to install the pre-compiled version.

选项1 使用包管理器工具安装预编译版本。

Note: yum installs OpenCV 2.4.5, which may have an opencv/gstreamer issue.

​注意:yum安装OpenCV 2.4.5,该版本可能存在OpenCV/gstareamer问题。

$ sudo yum install opencv-devel

Option 2. Build OpenCV from source code.

选项2 从源代码构建OpenCV。

Note: You may need to modify WORKSPACEopencv_linux.BUILD and ffmpeg_linux.BUILD to point MediaPipe to your own OpenCV and FFmpeg libraries. For example if OpenCV and FFmpeg are both manually installed in "/usr/local/", you will need to update: (1) the "linux_opencv" and "linux_ffmpeg" new_local_repository rules in WORKSPACE, (2) the "opencv" cc_library rule in opencv_linux.BUILD, and (3) the "libffmpeg" cc_library rule in ffmpeg_linux.BUILD. These 3 changes are shown below:

​注意:可能需要修改WORKSPACE、opencv_linux.BUILD和ffmpeg_linux.BUILD将MediaPipe指向自己的OpenCV和FFmpeg库。例如,如果OpenCV和FFmpeg都手动安装在“/usr/local/”中,则需要更新:(1)WORKSPACE中的“linux_opencv”和“linux_ffmpeg”new_local_pository规则,(2)opencv_linux.BUILD中的“OpenCV”cc_library规则,以及(3)ffmpeg_linux.BUILD中的“libffmpeg”cc_library规则。这3个变化如下所示:

  1. new_local_repository(
  2.     name = "linux_opencv",
  3.     build_file = "@//third_party:opencv_linux.BUILD",
  4.     path = "/usr/local",
  5. )
  6. new_local_repository(
  7.     name = "linux_ffmpeg",
  8.     build_file = "@//third_party:ffmpeg_linux.BUILD",
  9.     path = "/usr/local",
  10. )
  11. cc_library(
  12.     name = "opencv",
  13.     srcs = glob(
  14.         [
  15.             "lib/libopencv_core.so",
  16.             "lib/libopencv_highgui.so",
  17.             "lib/libopencv_imgcodecs.so",
  18.             "lib/libopencv_imgproc.so",
  19.             "lib/libopencv_video.so",
  20.             "lib/libopencv_videoio.so",
  21.         ],
  22.     ),
  23.     hdrs = glob([
  24.         # For OpenCV 3.x
  25.         "include/opencv2/**/*.h*",
  26.         # For OpenCV 4.x
  27.         # "include/opencv4/opencv2/**/*.h*",
  28.     ]),
  29.     includes = [
  30.         # For OpenCV 3.x
  31.         "include/",
  32.         # For OpenCV 4.x
  33.         # "include/opencv4/",
  34.     ],
  35.     linkstatic = 1,
  36.     visibility = ["//visibility:public"],
  37. )
  38. cc_library(
  39.     name = "libffmpeg",
  40.     srcs = glob(
  41.         [
  42.             "lib/libav*.so",
  43.         ],
  44.     ),
  45.     hdrs = glob(["include/libav*/*.h"]),
  46.     includes = ["include"],
  47.     linkopts = [
  48.         "-lavcodec",
  49.         "-lavformat",
  50.         "-lavutil",
  51.     ],
  52.     linkstatic = 1,
  53.     visibility = ["//visibility:public"],
  54. )

4.Run the Hello World! in C++ example.

​4.运行Hello World!在C++示例中。

  1. $ export GLOG_logtostderr=1
  2. # Need bazel flag 'MEDIAPIPE_DISABLE_GPU=1' if you are running on Linux desktop with CPU only
  3. $ bazel run --define MEDIAPIPE_DISABLE_GPU=1 \
  4.     mediapipe/examples/desktop/hello_world:hello_world
  5. # Should print:
  6. # Hello World!
  7. # Hello World!
  8. # Hello World!
  9. # Hello World!
  10. # Hello World!
  11. # Hello World!
  12. # Hello World!
  13. # Hello World!
  14. # Hello World!
  15. # Hello World!

If you run into a build error, please read Troubleshooting to find the solutions of several common build issues.

​如果遇到生成错误,请阅读“疑难解答”以找到几个常见生成问题的解决方案。

Installing on macOS

在macOS上安装

1.Prework:

1.前期工作:

  • Install Homebrew.
  • ​安装Homebrew。
  • Install Xcode and its Command Line Tools by xcode-select --install.
  • ​通过xcode-select --install安装Xcode及其命令行工具。

2.Install Bazelisk.

2.安装Bazelisk。

Follow the official Bazel documentation to install Bazelisk.

​按照官方Bazel文档安装Bazelik。

3.Checkout MediaPipe repository.

3.切换到MediaPipe存储库。

  1. $ git clone --depth 1 https://github.com/google/mediapipe.git
  2. $ cd mediapipe

4.Install OpenCV and FFmpeg.

4.安装OpenCV和FFmpeg。

Option 1. Use HomeBrew package manager tool to install the pre-compiled OpenCV 3 libraries. FFmpeg will be installed via OpenCV.

选项1 使用HomeBrew软件包管理器工具安装预编译的OpenCV 3库。FFmpeg将通过OpenCV安装。

  1. $ brew install opencv@3
  2. # There is a known issue caused by the glog dependency. Uninstall glog.
  3. $ brew uninstall --ignore-dependencies glog

Option 2. Use MacPorts package manager tool to install the OpenCV libraries.

选项2 使用MacPorts软件包管理器工具安装OpenCV库。

$ port install opencv

Note: when using MacPorts, please edit the WORKSPACEopencv_macos.BUILD, and ffmpeg_macos.BUILD files like the following:


注意:使用MacPorts时,请编辑WORKSPACE,opencv_macos.BUILD和ffmpeg_macos.BUILD文件如下所示:

  1. new_local_repository(
  2.     name = "macos_opencv",
  3.     build_file = "@//third_party:opencv_macos.BUILD",
  4.     path = "/opt",
  5. )
  6. new_local_repository(
  7.     name = "macos_ffmpeg",
  8.     build_file = "@//third_party:ffmpeg_macos.BUILD",
  9.     path = "/opt",
  10. )
  11. cc_library(
  12.     name = "opencv",
  13.     srcs = glob(
  14.         [
  15.             "local/lib/libopencv_core.dylib",
  16.             "local/lib/libopencv_highgui.dylib",
  17.             "local/lib/libopencv_imgcodecs.dylib",
  18.             "local/lib/libopencv_imgproc.dylib",
  19.             "local/lib/libopencv_video.dylib",
  20.             "local/lib/libopencv_videoio.dylib",
  21.         ],
  22.     ),
  23.     hdrs = glob(["local/include/opencv2/**/*.h*"]),
  24.     includes = ["local/include/"],
  25.     linkstatic = 1,
  26.     visibility = ["//visibility:public"],
  27. )
  28. cc_library(
  29.     name = "libffmpeg",
  30.     srcs = glob(
  31.         [
  32.             "local/lib/libav*.dylib",
  33.         ],
  34.     ),
  35.     hdrs = glob(["local/include/libav*/*.h"]),
  36.     includes = ["local/include/"],
  37.     linkopts = [
  38.         "-lavcodec",
  39.         "-lavformat",
  40.         "-lavutil",
  41.     ],
  42.     linkstatic = 1,
  43.     visibility = ["//visibility:public"],
  44. )

5.Make sure that Python 3 and the Python "six" library are installed.

5.确保已安装Python 3和Python“six”库。

  1. $ brew install python
  2. $ sudo ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python
  3. $ python --version
  4. Python 3.7.4
  5. $ pip3 install --user six

6.Run the Hello World! in C++ example.

​6.运行Hello World!在C++示例中。

  1. $ export GLOG_logtostderr=1
  2. # Need bazel flag 'MEDIAPIPE_DISABLE_GPU=1' as desktop GPU is currently not supported
  3. $ bazel run --define MEDIAPIPE_DISABLE_GPU=1 \
  4.     mediapipe/examples/desktop/hello_world:hello_world
  5. # Should print:
  6. # Hello World!
  7. # Hello World!
  8. # Hello World!
  9. # Hello World!
  10. # Hello World!
  11. # Hello World!
  12. # Hello World!
  13. # Hello World!
  14. # Hello World!
  15. # Hello World!

If you run into a build error, please read Troubleshooting to find the solutions of several common build issues.

​如果遇到生成错误,请阅读“疑难解答”以找到几个常见生成问题的解决方案。

Installing on Windows

在Windows上安装

Disclaimer: Running MediaPipe on Windows is experimental.

免责声明:在Windows上运行MediaPipe是实验性的。

Note: building MediaPipe Android apps is still not possible on native Windows. Please do this in WSL instead and see the WSL setup instruction in the next section.

注意:在本机Windows上仍然无法构建MediaPipe Android应用程序。请改为在WSL中执行此操作,并参阅下一节中的WSL设置说明。

1.Install MSYS2 and edit the %PATH% environment variable.

​1.安装MSYS2并编辑%PATH%环境变量。

If MSYS2 is installed to C:\msys64, add C:\msys64\usr\bin to your %PATH% environment variable.

如果MSYS2安装到C:\msys64,请将C:\msys64\usr\bin添加到%PATH%环境变量中。

2.Install necessary packages.

2.安装必要的包。

C:\> pacman -S git patch unzip

3.Install Python and allow the executable to edit the %PATH% environment variable.

3.安装Python并允许可执行文件编辑%PATH%环境变量。

Download Python Windows executable from https://www.python.org/downloads and install.

​从下载Python Windows可执行文件https://www.python.org/downloads并安装。

4.Install Visual C++ Build Tools 2019 and WinSDK

4.安装Visual C++Build Tools 2019和WinSDK

Go to the VisualStudio website, download build tools, and install Microsoft Visual C++ 2019 Redistributable and Microsoft Build Tools 2019.

​转到VisualStudio网站,下载构建工具,然后安装Microsoft Visual C++2019 Redistributable和Microsoft build tools 2019。

Download the WinSDK from the official MicroSoft website and install.

​从MicroSoft官方网站下载WinSDK并安装。

5.Install Bazel or Bazelisk and add the location of the Bazel executable to the %PATH% environment variable.

5.安装Bazel或Bazelisk,并将Bazel可执行文件的位置添加到%PATH%环境变量中。

Option 1. Follow the official Bazel documentation to install Bazel 6.1.1 or higher.

​选项1 按照官方Bazel文档安装Bazel 6.1.1或更高版本。

Option 2. Follow the official Bazel documentation to install Bazelisk.

​选项2 按照官方Bazel文档安装Bazelik。

6.Set Bazel variables. Learn more details about "Build on Windows" in the Bazel official documentation.

​6.设置Bazel变量。在Bazel官方文档中了解有关“在Windows上构建”的更多详细信息。

  1. # Please find the exact paths and version numbers from your local version.
  2. C:\> set BAZEL_VS=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
  3. C:\> set BAZEL_VC=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC
  4. C:\> set BAZEL_VC_FULL_VERSION=<Your local VC version>
  5. C:\> set BAZEL_WINSDK_FULL_VERSION=<Your local WinSDK version>

7.Checkout MediaPipe repository.

7.切换到MediaPipe存储库。

  1. C:\Users\Username\mediapipe_repo> git clone --depth 1 https://github.com/google/mediapipe.git
  2. # Change directory into MediaPipe root directory
  3. C:\Users\Username\mediapipe_repo> cd mediapipe

8.Install OpenCV.

8.安装OpenCV。

Download the Windows executable from https://opencv.org/releases/ and install. MediaPipe 0.10.x supports OpenCV 3.4.10. Remember to edit the WORKSPACE file if OpenCV is not installed at C:\opencv.

​从下载Windows可执行文件https://opencv.org/releases/并安装。MediaPipe 0.10.x支持OpenCV 3.4.10。如果C:\OpenCV中未安装OpenCV,请记住编辑WORKSPACE文件。

  1. new_local_repository(
  2.     name = "windows_opencv",
  3.     build_file = "@//third_party:opencv_windows.BUILD",
  4.     path = "C:\\<path to opencv>\\build",
  5. )

9.Run the Hello World! in C++ example.

​9.运行Hello World!在C++示例中。

Note: For building MediaPipe on Windows, please add --action_env PYTHON_BIN_PATH="C://path//to//python.exe" to the build command. Alternatively, you can follow issue 724 to fix the python configuration manually.


注意:要在Windows上构建MediaPipe,请将--action_env PYTHON_BIN_PATH="C://path//to//python.exe"添加到构建命令中。或者,可以按照问题724手动修复python配置。

  1. C:\Users\Username\mediapipe_repo>bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C://python_36//python.exe" mediapipe/examples/desktop/hello_world
  2. C:\Users\Username\mediapipe_repo>set GLOG_logtostderr=1
  3. C:\Users\Username\mediapipe_repo>bazel-bin\mediapipe\examples\desktop\hello_world\hello_world.exe
  4. # should print:
  5. # I20200514 20:43:12.277598  1200 hello_world.cc:56] Hello World!
  6. # I20200514 20:43:12.278597  1200 hello_world.cc:56] Hello World!
  7. # I20200514 20:43:12.279618  1200 hello_world.cc:56] Hello World!
  8. # I20200514 20:43:12.279618  1200 hello_world.cc:56] Hello World!
  9. # I20200514 20:43:12.279618  1200 hello_world.cc:56] Hello World!
  10. # I20200514 20:43:12.279618  1200 hello_world.cc:56] Hello World!
  11. # I20200514 20:43:12.279618  1200 hello_world.cc:56] Hello World!
  12. # I20200514 20:43:12.279618  1200 hello_world.cc:56] Hello World!
  13. # I20200514 20:43:12.279618  1200 hello_world.cc:56] Hello World!
  14. # I20200514 20:43:12.280613  1200 hello_world.cc:56] Hello World!

If you run into a build error, please read Troubleshooting to find the solutions of several common build issues.

​如果遇到生成错误,请阅读“疑难解答”以找到几个常见生成问题的解决方案。

Installing on Windows Subsystem for Linux (WSL)

在Windows Subsystem for Linux(WSL)上安装

Note: The pre-built OpenCV packages don't support cameras in WSL. Unless you compile OpenCV with FFMPEG and GStreamer in WSL, the live demos won't work with any cameras. Alternatively, you use a video file as input.


注意:预先构建的OpenCV包不支持WSL中的摄像头。除非在WSL中使用FFMPEG和GStreamer编译OpenCV,否则现场演示将无法与任何相机一起使用。或者,使用视频文件作为输入。

1.Follow the instruction to install Windows Subsystem for Linux (Ubuntu).

​1.按照说明安装Windows Subsystem for Linux(Ubuntu)。

2.Install Windows ADB and start the ADB server in Windows.

2.安装Windows ADB并在Windows中启动ADB服务器。

Note: Windows' and WSL’s adb versions must be the same version, e.g., if WSL has ADB 1.0.39, you need to download the corresponding Windows ADB from here.


注意:Windows和WSL的adb版本必须是相同的版本,例如,如果WSL有adb 1.0.39,您需要从这里下载相应的Windows adb。

3.Launch WSL.

3.启动WSL。

Note: All the following steps will be executed in WSL. The Windows directory of the Linux Subsystem can be found in C:\Users\YourUsername\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_SomeID\LocalState\rootfs\home

注意:以下所有步骤都将在WSL中执行。Linux子系统的Windows目录可以在C:\Users\YourUsername\AppData\Local\Packages\CanonicalGroupLimited中找到。UbuntuonDows_SomeID\LocalState\rootfs\home

4.Install the needed packages.

4.安装所需的包。

username@DESKTOP-TMVLBJ1:~$ sudo apt-get update && sudo apt-get install -y build-essential git python zip adb openjdk-8-jdk

5.Install Bazelisk.

5.安装Bazelisk。

Follow the official Bazel documentation to install Bazelisk.

​按照官方Bazel文档安装Bazelik。

6.Checkout MediaPipe repository.

6.切换到MediaPipe存储库。

  1. username@DESKTOP-TMVLBJ1:~$ git clone --depth 1 https://github.com/google/mediapipe.git
  2. username@DESKTOP-TMVLBJ1:~$ cd mediapipe

7.Install OpenCV and FFmpeg.

7.安装OpenCV和FFmpeg。

Option 1. Use package manager tool to install the pre-compiled OpenCV libraries. FFmpeg will be installed via libopencv-video-dev.

选项1 使用包管理器工具安装预编译的OpenCV库。FFmpeg将通过libopencv-video-dev安装。

  1. username@DESKTOP-TMVLBJ1:~/mediapipe$ sudo apt-get install libopencv-core-dev libopencv-highgui-dev \
  2.                        libopencv-calib3d-dev libopencv-features2d-dev \
  3.                        libopencv-imgproc-dev libopencv-video-dev

Option 2. Run setup_opencv.sh to automatically build OpenCV from source and modify MediaPipe's OpenCV config.

​选项2 运行setup_opencv.sh从源代码自动构建opencv,并修改MediaPipe的opencv配置。

Option 3. Follow OpenCV's documentation to manually build OpenCV from source code.

​选项3 按照OpenCV的文档从源代码手动构建OpenCV。

Note: You may need to modify WORKSPACE and opencv_linux.BUILD to point MediaPipe to your own OpenCV libraries, e.g., if OpenCV 4 is installed in "/usr/local/", you need to update the "linux_opencv" new_local_repository rule in WORKSPACE and "opencv" cc_library rule in opencv_linux.BUILD like the following:


注意:可能需要修改WORKSPACE和opencv_linux.BUILD将MediaPipe指向自己的OpenCV库,例如,如果OpenCV 4安装在“/usr/local/”中,则需要更新WORKSPACE中的“linux_opencv”new_local_pository规则和opencv_linux.BUILD中的“OpenCV”cc_library规则。按照以下方式:

  1. new_local_repository(
  2.     name = "linux_opencv",
  3.     build_file = "@//third_party:opencv_linux.BUILD",
  4.     path = "/usr/local",
  5. )
  6. cc_library(
  7.     name = "opencv",
  8.     srcs = glob(
  9.         [
  10.             "lib/libopencv_core.so",
  11.             "lib/libopencv_highgui.so",
  12.             "lib/libopencv_imgcodecs.so",
  13.             "lib/libopencv_imgproc.so",
  14.             "lib/libopencv_video.so",
  15.             "lib/libopencv_videoio.so",
  16.         ],
  17.     ),
  18.     hdrs = glob(["include/opencv4/**/*.h*"]),
  19.     includes = ["include/opencv4/"],
  20.     linkstatic = 1,
  21.     visibility = ["//visibility:public"],
  22. )

8.Run the Hello World! in C++ example.

​8.运行Hello World!在C++示例中。

  1. username@DESKTOP-TMVLBJ1:~/mediapipe$ export GLOG_logtostderr=1
  2. # Need bazel flag 'MEDIAPIPE_DISABLE_GPU=1' as desktop GPU is currently not supported
  3. username@DESKTOP-TMVLBJ1:~/mediapipe$ bazel run --define MEDIAPIPE_DISABLE_GPU=1 \
  4.     mediapipe/examples/desktop/hello_world:hello_world
  5. # Should print:
  6. # Hello World!
  7. # Hello World!
  8. # Hello World!
  9. # Hello World!
  10. # Hello World!
  11. # Hello World!
  12. # Hello World!
  13. # Hello World!
  14. # Hello World!
  15. # Hello World!

If you run into a build error, please read Troubleshooting to find the solutions of several common build issues.

​如果遇到生成错误,请阅读“疑难解答”以找到几个常见生成问题的解决方案。

Installing using Docker

使用Docker安装

This will use a Docker image that will isolate mediapipe's installation from the rest of the system.

这将使用Docker映像,将mediapipe的安装与系统的其他部分隔离开来。

1.Install Docker on your host system.

​1.在主机系统上安装Docker。

2.Build a docker image with tag "mediapipe".

2.使用标签“mediapipe”构建docker图像。

  1. $ git clone --depth 1 https://github.com/google/mediapipe.git
  2. $ cd mediapipe
  3. $ docker build --tag=mediapipe .
  4. # Should print:
  5. # Sending build context to Docker daemon  147.8MB
  6. # Step 1/9 : FROM ubuntu:latest
  7. # latest: Pulling from library/ubuntu
  8. # 6abc03819f3e: Pull complete
  9. # 05731e63f211: Pull complete
  10. # ........
  11. # See http://bazel.build/docs/getting-started.html to start a new project!
  12. # Removing intermediate container 82901b5e79fa
  13. # ---> f5d5f402071b
  14. # Step 9/9 : COPY . /mediapipe/
  15. # ---> a95c212089c5
  16. # Successfully built a95c212089c5
  17. # Successfully tagged mediapipe:latest

3.Run the Hello World! in C++ example.

​3.运行Hello World!在C++示例中。

  1. $ docker run -it --name mediapipe mediapipe:latest
  2. root@bca08b91ff63:/mediapipe# GLOG_logtostderr=1 bazel run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world
  3. # Should print:
  4. # Hello World!
  5. # Hello World!
  6. # Hello World!
  7. # Hello World!
  8. # Hello World!
  9. # Hello World!
  10. # Hello World!
  11. # Hello World!
  12. # Hello World!
  13. # Hello World!

If you run into a build error, please read Troubleshooting to find the solutions of several common build issues.

​如果遇到生成错误,请阅读“疑难解答”以找到几个常见生成问题的解决方案。

1.Build a MediaPipe Android example.

1.构建一个MediaPipe Android示例。

  1. $ docker run -it --name mediapipe mediapipe:latest
  2. root@bca08b91ff63:/mediapipe# bash ./setup_android_sdk_and_ndk.sh
  3. # Should print:
  4. # Android NDK is now installed. Consider setting $ANDROID_NDK_HOME environment variable to be /root/Android/Sdk/ndk-bundle/android-ndk-r19c
  5. # Set android_ndk_repository and android_sdk_repository in WORKSPACE
  6. # Done
  7. root@bca08b91ff63:/mediapipe# bazel build -c opt --config=android_arm64 mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectiongpu:objectdetectiongpu
  8. # Should print:
  9. # Target //mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectiongpu:objectdetectiongpu up-to-date:
  10. # bazel-bin/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectiongpu/objectdetectiongpu_deploy.jar
  11. # bazel-bin/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectiongpu/objectdetectiongpu_unsigned.apk
  12. # bazel-bin/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectiongpu/objectdetectiongpu.apk
  13. # INFO: Elapsed time: 144.462s, Critical Path: 79.47s
  14. # INFO: 1958 processes: 1 local, 1863 processwrapper-sandbox, 94 worker.
  15. # INFO: Build completed successfully, 2028 total actions

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

闽ICP备14008679号