opencv: Setting CAP_PROP_EXPOSURE on VideoCapture does not change anything

System information (version)
  • OpenCV => 3.3.0
  • Operating System / Platform => Windows 10 Enterprise 64 Bit
  • Compiler => using opencv-python
Detailed description

Setting exposure is not working with the python wrapper for opencv, I don’t know if this is related to the wrapper.

I tried to set CAP_PROP_AUTO_EXPOSURE as well to disable any auto exposure.

The camera is a HD USB Camera USB8MP02G http://www.elpcctv.com/8mp-highdefinition-usb-camera-module-usb20-sony-imx179-color-cmos-sensor-75degree-lens-p-223.html

Steps to reproduce

I use this snippet to try to set the exposure to different values

import cv2

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 0)
cap.set(cv2.CAP_PROP_EXPOSURE, -7.0)
print(cap.get(cv2.CAP_PROP_EXPOSURE))
while True:
	ret, frame = cap.read()
	cv2.imshow('test', frame)
	cv2.waitKey(1)

I can’t see any difference when changing exposure

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (1 by maintainers)

Most upvoted comments

i think finally i found a solution, at least for my problem,

capture = cv2.VideoCapture(id)
capture.set(cv2.CAP_PROP_AUTO_EXPOSURE, 3) # auto mode
capture.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1) # manual mode
capture.set(cv2.CAP_PROP_EXPOSURE, desired_exposure_value)

i have to first set the auto_exposure to 3 (auto mode)
then i have to set it to 1 (manual mode)
and then i can set the manual exposure


you can set the settings with shell too
list available options

video_id=1
v4l2-ctl --device /dev/video$video_id --all

set them with python
def set_manual_exposure(dev_video_id, exposure_time):
    commands = [
        ("v4l2-ctl --device /dev/video"+str(dev_video_id)+" -c exposure_auto=3"),
        ("v4l2-ctl --device /dev/video"+str(dev_video_id)+" -c exposure_auto=1"),
        ("v4l2-ctl --device /dev/video"+str(dev_video_id)+" -c exposure_absolute="+str(exposure_time))
    ]
    for c in commands: 
        os.system(c)
# usage 
set_manual_exposure(1, 18)

I’ve been having almost exactly the same problem using an ELP camera. I solved it by doing

cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 0.25)

Then setting the exposure to what I needed. I believe that 0.25 is the value that CAP_PROP_AUTO_EXPOSURE needs to be to give you manual control.

I needed to set my exposure as an absolute value, 0.01 in my case, rather than using negative values. But that may be different for your camera.

I hope this helps!

I have encountered an issue with cap prop exposure for my specific camera, the logitech c270 webcam

So the problem is that when you set cap prop exposure the first time the camera is placed in, the exposure is not changed, but if you close the python code and rerun it, it works. Whenever you take the camera out and put it in again and run the code again, the exposure not being set property arises again.

To fix this issue call ret, frame = cap.read() before the cap exposure call

cap = cv2.VideoCapture(0)
# we capture the first frame for the camera to adjust itself to the exposure
ret_val , cap_for_exposure = cap.read()

cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 0.25)
cap.set(cv2.CAP_PROP_EXPOSURE , -1)

I believe the reason for calling read before setting the exposure for it to work is because the camera needs to adjust and understand what it is seeing before adjusting the exposure, sort of like dipping your toes in a cold pool.

I may be completely wrong with my explanation, but I hope this helps anyone 😃

I find the reason!! At first, I use OpenCV 3.4.10. I follows the code

#!/usr/bin/env python3
import cv2
print(cv2.__version__)
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 3) # auto mode
cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1) # manual mode
cap.set(cv2.CAP_PROP_EXPOSURE, 10)
while cap.isOpened():
    ret, frame = cap.read()
    cv2.imshow("DetectionResults", frame)
    cv2.waitKey(1)

output

3.4.10
[ WARN:0] OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
[ WARN:0] OpenCV | GStreamer warning: GStreamer: unhandled property
[ WARN:0] OpenCV | GStreamer warning: GStreamer: unhandled property
[ WARN:0] OpenCV | GStreamer warning: GStreamer: unhandled property

I can not set the CV_CAP_PROP_EXPOSURE or CV_CAP_PROP_AUTO_EXPOSURE.

However, when I change the python version to 4.2.0 at the first line

#!/usr/bin/env python
import cv2
print(cv2.__version__)
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 3) # auto mode
cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1) # manual mode
cap.set(cv2.CAP_PROP_EXPOSURE, 10)
while cap.isOpened():
    ret, frame = cap.read()
    cv2.imshow("DetectionResults", frame)
    cv2.waitKey(1)

output is

4.2.0

Yes ! ! I can set the CV_CAP_PROP_EXPOSURE. I try form 1 to 30, the EXPOSURE will increase.

In my case, it works on Windows, but doesn’t work on Mac. Is there anyone who could set CAP_PROP_EXPOSURE and CAP_PROP_AUTO_EXPOSURE properties on Mac?

Hi. I could make the camera work on manual mode now with auto exposure set on 0.25. But I can’t put the Camera back on auto mode. I have tried setting 0 and 1 as the auto_exposure value, but no help. Can you please guide?

I have encountered an issue with cap prop exposure for my specific camera, the logitech c270 webcam

So the problem is that when you set cap prop exposure the first time the camera is placed in, the exposure is not changed, but if you close the python code and rerun it, it works. Whenever you take the camera out and put it in again and run the code again, the exposure not being set property arises again.

To fix this issue call ret, frame = cap.read() before the cap exposure call

cap = cv2.VideoCapture(0)
# we capture the first frame for the camera to adjust itself to the exposure
ret_val , cap_for_exposure = cap.read()

cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 0.25)
cap.set(cv2.CAP_PROP_EXPOSURE , -1)

I believe the reason for calling read before setting the exposure for it to work is because the camera needs to adjust and understand what it is seeing before adjusting the exposure, sort of like dipping your toes in a cold pool.

I may be completely wrong with my explanation, but I hope this helps anyone 😃

This really work for my problem when I try to set focus value manually. Tks u so much!!!

Usage questions should go to Users OpenCV Q/A forum: http://answers.opencv.org This tracker is for issues and bugs that needs fix in OpenCV.


cap.set(…)

Always check returned values.


Properties availability/implementation/etc are backend-specific. So it is bad idea to use them without backend check. To use V4L2 properties you should force backend via CAP_V4L2 parameter.


opencv-python

Check cv.getBuildInformation() at first for V4L2 availability:

python -c 'import cv2 as cv; print(cv.getBuildInformation())'

3.3.0

I believe it should be fixed in fresh OpenCV packages.

Hi hoerin, The auto_exposure property should expect two values 0.75 as auto exposure On and 0.25 as auto exposure OFF. Once you set auto exposure Off with 0.25 then set exposure to any value that you desire. This is tested on Mac and Raspberry both.