OpenCV in action: Fungi by Todd Vanderlin. (CC)

Linux can be an ideal operating system for visualists – with a little attention, anyway. Because it’s a free OS, you have a unique amount of control over hardware, and you can easily deploy your setup to any machine – perfect for last-minute computer changes for gigging, or for shipping off for installations. We’ll be looking at various tips for working with this OS, but I wanted to start with some install tricks for using Intel’s widely-used, open-source computer vision platform. On Windows and Mac, you have fairly easy installers. Linux is trickier.

Worse, a recent Ubuntu bug kept me from installing at all. Basically, it’s possible to install packages depending on ffmpeg (like Blender) in ways that prevent other key dependencies from installing correctly. (I think I described that more or less accurately.) The most active iteration of this bug:

Bug #312898: libxxx-dev should be installable with libxxx-unstripped

That bug has a number of duplicate reports, such as 343005.

This is already fixed in a file that is available in Karmic, aka 9.10, the release due out this fall and currently in alpha. But I didn’t want to wait. Here’s the fix that finally worked for me.

1. Install ffmpeg and development libraries. Get the ffmpeg dependencies from Karmic and install the .deb files one at a time. Start with libavformat-dev. Package Installer (gdebi-gtk) will return an error if another dependency is required. One at a time, install the dependencies (you may need to choose File > Refresh once a file is installed) for each package it requests. The files are available here:
ffmpeg-debian in Ubuntu Karmic
So, for 32-bit, the most current downloads I grabbed were at:
i386 build of ffmpeg-debian 4:0.5+svn20090609-1ubuntu3

2. Use a fixed version of OpenCV for Ubuntu. Once ffmpeg is installed, you’ll want to grab a different version of OpenCV that has some fixes for capture. (I actually was unable to even install the OpenCV version from subversion, so this was quite a lot easier.) The problem – and solution instructions – are detailed in a blog post by Gijs Molenaar.
Getting video i/o working with opencv and Ubuntu Jaunty (9.04)
He also provides a package repository for his fix:

3. Laugh heartily and enjoy. Once you’ve got all of this working, it should be easier to make use of OpenCV in OpenFrameworks (site | cdm tag), and to use the handy OpenCV library for Processing (site | cdm tag) — which in turn comes with some great example code.

OpenCV Library for Processing (a project of the Atelier hypermédia at the École Supérieure d’Art d’Aix-en-Provence,maintained by Stéphane Cousot and Douglas Edric Stanley.)

The next challenge: getting multiple cameras working easily, so you can, for instance, ignore your built-in webcam and use a PS3 Eye. The solution to that appears to be OpenCV’s cvCam library, which I think is not fully supported in the Processing library (yet – I may try to get that working).

Multiple cameras with cvCam and OpenCV [OpenCV FAQ]

Andy Best has done some terrific tutorials on making use of this combination:

Processing Tutorials: Getting Started with Video Processing via OpenCV

OpenCV Motion Tracking, Face Recognition with Processing: I’m Forever Popping Bubbles

Now, please note: this is me hacking around. Your mileage may vary — and some folks reading this site may have a better sense of what they’re doing than I do. So definitely let us know your feedback, whether you’ve worked out a better way or have found other issues.

Also, I really do wonder: is there a way we could start to maintain a Launchpad repository for everything you need for video capture and computer vision in Processing under Ubuntu, rather than having to cobble together solutions? The problem is, with this many different pieces, video often winds up painfully out of sync. That’s not just a Linux problem – Mac and Windows often suffer, too. But on Linux, it’s solvable.