Installing OpenCV on the Raspberry Pi

UPDATE 2:Here is my guide for Arch Linux

UPDATE: I’ve moved to Archlinux because it has the webcam modules included. OpenCV is really easy to install: pacman -S opencv

Installing OpenCV (2.3.1) on the Raspberry Pi is pretty easy using the base Debian Squeeze image and following these instructions for Debian/Ubuntu.You will need to have more space on the root partition so I recommend resizing it to at least 3GB (see the video tutorial using GParted or follow these instructions). Here they are with some comments on the few issues I found:

I found an error trying to install cmake for the first time, so first do

sudo apt-get update

two times before anything else. The first time I did the update an error on “duplicate sources” was shown thus the second update was necessary.

Install in the following order:

sudo apt-get install build-essential
sudo apt-get install cmake 
sudo apt-get install pkg-config 
sudo apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3 
sudo apt-get install libpnglite-dev libpngwriter0-dev libpngwriter0c2 
sudo apt-get install zlib1g-dbg zlib1g zlib1g-dev 
sudo apt-get install pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools 
sudo apt-get install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs 
sudo apt-get install ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev 
sudo apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0  libgstreamer0.10-dev 
sudo apt-get install libxine1-ffmpeg  libxine-dev libxine1-bin 
sudo apt-get install libunicap2 libunicap2-dev 
sudo apt-get install libdc1394-22-dev libdc1394-22 libdc1394-utils 
sudo apt-get install swig 
sudo apt-get install libv4l-0 libv4l-dev 
sudo apt-get install  python-numpy 
sudo apt-get install libpython2.6 python-dev python2.6-dev 
sudo apt-get install libgtk2.0-dev pkg-config

The package build-essential was already installed on my device so maybe you don’t need to install it. Note that for the eighth line the original link says “libjpeg-prog” but it must be “libjpeg-progs”. Also, check the last step that is not included on the original instructions but it’s needed for this platform.

Get the sources (check the version you want to install):


Uncompress the sources and create a directory inside it (I called it ‘release’). Chdir to it. Run cmake to configure, compile and install. Compilation will take a while, about a couple of hours:

sudo make install 

Now you can run the samples. In this image, the Python version of contours: