1

I have some trouble with Manual Exposure of Camera setting in OpenCV 4.0.1. I`m using Raspberry Pi 3 B+ as a computer with Raspbian Stretch OS and Python 3.x. When I have an older version of OpenCV 3.x.x, the Manual setting of Exposure work perfectly with this code:

"camera.set(cv2.CAP_PROP_AUTO_EXPOSURE, 0.25)"

"camera.set(cv2.CAP_PROP_EXPOSURE, (float(exposureTime))"

But now when I have OpenCV 4.0.1, the above code does not change anything and the camera is still in AUTO Exposure mode. The camera sensor is same as before and it is Sony IMX322 by ELP manufacture. Have you got any experience with MANUAL EXPOSURE in OpenCV 4.0.1?

Thank you for your answers...

Peter
  • 21
  • 1
  • 5
  • Had a similar issue with CAP_PROP options not working sometimes. The constants are integers and eventually had some luck with trial/error finding the right integer for the properties I needed to change. I'd also recommend trying some other UVC controls (e.g. `uvcdynctrl`,`v4l2-ctl`, etc.). Although an older Sony model (IMX219), the [Raspberry Pi Camera v2.1](https://www.raspberrypi.org/documentation/hardware/camera/) it's got good support via the [PiCamera module which integrates with OpenCV](https://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/) – George Profenza Jan 25 '19 at 12:35
  • ...also might gain a few frames here and there because of CSI vs USB interface and being able to retrieve the grayscale image directly (if needed) by fetching frames in YUV colour space. – George Profenza Jan 25 '19 at 12:37
  • 1
    Hi George and thanks for quickly reply. I tried v4l2-ctl with some parameter as you said (set exposure to manual) and it works in VLC player! Great... but when I run my applicaton where I used to OpenCV to capture image from camera, it stills with AUTO exposure mode. After weekend I try more... Thanks again and have a nice DAYs :) – Peter Jan 25 '19 at 19:42

2 Answers2

1

Thank you all for helping me. I tried "-4" in set parameter but it does not working.

Only thing that works for me is this:

# Manual / Auto exposure mode
if exposureMode == 1:
    command = "v4l2-ctl -d /dev/video0 -c exposure_auto=1 -c exposure_absolute=" + str(exposureTime)
    output = subprocess.call(command, shell=True)
else:
    command = "v4l2-ctl -d /dev/video0 -c exposure_auto=3"
    output = subprocess.call(command, shell=True)

Have a nice day :)

Peter
  • 21
  • 1
  • 5
0

The following worked for me:

import cv2

#capture from camera at location 0
cap = cv2.VideoCapture(0)

# now set the camera exposure to -4 ( means 2^-4 = 1/16 = 80 ms)
cap.set(15, -4)

while True:
    ret, img = cap.read()
    # print(img.shape)
    cv2.imshow("input", img)

    key = cv2.waitKey(10)
    if key == 27: # Esc
        break

cv2.destroyAllWindows() 
cap.release()
Hafizur Rahman
  • 2,314
  • 21
  • 29