Monday 16 November 2009

Image grabbing using ubuntu


To make a USB Web-camera to work on linux system you need to Install the webcam driver for web-camera. In most cases, webcam drivers differ according to the model of the webcam attached to your PC and according to the computer's operating system and the on-board video card. The main function of a webcam driver is to allow the operating system and installed webcam software applications to transmit digital images/video from the camera through the PC to an application / steaming connection.

In most cases, advanced operating systems such as Linux, Windows XP and Windows Vista contain default drivers that can detect a webcam on the first instance it is connected to the machine.

In Linux distributions many webcams will "just work" by default.

In Linux there are 2 different drivers which covers the majority of web-cameras available, these are the gspca and linux-uvc driver. You will need to determine which is the correct driver to install. If you are not sure which webcam you have you can make use of the 'lspci' and 'lsusb' commands to print a list of devices on your system.

After determining your webcam type you need to see which driver supports your webcam. Here is a list of webcams supported by the gspca driver (http://mxhaard.free.fr/spca5xx.html) and the Linux-UVC project has a good list of UVC compatible webcams supported by the linux-uvc driver (http://linux-uvc.berlios.de/#devices).

If you webcam doesn't appear on either list then it's possible your webcam isn't supported. If you like you can just try installing both drivers anyway and see how you go.

Linux UVC driver project
The goal of this project is to provide all necessary software components to fully support UVC compliant devices in Linux. The USB Device Class Definition for Video Devices, or USB Video Class (UVC), defines video streaming functionality on the Universal Serial Bus. Much like nearly all mass storage devices (USB flash disks, external IDE disk enclosures, ...) can be managed by a single driver because they conform to the USB Mass Storage specification, UVC compliant peripherals only need a generic driver.

GSPCA project
The gpsca video for linux (v4l) driver, provides support for webcams and digital cameras based on the spca5xx range of chips manufactured by SunPlus, Sonix, Z-star, Vimicro, Conexant, Etoms, Mars-semi, Pixart and Transvision.The gspca driver is a rewrite of the well known spca5xx v4l kernel module from the same author, Michel Xhaard.

Installing UVC driver on Ubuntu

Ensure that you have the header files for building the UVC module with:

# sudo apt-get install linux-headers-`uname -r`

In latest versions of Ubuntu the UVC module has been included which means that some webcams 'just work' but it is recommended that you still download the source code at LinuxTV uvcvideo development repository - (http://linux-uvc.berlios.de/#download)


Navigate to the 'uvcvideo' directory (or some similar name) containing the source. If you want to customize which drivers to compile, run:

# make menuconfig

If you do not know how to customize, just accept the defaults and exit by pressing ESC twice. To compile the drivers, run

# make

then, to install the compiled drivers to the appropriate module directories, run

# sudo make install

followed by

# sudo depmod -a

After that just ensure that you can see the webcam connected to the USB using:

# lsusb

If it is there, then run:

# sudo modprobe uvcvideo

Installing GSPCA driver on Ubuntu

GSPCA drivers are by default provided with ubuntu distribution. Else try the following command to install it.


# sudo aptitude install gspca-source -y

In the /usr/src directory, archive with driver source gspca-source.tar.bz2 will appear. Unpack it and change directory to /usr/src/modules/gspca and execute following:

# make

Module must compile without errors. Next, do this:


# sudo make install


This command will install your module in directory, were other kernel modules are placed. Optionally it can be executed:


# sudo depmode -a

That`s almost all, our goal is to load module of a webcam:

# sudo modprobe gspca

Testing your webcam

Ekiga is installed by default in Ubuntu, and can be used to test your webcam. For UVC devices luvcview is a good program you can use to test that the camera is working. If it doesn't work, you may need to update the UVC driver. Cheese, Camorama, xawtv, VLC, aMSN, and Kopete are all in the Ubuntu repositories. They all can be used to test and use your webcam. In some cases you (VLC, mplayer, amongst others) will need to know the video and audio device files for your webcam. Before you plug in your webcam, try the following two command at a console:

# ls /dev/video*
# ls /dev/audio*

Make a note of the devices appearing. Now plug in your webcam, allow the system a few seconds to register the device, and run the two commands again. The new appearances should belong to your webcam (for instance, /dev/video1 and /dev/audio2).


Command Line Image Grabbing in Linux

Streamer

Streamer (http://linux.bytesex.org/xawtv/) is a versatile program that allows a capture from a webcam or video device using only the command line. It may be offered in your Linux distribution's Xawtv package. To install streamer try

# sudo apt-get install xawtv

To take a standard JPEG picture from the command line where the camera is accessed through /dev/video0:

#streamer -c /dev/video0 -b 16 -o outfile.jpeg

Where > -b is the number of colors (in bpp,whether 15, 16, 24 or 32)
& -o is the output filename in the current directory

If you are going to capture multiple images be sure to append the output file name with zeros, as streamer can name the capture files in sequence, i.e., -o outfile000.jpeg becomes outfile001.jpeg, outfile002.jpeg, and so on.

Motion

Motion (http://www.lavrsen.dk/twiki/bin/view/Motion/WebHome) is a brilliant program that is able to monitor the video signal from one or several webcams. It can record periodic snapshots, and when motion is detected, record an mpeg and/or perform another action such as sending an email or executing a command. It can track and graphically mark the motion it detects, feed files via an http server to your website, stream them to another application and more. The number of command line options may be intimidating; there is however, a Wiki available online (http://www.lavrsen.dk/twiki/bin/view/Motion/MotionGuide) that outlines the various command and configuration file options nicely.

camE


camE is a rewrite of the xawtv webcam application using imlib2. It is a command-line program that works in daemon mode to capture frames from your v4l device for archive or upload (to a webserver, for example) via ftp or scp. You can overlay other graphics, timestamp the frames, or add other dynamic text all by altering the appropriate line in the configuration file.

No comments: