Manual Exposure vs Auto Exposure for ELP 2 MP USB Camera

For our drone flying project, we have been using the ELP 2 Megapixel USB Camera. The auto exposure on this camera works in most situations, but we found that it does not always adjust to bright sunlight. In preparation for demonstrating our computer-controlled drone at the Maker Faire, I wanted to have a plan in case we were outdoors. It was a good thing too, since we were assigned an outdoor booth next to the Drone Combat arena.

We detect the location of our drone by using blob detection on four paper circles that we have taped to the top of the drone. Originally, we were using a medium green color, but we found that under some lighting conditions, our code would confuse the light blue color on the body of the drone with the green circles. I thought about making our blob detection code more robust, but the Maker Faire was quickly approaching! Instead we decided to make our flying area more controlled. We used white poster board as the background for our flying area and I tested some different colors for the paper circles. Red circles were good, except that our code got confused if one of our hands was reaching into the flying area. Black was not good in dim light. In the end, we decided on a dark purple with a blue undertone.

Testing different circle colors
The winning color: dark purple

OpenCV provides a way to set a webcam’s manual exposure, but there are two problems. The first is that OpenCV is not well-documented. I could find the documentation stating that I should be able to set the exposure value, but it was not at all clear what values to pass! The second problem is that your particular webcam may not support programmatic setting of the exposure. Thus, when your code doesn’t work, it can be difficult to determine if your code is wrong or if your webcam just won’t allow it!

OpenCV’s VideoCapture.set() is the method to use. If you look at the documentation, you will see that there is a property named CV_CAP_PROP_EXPOSURE. It took me some time to discover that depending on the version of OpenCV you are using, the property’s name might actually be CAP_PROP_EXPOSURE.

There is no hint as to what the exposure value should be set to, but luckily for me, I found a mapping for the ELP 2 MP webcam on this page by Joan Charmant. He shows that the exposure values range between -1 and -13. You can programmatically set the exposure in this manner:

vc = cv2.VideoCapture(1)

Unfortunately, I could not figure out a programmatic way to set the exposure back to auto exposure. If you know how, please add a comment! Please be aware that for some webcams, such as this one, the manual exposure setting is stored in its on-board memory, which means that turning off your program and even turning off the webcam itself, the manual exposure will still be set!

As a workaround, I found a way to bring up the DirectShow property pages so that I could use the DirectShow GUI to set the manual exposure or to turn auto exposure back on.


Here’s the code to launch the DirectShow property page:


During the Maker Faire, our demonstration area was shaded by a tent for most of the day, but around 2 PM our flying area was part sun and part shade. We delayed the inevitable by moving our table back with the shade, but eventually we had to move our table back to the front of the booth and into the sun. On Saturday, the afternoon was mostly overcast, and the camera’s auto exposure worked most of the time. I was surprised that our blob detection code even worked when people walked in front of our booth and made our flying area partly shaded by their shadows.

Sunday was mostly sunny, and the webcam’s auto exposure did not work when it was very bright. At these times, I opened up the DirectShow property pages and set the exposure manually so that our demo would still work. Maker disaster averted!

2 thoughts on “Manual Exposure vs Auto Exposure for ELP 2 MP USB Camera”

  1. Hi there,

    iam using OpenCV and have the same issues you have with manual/auto Exposure. i want a camera that doesn’t auto adjust anything (exposure, whitebalance, brightness etc) AND remembers that after the camera is turned off. you use the ELP 2 Megapixel USB Camera. can it do these things?

    also you asked about a programmatic way to set the exposure back to auto exposure. i added some options below.

    hope to hear from you soon, i have a deadline comming…

    vc = cv2.VideoCapture(1)
    vc.set(CAP_PROP_AUTO_EXPOSURE, 0 ); // off?
    vc.set(CAP_PROP_AUTO_EXPOSURE, 1 ); // on?
    vc.set(CV_CAP_PROP_AUTO_EXPOSURE, 0 ); // off?
    vc.set(CV_CAP_PROP_AUTO_EXPOSURE, 1 ); // on?

    int i = vc.get(CV_CAP_PROP_AUTO_EXPOSURE ); // you can check if it is the right value with ‘get’

    // show settings menu
    cap.set(CV_CAP_PROP_SETTINGS , 1 );

    1. Thanks for your tips, ivdg. Yes, it does look like the ELP 2 Megapixel USB Camera will do what you want. I brought up the DirectShow Properties GUI to change the default settings on my ELP 2 Megapixel USB Camera. For this camera, White balance and Exposure can be set manually or to Auto. The GUI also allows me to manually set Brightness, Contrast, Hue, Saturation, Sharpness, Gamma, Backlight Comp, Gain, PowerLine Frequency, and Low Light Compensation. I used the GUI to change all of these values to non-default numbers and then I unplugged the camera from my USB port. After waiting 10 seconds or so, I plugged the camera back in and brought up the Properties GUI again. The settings all remained at the values I had set manually. The GUI has a Default button to restore the values too. Best of luck with your project!

Leave a Reply

Your email address will not be published. Required fields are marked *