Curious Emperor PenguinUsing Webcams Under Linux

 

 

 

 

Table of contents:


Drivers

Webcam support under Linux is pretty decent overall. As with most USB things under Linux, though, getting a particular camera to work with your setup can be hit and miss.

The largest manufacturer of webcams is Logitech. They aren't very Linux-friendly, but their cameras are generally well supported. I haven't used many other manufacturers' cameras, so I can't provide input on how they work. However, there are only a few common camera sensor/controller chips out there (for better or worse...), so a driver for another camera using the same chip may work with yours, too.

When trying to find a Linux driver for a USB device, the first thing to do is to note the USB ID (which is a combination of a two-byte vendor and two-byte product ID) reported by the kernel. Then, you should search for that ID in the supported devices database. It's quite likely that someone has tried the device before and posted their results. Even if the report is grim, don't despair -- sometimes it takes a while for the database to get updated after a driver is released.

To save you some time, here are a few direct links to common drivers:

Depending on your camera, things might work better (or at all) only under one of kernel 2.4 or 2.6. Many of the recent ones work best (or at all) only under 2.6, while many old ones might require 2.4. Sometimes there are drivers for both, but you'll find that one series is more stable than the other.

If you can afford it, I personally recommend the Quickcam Pro 4000. It's about $100 and well supported by the new pwc driver. I've been able to do 320x240 at 30fps (640x480 should be possible too but I've never gotten that working reliably).


Labtec Webcam

The webcam given out in the CMU humanoids class is a Labtec Webcam. For those curious, the vendorid/productid is 0x46d/0x870. It seems to be supported by the qce-ga driver. There aren't any debian/redhat/whatever packages available to my knowledge, but the installation from source is pretty simple. Read the README file and run quickcam.sh in the top directory.

I've managed to run the camera at 320x240 at 5.67fps using most any colorspace except YUV420/422. A higher framerate should really be possible (what can it achieve in windows?), so this might be a driver limitation. The maximum resolution appears to be 352x292, with smaller resolutions just cropping the image.

The image quality isn't fabulous (and presumably worse than the windows driver can achieve), but it's surely adequate for a lot of experimentation. Some practical advice might be to try running the camera in black and white mode (i.e., by selecting grayscale in the capture library you're using), since most vision algorithms use intensity (grayscale) images anyway and skipping the intermediate grayscale conversions improves the image quality somewhat. You might also want to fiddle with the camera settings using the "qcset" utility included in the driver distribution. Another piece of advice, especially when trying vision algorithms for motion processing, is to move the camera verrry slowly to avoid blurring effects that can break your algorithm.

If anyone discovers a better driver or some way to make things work better than I've here described, let me know, and I'll post that here.


Framegrabbing

Framegrabbing is done under Linux using the video4linux (v4l) API. There are now 2 versions out there (versions 1 and 2). Most things still use version 1, and I've managed to get away with using just that.

The API is pretty complicated and can require some intimate knowledge of colorspace representations to get what you want. You'll probably instead want to talk to some higher level layer that does the work for you.

Here are a few libraries that help with this:

If you just want to check to see that your camera is working by viewing an unprocessed video stream, a lot of standard video players such as Xine and MPlayer support video4linux inputs.

It's also useful to know that there exist a number of commandline utilities both for specific cameras and for v4l generally that tweak configuration parameters, such as the current resolution, framerate, etc.

A common gotcha is getting the requested colorspace right. Many cameras can produce RGB24 images just fine, while others (Quickcam Pro 4000s, for instance) seem to only want to produce YUV420P images.


Example Programs

The very simple extremely high level interface provided by OpenCV can be a great way to get started. Many of the provided sample programs (in the samples/ directory in the source tree) use live camera input.


Software and Link Recommendations

Presumably, you're doing this to try out computer vision stuff. Here are some useful links for that:


Last modified 10/18/2005