Peter
Peter

Reputation: 21

Exposure Mode OpenCV 4.0.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...

Upvotes: 1

Views: 5268

Answers (2)

Hafizur Rahman
Hafizur Rahman

Reputation: 2370

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()

Upvotes: 0

Peter
Peter

Reputation: 21

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 :)

Upvotes: 1

Related Questions