Second camera is not opening until the first camera is released
I want to display the video inputs from two cameras at the same time. I used below code.
capL = cv.VideoCapture(0)
capR = cv.VideoCapture(1)
if capL.isOpened() & capR.isOpened():
while True:
retL, frameL = capL.read()
retR, frameR = capR.read()
leftImage = cv.cvtColor(frameL, cv.COLOR_BGR2GRAY)
rightImage = cv.cvtColor(frameR, cv.COLOR_BGR2GRAY)
cv.imshow('Left Camera', leftImage)
cv.imshow('Right Camera', rightImage)
if cv.waitKey(25) & 0xFF == ord('q'):
break
else:
print("unable to open camera")
But the output always shows
unable to open camera
To debug it, I used below code
capL = cv.VideoCapture(0)
while not capL.isOpened():
print('L not open')
capR = cv.VideoCapture(1)
while not capR.isOpened():
print('R not open')
And I found out the second camera is not opening. But if I release the first camera then the second camera is opening.
capL = cv.VideoCapture(0)
while not capL.isOpened():
print('L not open')
capL.release()
capR = cv.VideoCapture(1)
while not capR.isOpened():
print('R not open')
Am I doing something wrong?
Is current sufficient on usb bus for both camera?
@LBerger I have tried with one USB cam and a built-in webcam. same problem
Do you use a raspberry card?
@LBerger Not at this moment but will use it in near future.
I don't know python but in capL.isOpened() & capR.isOpened() the & is logical "and" or a binary operator
@LBerger It is correct. In python, it is single
&
or I can useand
. I have tested,capR.isOpened()
returns falseCan you run two programs first one openning first camera and second program the second camera?