• OS: Raspbian OS
  • PaddleX 1.0+
  • OpenVINO 2020.4 <<重点,ubuntu18.04 host的版本要与之一致

Installing OpenVINO’s optimized OpenCV on the Raspberry Pi

In this section, we’ll cover prerequisites and all steps required to install OpenCV and OpenVINO on your Raspberry Pi.

Be sure to read this entire section before you begin so that you are familiar with the steps required.

Let’s begin.

Hardware, assumptions, and prerequisites

In this tutorial, I am going to assume that you have the following hardware:

  • Raspberry 4B or 3B+ (running Raspbian Buster)
  • Movidius NCS 2 (or Movidius NCS 1)
  • PiCamera V2 (or USB webcam)
  • 32GB microSD card with Raspbian Stretch freshly flashed
  • HDMI screen + keyboard/mouse (at least for the initial WiFi configuration)
  • 5V power supply (I recommend a 2.5A supply because the Movidius NCS is a power hog)

If you don’t have a microSD with a fresh burn of Raspbian Stretch, you may download it here. I recommend the full install:1

Step #1: Expand filesystem on your Raspberry Pi


Step #2: Reclaim space on your Raspberry Pi

One simple way to gain more space on your Raspberry Pi is to delete both LibreOffice and Wolfram engine to free up some space on your Pi:

$ sudo apt-get purge wolfram-engine
$ sudo apt-get purge libreoffice*
$ sudo apt-get clean
$ sudo apt-get autoremove

After removing the Wolfram Engine and LibreOffice, you can reclaim almost 1GB!

Step #3: Install OpenVINO + OpenCV dependencies on your Raspberry Pi

This step shows some dependencies which I install on every OpenCV system. While you’ll soon see that OpenVINO is already compiled, I recommend that you go ahead and install these packages anyway in case you end up compiling OpenCV from scratch at any time going forward.
Let’s update our system:

$ sudo apt-get update && sudo apt-get upgrade

And then install developer tools including CMake:

$ sudo apt-get install build-essential cmake unzip pkg-config

Next, it is time to install a selection of image and video libraries — these are key to being able to work with image and video files:

$ sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev

From there, let’s install GTK, our GUI backend:

$ sudo apt-get install libgtk-3-dev

And now let’s install a package which may help to reduce GTK warnings:

$ sudo apt-get install libcanberra-gtk*

The asterisk ensures we will grab the ARM-specific GTK. It is required.

Now we need two packages which contain numerical optimizations for OpenCV:

$ sudo apt-get install libatlas-base-dev gfortran

And finally, let’s install the Python 3 development headers:

$ sudo apt-get install python3-dev

Once you have all of these prerequisites installed you can move on to the next step.

Step #4: Download and unpack OpenVINO for your Raspberry Pi

From here forward, our install instructions are largely based upon Intel’s Raspberry Pi OpenVINO guide. There are a few “gotchas” which is why I decided to write a guide. We’ll also use virtual environments as PyImageSearch readers have come to expect.

Our next step is to download OpenVINO.

Let’s navigate to our home folder and create a new directory

$ cd ~

From there, go ahead and grab the OpenVINO Toolkit via wget :

$ wget

Create an installation folder.

$ sudo mkdir -p /opt/intel/openvino

Unpack the archive:

$ sudo tar -xf  l_openvino_toolkit_runtime_raspbian_p_2020.4.287.tgz --strip 1 -C /opt/intel/openvino

Now the OpenVINO toolkit components are installed. Additional configuration steps are still required. Continue to the next sections to install External Software Dependencies, configure the environment and set up USB rules.

Step #5: Configure OpenVINO on your Raspberry Pi

Let’s use nano to edit our ~/.bashrc . We will add a line to load OpenVINO’s each time you invoke a Pi terminal. Go ahead and open the file:

$ nano ~/.bashrc

Scroll to the bottom and add the following lines:

# OpenVINO
source /opt/intel/openvino/bin/

Save and exit from the nano text editor.

Then, go ahead and source your ~/.bashrc file:

$ source ~/.bashrc

To test your change, open a new terminal. You will see the following:

[] OpenVINO environment initialized

ontinue to the next section to add USB rules for Intel® Neural Compute Stick 2 devices.

Step #6: Configure USB rules for your Movidius NCS and OpenVINO on Raspberry Pi

OpenVINO requires that we set custom USB rules. It is quite straightforward, so let’s get started.

First, enter the following command to add the current user to the Raspbian “users” group:

$ sudo usermod -a -G users "$(whoami)"

Then logout and log back in. If you’re on SSH, you can type exit and then re-establish your SSH connection. Rebooting is also an option via sudo reboot now .

Once you’re back at your terminal, run the following script to set the USB rules:

$ sh /opt/intel/openvino/install_dependencies/

Plug in your Intel® Neural Compute Stick 2.

You are ready to compile and run the Object Detection sample to verify the Inference Engine installation.

Install External Software Dependencies

CMake* version 3.7.2 or higher is required for building the Inference Engine sample application. To install, open a Terminal* window and run the following command:

$ sudo apt install cmake

