Installing OpenCV 3.1.0

Mark Boszko edited this page May 11, 2016 · 5 revisions

Instructions based on PyImageSearch's great instructions, updated for OpenCV 3.1.0 and dropping the use of virtualenv, because (1) the Raspberry Pi is single-purpose, and (2) the rpi_ws281x library doesn't seem to play nice with it. I’m using Python 2.7, because I'm not sure if some of the libraries I want to use for the Volcano project are ported to Python 3.

Install Dependencies

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo rpi-update
$ sudo reboot
$ sudo apt-get install build-essential git cmake pkg-config
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
$ 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

Grab the OpenCV source code

$ cd ~
$ wget -O
$ unzip
$ wget -O
$ unzip

Set up Python

This bit may not be necessary if you ran the Adafruit bootstrapper, since that already installs pip:

$ wget
$ sudo python

Install numpy

May be already installed; if so, it will tell you instead of re-installing.

$ pip install numpy

Compile and install OpenCV

$ cd ~/opencv-3.1.0/
$ mkdir build
$ cd build
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \
$ make -j4
$ sudo make install
$ sudo ldconfig

Verifying your OpenCV install

$ sudo python
>>> import cv2
>>> cv2.__version__
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.