Modified uvccapture

I’m using Microsoft LifeCam Cinema webcams, which support both YUYV and MJPEG capture modes. However, in YUYV mode, auto exposure correction doesn’t work correctly (or maybe at all). After resetting (or plugging out and in) a webcam, the exposure will be at max, and it won’t auto change if I use the YUYV mode. In MJPEG mode, it needs a few secs to compensate a light change.

So my changes in uvccapture-0.5:

  • I added a -D option to uvccapture for this. After opening the /dev/videoX device, it waits for the given predelay secs and then it captures the frame. This way when the camera is in MJPEG mode, it can auto change the exposure while uvccapture is predelaying.
  • Corrected JPEG header output, when saving MJPEG frames. The default routines in uvccapture saved an unreadable JPEG file, now it’s fixed.
  • It parses output filenames with strftime, so this will save the full date in the filename: -o%Y%m%d%H%M%S.jpg
  • Only saves JPEG when -o is set
  • No auto YUYV capture, by default it uses MJPEG, if you want it, use the -m switch
  • Resetting brightness/contrast/saturation/gain controls only when one of the regarding cmdline option is used

Merged the following modifications by Reece Arnott and John:

  • changed the include statements in uvccapture.c and v4l2uvc.c from linux/videodev.h to linux/videodev2.h
  • added the -i cmdline switch to have the ability to have an initializing script run before an image is captured (this means that -D option could be done with -w -i<script>
  • predelay sleep optionally keeps taking 1 image/sec (-W cmdline switch)
  • daemon feature with -b cmdline switch
  • additional post delay option

Current version: uvccapture-0.5-nonoo-r4

download (16 kb)


Debian packages built by John:

download (50.4 kb)


I’m using uvccapture this way (to allow my Microsoft LifeCam Cinemas to auto adjust exposure):

uvccapture -v -d/dev/video -x1280 -y720 -D4
uvccapture -v -d/dev/video -x1280 -y720 -D3 -o%Y%m%d%H%M%S.jpg

(Yes, two sequential calls to uvccapture, one with 7 secs predelay is no go, I need two calls. The first call won’t save anything, just opens the device and waits given secs).

maya 2011-06-22 11:17:30

When I invoke uvccapture just once, the image that I get is very dark. But when I set the -t option and take shots continuously, the image becomes brighter and clearer after some time. But this doesn’t work with setting the time delay.
Can you pls help me out?

Thanks in advance.

Nonoo 2011-06-22 11:19:37

Invoke uvccapture twice, as shown in the example above.

maya 2011-06-22 11:27:09

yes i tried that, but its still the same… Does it have anything to do with the auto focus feature of the camera??

Nonoo 2011-06-22 11:29:49
maya 2011-06-22 13:45:50

I tried as you’ve mentioned, but i get this message:

VIDIOC_S_STD: failed: Invalid argument

Nonoo 2011-06-22 13:55:05

Update your UVC driver in the kernel.

 
 
 
 
 
 
Pingback by Bookscanner project | DSpace.org.nz 2011-09-12 00:05:48

[…] forked version of uvccapture came originally from http://dp.nonoo.hu/modified-uvccapture/ and will capture a in MJPEG mode for all resolutions by default. I have added a -i option for […]

 
John 2011-09-23 05:18:01

Thanks so much for making these patches available, for what ever reason YUYV mode locks up uvccapture, so 960×720 was the max size I could pull from the camera.

A couple of quick suggestions, the delay just doesn’t work for me, the only way auto exposure kicks in is if images are actually taken, so if you are still working on this, maybe an option to dump images to /dev/null.

The other option that would be nice is some kind of background mode/daemon mode so it could run constantly in the background taking minutely images.

Nonoo 2011-09-23 07:57:19

I’m not working anymore on this project, uvccapture works fine for me. I think outputting images to /dev/null is supported, try it out. If you want images taken minutely, you should use cron.

John 2011-09-23 12:19:48

You seem to have misunderstood me, I can’t use cron because unless the camera is constantly taking images the webcam’s auto exposure etc doesn’t kick in.

I’ve built a quick patch that I think should address the features I am looking for:

http://pastebin.com/BNAnJvsV

Adds daemon functionality and modifies the sleep to keep taking images, rather than taking one image and then sleeping.

Nonoo 2011-09-23 12:23:53

Cool, could you please make a command line parameter which can toggle that the camera should take images while sleeping, or take just 1 picture? If you could do this, I’ll merge your patch into my version of uvccapture. Thanks

John 2011-09-23 13:30:12

Ok, made the preDelay loop optional as you requested, default is it will only do 1 image as per your patch.

I also added code to exit the preDelay loop if ctrl+c is hit, otherwise you have to wait for the preDelay to finish first.

http://pastebin.com/VyARaPG0

 
 
 
 
 
John 2011-09-24 13:09:11

Thanks for merging my patch, if you use the -W option you probably don’t need to use uvccapture twice, in fact you might only need a smaller delay if you pull an image per second.

Nonoo 2011-09-24 13:13:36

Yes, you’re right. I didn’t modify my webcam scripts as it currently works fine with the old settings :)

 
 
John 2011-09-24 13:33:57

Hopefully this is my last patch :D

http://pastebin.com/x9dPXRiz

I added an additional post delay option, that way you could have a 5s predelay and then a much larger postdelay of say 55s etc…

Nonoo 2011-09-24 13:40:31

Could you make a diff using the latest version of my uvccapture as the base?

John 2011-09-24 13:56:59

I actually thought of that after posting, I also added a sanity check for the pre/post delay to make sure they’re positive numbers.

http://pastebin.com/GYwD6gm5

 
 
 
Name (required)
E-mail (required - never shown publicly)
Webpage URL
Comment:
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> in your comment.

Trackback responses to this post

About me

Nonoo
I'm Nonoo. This is my blog about music, sounds, filmmaking, amateur radio, computers, programming, electronics and other things I'm obsessed with. ... »

Twitter

Listening now

My favorite artists