Webcam drivers - Mini Howto Part 2 - Linux uvc cameras

From Gumstix User Wiki
Revision as of 04:46, 5 December 2008 by 189.47.137.189 (Talk) (Building the Linux uvc driver)

Jump to: navigation, search

this is my second Howto on webcams, this time covering uvc webcams. You may need to do some of the steps under the first Howto which deals with cameras using the pwc driver, so it's worth having that to hand also.

As with the first Howto, this is not guaranteed to work on your system but I hope there is enough info here for you to figure out the problem if it doesn't.


01.txt;15;15

04.txt;15;15

Seeing the picture

Why not use motion again?

It didn’t work for me with the uvcvideo driver. I think there may be a problem with motion working with the v4l2 drivers that uvcvideo uses. So if you want to use motion and it’s facilities, one way to do it is to get a stream produced which motion can then use – in the same way as if it would get a feed from an IP camera.

This is what mjpg-streamer does, and it also has the ability to drive the pan / tilt mechanism.

Again, the build uses a Makefile, and the same approach works.

Download from here:

svn co https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer 

Again you edit the Makefile. The structure of the program is a binary and six plugin shared libraries. A number of the libraries also have Makefiles themselves so remember you have to edit each one to avoid the libraries building using the i386 architecture on your build machine. This caused me some headscratching as the libraries built okay but then were unrecogniseable when installed. To build for the gumstix all I did was change the head of the file by making CC = (absolute path to your cross compile gcc), defining the CROSS_COMPILE variable as before, and defining ARCH = arm. I suspect the latter two changes aren’t needed but it did no harm to have them in. No changes are needed to the body of the Makefile.

CD into the main directory and enter "make".

If you have edited the Makefiles correctly, the binary and the six plugins will all be built.

To be honest, these are really simple Makefiles so it should be easy to write a bitbake recipe along the lines of the “hello world” tutorial. However the above approach took me very little time and was effective.

The source download also includes material for a sample webpage which the built in webserver can use. Included is a control page which allows you to drive a pan / tilt camera also.

You can install the libraries in the usual expected places or keep all the files in one directory and run it from there. There is a short script which allows this by exporting the current directory as the library path.

That’s it!

Briany 06:38, 15 July 2008 (CDT)

libwebcam

Logitech has created a library for accessing webcams called libwebcam. Of particular interest to me is the tool uvcdynctrl, which can control all aspects of the camera including the pan and tilt.

Compilation works with two caveats. For cmake, you'll need a toolchain file in order to cross compile for the gumstix. Mine looks like this:

SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
SET(CMAKE_C_COMPILER  /home/randall/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER /home/randall/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-g++)
# where is the target environment 
SET(CMAKE_FIND_ROOT_PATH  /home/randall/gumstix/gumstix-oe/tmp/cross/arm-angstrom-linux-gnueabi)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)


Make sure you've got cmake 2.6 or later. This won't work with earlier versions. I used libwebcam-0.1.1, but I think this works with the current trunk. Create links to uvcvideo.h and uvc_compat.h as instructed in the README. Then:

1. Create a file with text above and call it toolchain.cmake or whatever you like.

2. cd libwebcam-0.1.1

3. in Libs/libwebcam/libwebcam.c, change NAME_MAX to 255 This is a workaround because it seems to pick up limits.h in CMAKE_FIND_ROOT_PATH/include intead of CMAKE_FIND_ROOT_PATH/include/linux/

4. mkdir build && cd build

5. cmake -DCMAKE_TOOLCHAIN_FILE=../../toolchain.cmake ..

6. make


This builds build/Libs/libwebcam.so.0.1.1 (and hyperlink) and build/Apps/uvcdynctrl/uvcdynctrl (and hyperlink). Copy them over to your gumstix in /usr/local/lib and /usr/local/bin respectively and run ldconfig to pick up the library. To get access to all the camera controls, you'll need to copy Apps/uvcdynctrl/data/046d/logitech.xml also and load it with uvcdynctrl -i logitech.xml. There's a way to set this up to happen automagically with udev, but I don't know how yet.

If you've got a pan/tilt camera, run /usr/local/bin/uvcdynctrl -s "Pan (relative)" 1280 and smile! Steps are 1/64 degree (at least on the orbit) and the motor's smallest step is 1 degree. Note that negatives are done like "Pan (relative)" -- -1280

I used the stable version of libwebcam 0.1.1 and the recommended revision 178 of the Linux uvc driver. --Randall 23:57, 21 September 2008 (CDT)