Compiling OpenCV on Raspberry Pi

To get the latest version of OpenCV on my Raspi, I follow the Installing OpenCV on a Raspberry Pi guide by Robert Castle.

Installing the dependencies is fine, and I use

git clone

to get the latest version (2.4.9).

I know from previous experience that memory is a problem, make stalls at

[ 37%] Building CXX object modules/core/CMakeFiles/opencv_perf_ core.dir/perf/opencl/perf_arithm.cpp.o

To help get around this I enable a fairly large swap, 2GB, compare with RasPi’s 512kB of physical memory.  Running top during the make, I saw at times when there was as much  swapped memory as physical memory in use.

Even with this, the build stalled. What got it working was accessing the Pi via ssh, rather than running LXDE via TightVNC,  and making sure no desktop was running (I have it start by default) with

sudo /etc/init.d/lightdm stop

I also killed tightvnc, Xorg and other X or desktop manager related processes.

After that OpenCV compiled in (but it took a day), and it works. That is to say that the python demo works samples/python2 directory displays a video that up dates about 1 frame per second. Testing it more thoroughly in python and getting it working with the picam is next.



2 thoughts on “Compiling OpenCV on Raspberry Pi

  1. Interesting, what are you planning on using OpenCV for on a pi? I have been looking in to a banana pi to see if I could do anything interesting with motion detection, I hadn’t come across OpenCV before, but was thinking about doing something with Zoneminder logs.

    1. I’ve always wanted to create a computer controlled scalextric. I’ve done something with sensors in the track to monitor where the car is, but computer vision would be cooler. That said, I don’t think the pi is up to it, it won’t keep up with a car going at any speed, but the whole computer vision object tracking thing is pretty amazing.

Comments are closed.