OpenCV, Microsoft HD Lifecam 3000 exposure problems

Okay, so we’re using vision tracking this year, since we’re shooting for the high goal. We decided to use OpenCV, since we didn’t want to deal with FIRST’s apis or GRIP’s. I wrote up some code for getting images from the camera and did some calculations, and it all works great, except for one thing. 90% of the time I go to take a picture, the entire image is incredibly bright. Have you ever pressed something up close to a webcam and pulled it back and seen the webcam get really bright for a second? Yeah, that type of bright is what we’re getting. I think it may be due to how I’m getting the current image (opening the camera, getting the image, and closing the camera), and I’m not sure how to fix it. I haven’t figured out how to tell the HD Lifecam to not auto-adjust it’s settings, and I haven’t been able to find a working alternative to getting the current image other than just turning the camera on and off. We’re doing the vision processing on the RIO (I’m aware people like to do it on driver stations instead, but the RIO works fine for what we’re doing), so I’d appreciate if any suggestions keep that in mind (I am, however, willing to do it on the DS if there’s no other way). So, to summarize all this and put it into question form:

***** How can I stop the Microsoft HD Lifecam 3000 from adjusting it’s exposure/contrast/brightness/whatever automatically?

***** Is there a better, alternate way, using OpenCV, to grab the current image on the camera (Camera.getImage() returns the next frame the camera saw, not the current one).

Thank you to anyone who helps out. If you can, please provide some example code, as I’m much better at understanding your suggestion/logic if at least some of it is laid out in code.

Here’s what we’re using to grab images from the camera. We’re using OpenCV 2.4 in python, but it should translate directly to other languages.

camera = cv2.VideoCapture(0)

    # Capture frame-by-frame
    ret, frame =
    cv2.imshow('Raw', frame)

As for setting the exposure, you can try calling this in OpenCV:


No camera’s exposure goes this low, but this will set it as low as possible.

If I remember right, we had to use v4l to set the LifeCam’s exposure. It wasn’t too difficult to do though, we just had to add it to the same startup script that launched our python vision processing script. Here’s the command:

v4l2-ctl -d /dev/video1 -c exposure_auto=1 -c exposure_absolute=5

You may need to change the video device number to 0.

In addition, we’ve written documentation on much of the process of setting up our vision system. The “Configure the Raspberry Pi” blog has details about how to set up the camera, and the “The Java MQTT Broker” has a section about writing startup scripts on the roboRIO (and I believe Linux systems in general… don’t quote me on that)!news-blog/ck6w

Our code is also available on GitHub if you wanna poke around: