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.

What You Need

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 or Ubuntu systems.

How to Install OpenCV 3.2 to Raspberry Pi Zero W

  1. Enable my Pi Zero repository:

    echo 'deb [trusted=yes] stretch-backports main' |\
      sudo tee  /etc/apt/sources.list.d/bintray-yoursunny-PiZero.list
  2. Update package lists:

    sudo apt update
  3. Install OpenCV package:

    sudo apt install python3-opencv

    Depending on the speed of your Internet connection, this may take between 15 and 30 minutes.

  4. Verify the installation:

    python3 -c 'import cv2; print(cv2.__version__)'

    It'll take around 30 seconds, and then you should see:


How were the Packages Built?

Short version: They were built as a private backport from Debian Buster's opencv package.

Long version: read about my quest.

Tags: OpenCV RaspberryPi