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 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

Set up Python

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

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

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
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_C_EXAMPLES=OFF \
    -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

Verifying your OpenCV install

$ sudo python
>>> import cv2
>>> cv2.__version__
'3.1.0'
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.