- OS: Raspbian OS
- PaddleX 1.0+
- OpenVINO 2020.4
- Raspbian OS:树莓派操作操作系统下载与安装请参考树莓派系统安装与环境配置
- PaddleX: PaddleX安装请参考PaddleX
- OpenVINO: OpenVINO的安装请参考OpenVINO-Raspbian
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.
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 https://download.01.org/opencv/2020/openvinotoolkit/2020.4/l_openvino_toolkit_runtime_raspbian_p_2020.4.287.tgz
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
nano to edit our
~/.bashrc . We will add a line to load OpenVINO’s
setupvars.sh 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/setupvars.sh
Save and exit from the nano text editor.
Then, go ahead and
$ source ~/.bashrc
To test your change, open a new terminal. You will see the following:
[setupvars.sh] 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/install_NCS_udev_rules.sh
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.
- Navigate to a directory that you have write access to and create a samples build directory. This example uses a directory named
$ mkdir build && cd build
- 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
.binfile with weights:
wget --no-check-certificate https://download.01.org/opencv/2020/openvinotoolkit/2020.1/open_model_zoo/models_bin/1/face-detection-adas-0001/FP16/face-detection-adas-0001.bin
- To download the
.xmlfile with the network topology:
wget --no-check-certificate https://download.01.org/opencv/2020/openvinotoolkit/2020.1/open_model_zoo/models_bin/1/face-detection-adas-0001/FP16/face-detection-adas-0001.xml
- 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.
更多使用树莓派的细节请参考树莓派官网 和 pyimagesearch ↩︎ ↩︎