Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV 4.1.0 not changing brightness

I made a program that can change the brightness/contrast of the camera by pressing the arrow keys, while showing a live feed of what the camera sees. Since I only used one camera, I initiated it using cv2.VideoCapture(-1), and it worked fine.

However, when I tried to add a second camera to the program, I ran into an issue. The two cameras can be found at /dev/video0 and /dev/video1. When I changed the first camera to use cv2.VideoCapture(0), the program stopped working. After further testing, whenever I try to change any setting on a camera initialized with a value other than -1, the property is set to zero. If I adjust a property twice (typically brightness or contrast) before taking a picture, I get an error (libv4l2: error setting pixformat: Device or resource busy). If I try to do anything with the camera after that, it fails entirely. Using cam.set() returns false no matter what property/value I provide.

These issues only show up using cv2.VideoCapture(0) and cv2.VideoCapture(1), but cv2.VideoCapture(-1) always works. I've tried keeping only one camera plugged in and using cv2.VideoCapture(0) and it still fails, and if I don't try to set any properties I can successfully take an image from both cameras, so I don't believe bandwidth is an issue.

OpenCV 4.1.0 not changing brightness

I made a program that can change the brightness/contrast of the camera by pressing the arrow keys, while showing a live feed of what the camera sees. Since I only used one camera, I initiated it using cv2.VideoCapture(-1), and it worked fine.

However, when I tried to add a second camera to the program, I ran into an issue. The two cameras can be found at /dev/video0 and /dev/video1. When I changed the first camera to use cv2.VideoCapture(0), the program stopped working. After further testing, whenever I try to change any setting on a camera initialized with a value other than -1, the property is set to zero. If I adjust a property twice (typically brightness or contrast) before taking a picture, I get an error (libv4l2: error setting pixformat: Device or resource busy). If I try to do anything with the camera after that, it fails entirely. Using cam.set() returns false no matter what property/value I provide.

These issues only show up using cv2.VideoCapture(0) and cv2.VideoCapture(1), but cv2.VideoCapture(-1) always works. I've tried keeping only one camera plugged in and using cv2.VideoCapture(0) and it still fails, and if I don't try to set any properties I can successfully take an image from both cameras, so I don't believe bandwidth is an issue.

Edit: I simplified the code to figure out what was causing the issue. This is what I am currently using:

import cv2

cam = cv2.VideoCapture(0)
r1 = cam.set(10,55)
ret0,img0 = cam.read()
r2 = cam.set(11,60)
ret1,img1 = cam.read()
r3 = cam.set(10,70)
print(r1,r2,r3)
print(ret0,ret1)

The output was as follows:

libv4l2: error setting pixformat: Device or resource busy
(True, True, False)
(True, False)

If I only took one picture, or only changed one setting, there was not an error.