Previous posts

Post 1 - Introduction

Post 2 - Installing OpenCV - Prerequisites


At this point we have all of our prerequisites installed, so let’s grab the 3.1.0  version of OpenCV from the OpenCV repository.


$ cd ~
$ wget -O
$ unzip


For the full install of OpenCV 3 (which includes features such as SIFT and SURF), be sure to grab the opencv_contrib repo as well.


$ wget -O
$ unzip


The first step in setting up Python for our OpenCV compile is to install pip , a Python package manager:


$ wget
$ sudo python


we can install NumPy, an important dependency when compiling the Python bindings for OpenCV. NumPy downloads and installs will take a while...


$ pip install numpy


We are now ready to compile OpenCV.


$ cd ~/opencv-3.1.0
$ mkdir build
$ cd build
 -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \


Now that our build is all setup, we can compile OpenCV:


$ make -j4


The -j4  switch stands for the number of cores to use when compiling OpenCV. Since we are using a Raspberry Pi 2, we’ll leverage all four cores of the processor for a faster compilation.

However, if your make  command errors out, I would suggest starting the compilation over again and only using one core:


$ make clean
$ make


Using only one core will take much longer to compile, but can help reduce any type of strange race dependency condition errors when compiling.

Assuming OpenCV compiled without error, all we need to do is install it on our system:


$ sudo make install
$ sudo ldconfig


Provided build finished without error, OpenCV should now be installed in/usr/local/lib/python2.7/dist-packages :


$ ls -l /usr/local/lib/python2.7/dist-packages/


Let’s verify that your OpenCV installation is working by importing cv2 , the OpenCV + Python bindings:


$ python
 >>> import cv2
 >>> cv2.__version__


You can see a screenshot of my terminal below, indicating that OpenCV 3 has been successfully installed:


OpenCV Version.png