A Dirty Hack for OpenCV on the OLPC XO

OpenCV has issues using the camera on the XO, rising from the way it negotiates color palette settings with the OV7670 v4l2 driver.  I haven’t delved deep enough into v4l2 yet to come up with a proper fix for either the driver or OpenCV.  However, I have a temporary fix that (probably) works fine but is very ugly.

The easy and dirty solution is to install the opencv, opencv-devel, and opencv-python packages with yum, to download the libhighgui.so.1.0.0 that I compiled, and to copy it to /usr/lib/libhighgui.so.1.0.0.  In short:

sudo yum install opencv opencv-devel opencv-python
sudo wget  http://eclecti.cc/files/2008/03/libhighguiso100 -O /usr/lib/libhighgui.so.1.0.0

The details of the problem are that when using ioctl with VIDIOC_S_FMT to negotiate the correct fmt.pix.pixelformat, ioctl fails with EINVAL (error 22), even when all the values being supplied by OpenCV are the values that the OV7670 wanted anyway.  The temporary fix involves using VIDIOC_G_FMT instead to let the OV7670 tell OpenCV what it wants.  Luckily, what it wants, OpenCV can handle.  If you want to build OpenCV from source and fix it, you’ll need to change line 419 in otherlibs/highgui/cvcap_v4l.cpp to the following:

if (-1 == xioctl (capture->deviceHandle, VIDIOC_G_FMT, &capture->form))

Unfortunately, there are other problems with building OpenCV on the XO. (aside from it being painfully slow to compile on)  One of the dependencies, gtk2-devel, currently will not install, a known bug.  I got it to work with the following, but YMMV:

yum -t –enablerepo=* install libXi-devel
yum -t –enablerepo=* install gtk2-devel

I also ran into a problem trying to compile python/swig support, but that may be from unrelated memory leaks…

Related Posts

4 Responses to “A Dirty Hack for OpenCV on the OLPC XO”

  • It turns out the actual problem is not with the colorspace as I suspected, but the field value. It is fixed in the latest CVS source.

    Changing line 414 from
    capture->form.fmt.pix.field = V4L2_FIELD_INTERLACED;
    capture->form.fmt.pix.field = V4L2_FIELD_ANY;
    will fix the problem.

    The fix described in the post works, but this fix will more generally work for other cameras.

  • An alternative to compiling on a real XO is to compile in emulation, and then copy across the resulting files. For example, I’ve had an emulation image, with enlarged disk, and the full gcc toolchain. But cameras have not been supported in emulation, so that may not help here. And emulation isn’t well supported by OLPC, so for the last few months, only qemu from CVS has been able to run current builds.

  • hello! I’m developing a driver for Linux in 2.6.30 version for ov7670, but I haven’t a good configuration, can you send me your configuration? thank you.

Leave a Reply