Ask Your Question

Enable Auto Exposure using code

asked 2013-10-07 11:19:53 -0600

MarxWright gravatar image

I've had trouble with this before hen trying to disable the Auto Exposure on my webcam, I managed to do it by setting the CV_CAP_PROP_EXPOSURE value which automatically disabled the Auto Exposure.

I'd now like to be able to turn it back on for a few seconds and then disable it again but any value I set for CV_CAP_PROP_AUTO_EXPOSURE doesn't seem to take yet I can open a dialog with CV_CAP_PROP_SETTINGS and enable it from within that popup.

There must be a way to enable this through code if it's possible through the Settings dialog.

I thank you for your time and any help you can offer.

edit retag flag offensive close merge delete


I'm having the same trouble except my camera doesn't respond when I try to set the exposure. After I set it I can get the value and the value has changed but the camera still returns an overexposed image as if I haven't changed the value. I'd be happy to build a patch for OpenCV if I could figure out how this particular camera works. Can someone point out where to start poking around in the code? I know it can be done because the software that came with the camera has an exposure feature and is adjustable from their GUI. I'm using Qt Creator on windows 7 in C++. The camera is a MicroView USB Microscope ($80) from adafruit.

GHD gravatar imageGHD ( 2013-10-10 15:17:16 -0600 )edit

I don't know if this will help you but I've had some success by setting the exposure value then calling QueryFrame twice and set the exposure value again. The next QueryFrame after that might come out with the expected value. This might not help with your particular camera but it seemed to work with mine and it doesn't help with the original question.

MarxWright gravatar imageMarxWright ( 2013-10-21 06:16:13 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-01-11 16:07:12 -0600

I know this is a very old post, but just in case other stumble upon it, let me offer the solution I used. First of all, I'm using OpenCV 2.4.11. At least in that version, the CV_CAP_PROP_AUTO_EXPOSURE is not implemented. However, it turns out that the logic that handles setting CV_CAP_PROP_EXPOSURE (at least the DirectShow-based interface used for Windows) already has the hooks necessary to restore the default values for the exposure setting.

The code is found the opencv\sources\modules\highgui\src\cap_dshow.cpp in the videoInput::setVideoSettingCamera function. I added the following code as a quick and dirty solution for restoring auto-exposure functionality:

if ( (Property == CameraControl_Exposure) && (lValue == 0.0) ) useDefaultValue = true;

Then rebuild the highgui library and use the modified copy. This allows you to restore the auto-exposure using cap.set(CV_CAP_PROP_EXPOSURE, 0.0) in your code. Of course, really you ought to implement CV_CAP_PROP_AUTO_EXPOSURE for a proper solution, but this has worked well for my purposes.

Hope this helps someone.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-10-07 11:19:53 -0600

Seen: 24,142 times

Last updated: Jan 11 '16