How to set V4L2 exposure to manual mode in OpenCV & Python
Using OpenCV on Linux, if you have a video device that interfaces a V4L2 device such as a USB webcam:
camera = cv2.VideoCapture(0)
you can typically set the automatic exposure mode by setting exposure_auto
to 1
(the following output is from v4l2-ctl -d /dev/video0 --all
):
exposure_auto 0x009a0901 (menu) : min=0 max=3 default=3 value=1
1: Manual Mode
3: Aperture Priority Mode
As you can see in our previous blogpost, exposure_auto
(which is named V4L2_CID_EXPOSURE_AUTO
in V4L2 in C/C++) is mapped to CAP_PROP_AUTO_EXPOSURE
.
Therefore, you can enable manual exposure using
camera.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1) # Set exposure to manual mode
You should, however, verify these settings using v4l2-ctl --all
using your specific camera.