Install OpenCV 3.2.0 on Raspberry Pi Zero W in 15 Minutes
OpenCV, or Open Source Computer Vision Library, is an open source computer vision and machine learning software. It works on Raspberry Pi computers, and can process photos captured by the Raspberry Pi Camera Module.
OpenCV has two supported versions: 2.4.x and 3.x. New features are being added to 3.x branch, while 2.4.x only receives bug fixes and efficiency fixes. It is recommended that new developments should use OpenCV 3.x, to take advantage of new features. However, the official operating system for the Raspberry Pi, Raspbian Stretch, comes with OpenCV 2.4.9. While I am not yet familiar with OpenCV algorithms, one thing notably missing from OpenCV 2.4.9 is a Python 3 binding.
I wanted to have OpenCV 3 running in Raspbian Stretch on a Raspberry Pi Zero W. Unable to find existing packages for Pi Zero and Stretch, I had no choice but to compile my own OpenCV 3. I decided to do it the proper way: build a backported Debian package. This method is superior to installing from the source code, because the packages can easily be deployed to other Raspberry Pi Zero W computers. I followed the Simple Backport Creation instruction, and spent a week building the packages. Now I'm sharing my compiled packages, so that you can use them if you dare.
- Raspberry Pi Zero W (paid link) running Raspbian Stretch
- Raspberry Pi Camera Module (paid link) (optional)
The packages are built for ARMv6 architecture used in Raspberry Pi Zero W, and depends on Raspbian Stretch libraries. They are not compatible with Raspberry Pi 2/3 that has a different CPU architecture. They will not work on Raspbian Jessie/Buster or Ubuntu systems.
Enable my Pi Zero repository:
echo 'deb [trusted=yes] http://dl.bintray.com/yoursunny/PiZero stretch-backports main' |\ sudo tee /etc/apt/sources.list.d/bintray-yoursunny-PiZero.list
UPDATE 2020-07-25: This repository is only for Raspbian "stretch". If you have Raspberry Pi OS "buster", do not add my repository. You can execute the remaining steps to install OpenCV 3 from default APT sources.
Update package lists:
sudo apt update
Install OpenCV package:
sudo apt install python3-opencv
Depending on the speed of your Internet connection, this may take between 15 and 30 minutes.
Verify the installation:
python3 -c 'import cv2; print(cv2.__version__)'
It'll take around 30 seconds, and then you should see:
Long version: read about my quest.