CMake is installed. Continue to the next section to set the environment variables.

此处开始未尝试,请异步原链接 OpenVINO, OpenCV, and Movidius NCS on the Raspberry Pi.

Build and Run Object Detection Sample

Follow the next steps to run pre-trained Face Detection network using Inference Engine samples from the OpenVINO toolkit.

  1. Navigate to a directory that you have write access to and create a samples build directory. This example uses a directory named build:
$ mkdir build && cd build
  1. Build the Object Detection Sample:
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=armv7-a" /opt/intel/openvino/deployment_tools/inference_engine/samples
make -j2 object_detection_sample_ssd

Download the pre-trained Face Detection model or copy it from the host machine:

  • To download the .bin file with weights:
wget --no-check-certificate
  • To download the .xml file with the network topology:
wget --no-check-certificate
  1. Run the sample with specifying the model and a path to the input image:
./armv7l/Release/object_detection_sample_ssd -m face-detection-adas-0001.xml -d MYRIAD -i <path_to_image>

The application outputs an image (out_0.bmp) with detected faced enclosed in rectangles.

Congratulations, you have finished the OpenVINO™ toolkit for Raspbian* OS installation. You have completed all required installation, configuration and build steps in this guide.

Read the next topic if you want to learn more about OpenVINO workflow for Raspberry Pi.

Workflow for Raspberry Pi*

If you want to use your model for inference, the model must be converted to the .bin and .xml Intermediate Representation (IR) files that are used as input by Inference Engine. OpenVINO™ toolkit support on Raspberry Pi only includes the Inference Engine module of the Intel® Distribution of OpenVINO™ toolkit. The Model Optimizer is not supported on this platform. To get the optimized models you can use one of the following options:
… …
For more information about how to use the Model Optimizer, see the Model Optimizer Developer Guide.


  1. PaddleX文档
  2. OpenVINO, OpenCV, and Movidius NCS on the Raspberry Pi.

  1. 更多使用树莓派的细节请参考树莓派官网pyimagesearch ↩︎ ↩︎

  • 0
  • 3
    觉得还不错? 一键收藏
  • 打赏
  • 0
<h3>回答1:</h3><br/>要在树莓派上安装opencv-contrib-python,可以按照以下步骤进行操作: 1. 打开终端,输入以下命令更新系统软件包: sudo apt-get update 2. 安装必要的软件包: sudo <h3>回答2:</h3><br/>树莓派安装opencv-contrib-python需要遵循以下步骤: 1. 安装依赖库 在终端中输入命令 "sudo apt-get install libatlas-base-dev" 安装依赖库,这是为了支持 numpy 数组和图像处理。 2. 下载OpenCV 我们可以从GitHub上下载OpenCV贡献软件包,使用git clone的方式: "git clone" 这将从opencv_contrib的主分支下载完整的源码。 3. 安装OpenCV-Python 接下来,我们需要使用以下命令安装OpenCV-Python: "sudo pip3 install opencv-contrib-python==" 这将安装版本为4.2.0.34的最新版本。 4. 验证安装 在终端中输入 python3,进入Python交互式命令行,输入 "import cv2",然后输入 "cv2.__ version__" 验证OpenCV的版本,如果输出的版本号与我们所安装的版本号匹配,则OpenCV-Python已经成功安装到树莓派中。 总结: 本文介绍了如何在树莓派上安装opencv-contrib-python。安装过程非常简单,只需要安装依赖库、下载OpenCV、安装OpenCV-Python并验证安装即可。这些步骤可以确保我们可以从 Python 中运行使用OpenCV的计算机视觉项目。 <h3>回答3:</h3><br/>树莓派是一款迷你单板电脑,可用于嵌入式系统和物联网应用。而opencv-contrib-python是一个开源的计算机视觉库,可以使树莓派拥有强大的图像处理能力,并用于各种应用场景。 以下是树莓派上安装opencv-contrib-python的步骤: 1. 首先,确保你的树莓派已经安装了Python环境。输入以下命令,检查是否已经安装了Python: python --version 2. 若已安装,请更新pip工具到最新版本,可以通过以下命令完成: sudo pip install --upgrade pip 3. 安装opencv-contrib-python模块,可以使用pip命令,如下: sudo pip install opencv-contrib-python 4. 最后,测试安装是否成功,输入以下命令,运行一个简单的示例: import cv2 img = cv2.imread("test.jpg") cv2.imshow("test", img) cv2.waitKey(0) cv2.destroyAllWindows() 通过以上步骤,可以成功安装opencv-contrib-python模块,并进行简单的图像处理,如读取图片和显示图像。 需要注意的是,树莓派计算能力是有限的,对于大型图像处理任务或实时处理要求较高的应用,可能需要更高性能的硬件设备。同时,在安装前,建议先了解清楚opencv-contrib-python模块的版本和依赖关系,以避免出现安装不成功或冲突的情况。


  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助




当前余额3.43前往充值 >
领取后你会自动成为博主和红包主的粉丝 规则




¥2 ¥4 ¥6 ¥10 ¥20
余额支付 (余额:-- )



钱包余额 0