Installing OpenCV 3 on Raspberry Pi 3

Learn how to install OpenCV 3 on your Raspberry Pi 3 running Raspbian Jessie.

Project State

Public Project

Licences

Software Licence: Project has no software
Hardware Licence: Project has no hardware

Project Tags

Admins

StudentCV

Does this project pique your interest?

Login or register to join or follow this project.

Installing OpenCV 3

This guide will help you set up the OpenCV 3 image processing library. It's goal is to keep the process short and efficient. For a detailed guide with in-depth explanations check out the instructions here. We will include the Python 3 bindings, as we need them for further projects like the "Face Detection using PyPylon" which you can find here.

Prerequisites

  1. This guide assumes that you're running Raspbian Jessie or a similar derivate (think Ubuntu) on your machine. Make sure Python 3 is already installed, which is the case if you are using Raspian Jessie.
  2. You should have enough free space on your micro-SD card as OpenCV needs a few gigabytes during the compile. An 8 GB SD card should be fine, but a minimum of 16 GB is advised.
  3. Ensure your system's software is up-to-date by running the following commands from your terminal:

    sudo apt-get update sudo apt-get dist-upgrade sudo raspi-update

Getting the installation process started

Installing libraries and dependencies:

sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python2.7-dev python3-dev

Download OpenCV 3.1.0: In the future you might want to change the 3.1.0 in the following code snippet to the newest version. You can check out the newest version here.

cd ~
wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.1.0.zip
unzip opencv.zip
wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip
unzip opencv_contrib.zip

Installing the Python 3 package manager:

wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

Installing NumPy:

pip install numpy

Compile and install OpenCV 3.1.0: Remember to update the version, if you used another version than specified before. Also, notice that this step can take a couple of hours.

cd ~/opencv-3.1.0/
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \
    -D BUILD_EXAMPLES=ON ..
make -j4
sudo make install
sudo ldconfig

Testing OpenCV 3 installation: To test the installation it is easiest to open Python and check whether it is possible to import the bindings. As a result this step should show you the installed version which is in this case 3.1.0 or a newer version of OpenCV.

cd ~
python3
import cv2
cv2. __version__

 

 

 

Comments

matt-amacker report abuse
These worked great! Thanks! One edit: raspi-update should be rpi-update... I think? Thanks!
berkcanacikgoz report abuse
if you are getting stdlib.h not included error, try adding: -D ENABLE_PRECOMPILED_HEADERS=OFF
ahmed-samir report abuse
can any one upload finished image (.img)to Raspberry b+ with opencv3
prateek-aranha report abuse
sudo apt-get update isn't working
WeepingAngel report abuse
prateek-aranha, that is suprising because it is a standard of the updating system. Do you have a more specific error message you can post? (remember many firewalls of companies stop apt-get working properly).

Ready to join the project?

You'd like to participate ... Show more