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 https://github.com/Itseez/opencv.git
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.