Skip to main content
dot-patterns opencv

Computer vision, OpenCV, Raspberry Pi, Webcams and CSI Raspicam

Before start to talk about the installation of openCV in a Raspberry Pi it’s important to clarify something:

  1. If you use a regular USB camera attached to the Raspberry Pi, the installation is basically the same as any other debian like distribution.
  2. If you use the Raspicam CSI camera, you must use UV4L (UserVideo4Linux) drivers and all will be a little bit tricky, and currently I didn’t tried yet to install the UV4L drivers to use the Raspicam CSI camera, but here are some resources about it*:

*NOTE: OpenCV works with raspicam following the instructions below (the same as the USB camera), but as far as I have been able to test, the video driver with raspicam has very low framerate and the scripts don’t run as good as with USB camera.


Ok, so, let’s continue with the installation of openCV in a debian-like distribution (Raspbian in particular):

The information below is not mine, it’s based on this great website about openCV and Raspberry Pi, I reproduce here the basic installation steps for record purposes only.

sudo aptget update

sudo aptget upgrade

#check to see that your webcam, or pi-cam is being read by your pi:


#you can test it by downloading the following

sudo aptget install guvcview

#and enter the following command:


#for easy package installation you can download synaptic

sudo aptget install synaptic

#install the python scipy stack

sudo aptget install pythonnumpy pythonscipy pythonmatplotlib pythonnotebook pythonpandas pythonsympy pythonnose

#to get the OpenCV zip or the tar.bz2 or the tar.gz:


#install basic development environment

sudo aptget install buildessential cmake pkgconfig

sudo aptget install defaultjdk ant

sudo aptget install libgtkglext1dev

sudo aptget install bison

sudo aptget install qt4devtools libqt4dev libqt4core libqt4gui

sudo aptget install v4lutils

sudo aptget install qtcreator           (you do not really have to have it)

#not on the original video tutorial

#more raspberry pi specific opencv-related dependencies that will make your life much easier

sudo apt-get install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs ffmpeg libavcodec-dev libavcodec53 libavformat53 libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev swig libv4l-0 libv4l-dev python-numpy libpython2.7 python-dev python2.7-dev libgtk2.0-dev

#ready to start compiling opencv

#now extract the opencv folder by unzipping the zip file you downloaded from Sourceforge


#change directory to the folder that you just extracted

cd opencv2.4.9.1

#create a directory called build

mkdir build

#change into that recently created directory

cd build

#very important step to create the flags and instructions for the compilation process


#now you are ready for make

sudo make

#and now you are ready to install  ***very important make sure you include sudo with the command

sudo make install

#create the following file:

sudo nano /etc/

#enter the following line into the empty file:


#after saving the file, enter the following command:

sudo ldconfig

#open your bash.bashrc file by entering the command:

sudo nano /etc/bash.bashrc

#in your bash.bashrc file enter the following two lines at the end of the document:



#save it and close the terminal, and log back in by opening a new terminal to make sure your changes to the bash.bashrc file take effect.

#Testing to make sure that everything is working properly:

#open the c samples directory:

cd ~/OpenCV-2.4.9/samples/c

chmod +x


#find an executable and run it by entering the following:


#if you want to test the python, go to the python directory and enter the following:


e.g   python

#and it will run.

Tutorial video

There is also a great video tutorial from the same guys:

The final test

Edge python script running 🙂

OpenCV edge script running
OpenCV edge script running

Leave a Reply

%d bloggers like this: