Log 6: Installing OpenCV on the RPI 2

A project log for Control Mechanism of an Autonomous Quadcopter

Obstacle detection system by OpenCv on Raspberry Pi 2 Model B

Canberk Suat GurelCanberk Suat Gurel 02/11/2016 at 21:200 Comments

Before we get started, I'd like to warn you that this stage takes about 3.5 hours total on a RPi 2.

Also during this process, you cannot use the PuTTY because it will lose the connection due to "connection timed out" error. Therefore you need to connect the RPI to a separate monitor via the HDMI cable (just like you've done in Log 1)

Once that's done, power up the RPI and log in with the default username / password, which is pi / raspberry (unless you've changed the log in details by the "sudo raspi-config" command)

Then execute the following commands one by one:

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install python-numpy python-scipy python-matplotlib

sudo apt-get install build-essential cmake pkg-config

sudo apt-get install default-jdk ant

sudo apt-get install libgtkglext1-dev

sudo apt-get install v4l-utils

sudo apt-get install libjpeg8 \
libjpeg8-dev \
libjpeg8-dbg \
libjpeg-progs \
libavcodec-dev \
libavformat-dev \
libgstreamer0.10-0-dbg \
libgstreamer0.10-0 \
libgstreamer0.10-dev \
libxine2-dev \
libunicap2 \
libunicap2-dev \
swig \
libv4l-0 \
libv4l-dev \
python-numpy \
libpython2.7 \
python-dev \
python2.7-dev \
libgtk2.0-dev \
libjasper-dev \
libpng12-dev \



cd opencv-3.0.0

mkdir build

cd build


The next command takes about 3 hours on the RPi 2. I used a mini 5V DC fan to facilitate air circulation and heat dissipation, otherwise I'll overheat due to the fact that this process will push the RPi to the limits of what it is capable of.

sudo make
sudo make install
sudo nano /etc/
# opencv.conf will be blank, add the following line:
/usr/local/lib       # enter this in opencv.conf, NOT at the command line
(leave a blank line at the end of opencv.conf) then save and exit nano

# back to the command line:

sudo ldconfig
sudo nano /etc/bash.bashrc
# add the following lines at the bottom of bash.bashrc
# enter these at the bottom of bash.bashrc, NOT at the command line
# enter these at the bottom of bash.bashrc, NOT at the command line
(leave a blank line at the end of bash.bashrc)

# save bash.bashrc changes, then back at the command line, reboot

sudo shutdown -r now
# after rebooting, verify our OpenCV install:
# enter interactive Python prompt session
>>> import cv2
>>> cv2.__version__

# should say your OpenCV version, i.e. '3.0.0', press Ctrl+D to exit the Python prompt session