In OpenCV, you can set the exposure for your camera manually by using the VideoCapture::set method. What isn’t obvious is what value to pass in for it. I have experimented with various webcams and the below settings seem to be accurate enough. Not all cameras allow setting the exposure programatically, so if the code below doesn’t work, you might try a different camera, or experiment with different values. Once you’ve set a value manually, I haven’t found a way to switch back to auto-exposure without restarting the camera.
Below is an example of using this setting in Python
import cv2 cap = cv2.VideoCapture(0) cap.set(cv2.CAP_PROP_EXPOSURE,-4) while(True): ret, frame = cap.read() cv2.imshow('frame',frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
Estimated exposure settings from Joan Charmant’s ‘Review of the ELP-USBFHD01M camera’
CAP_PROP_EXPOSURE | Exposure Time |
---|---|
-1 | 640 ms |
-2 | 320 ms |
-3 | 160 ms |
-4 | 80 ms |
-5 | 40 ms |
-6 | 20 ms |
-7 | 10 ms |
-8 | 5 ms |
-9 | 2.5 ms |
-10 | 1.25 ms |
-11 | 650 µs |
-12 | 312 µs |
-13 | 150 µs |