My problem is simple :
I Trying to use the 2 same camera in a USB HUB, and one of the two dosen’t work.
You can see here the simple code I use to test it :
if __name__ == '__main__':
# Load Camera(s)
camera_One = set_Camera(0)
camera_Two = set_Camera(1)
while True:
# Capture the video frame by frame
ret1, frame1 = camera_One.read()
ret2, frame2 = camera_Two.read()
cv2.imshow('Output One', frame1)
cv2.imshow('Output Two', frame2)
# the 'q' button is set as the quitting button
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# After the loop release the cap object
camera_One.release()
camera_Two.release()
# Destroy all the windows
cv2.destroyAllWindows()
The first camera work great, but not the second…
I don’t know if the HUB dosen’t regonize the two camera in cause is the same, or it’s because I plug two camera in the same port USB.
Thanks for helping, and feel free to replied me if you need more information ^^
I don’t understand but no. all cameras should be found. they have unique IDs.
maybe the hub is broken, maybe the cameras are broken, maybe you plugged the hub into a USB 2 port on your computer, maybe the cameras are USB 2 and the hub degrades to USB 2 then… many possible reasons. impossible to debug from afar.
remove the hub. if both cameras work when plugged directly into the computer, try a different hub.
be aware that this isn’t a problem with OpenCV but with the hardware. you can verify that by trying to view those cameras using your computer’s “camera app” or VLC or any other video program.
Cameras work fine, and my programe work when I plug the cameras in 2 differents port USB in my computer.
I try another HUB, and it dosen’t work to.
And I use USB 3.
I see in my Device Manager windows correctly recognize the two camera.
So I don’t know how it dosen’t work with PyCharm
Maybe I had to use different function ? (I only use “camera_One = set_Camera(0)”)
oh … my bad sorry it my personnal function to correctly set the cameras XD
Here is my function :
def set_Camera(source):
vid = cv2.VideoCapture(source)
if not vid.isOpened():
raise IOError("Cannot open webcam")
vid.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
vid.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
vid.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
vid.set(cv2.CAP_PROP_FPS, 120)
return vid
So I use cv2.VideoCapture to open the camera.
I notice, the error is when I use “imshow” …
I think about it : How can I correctly know in wich USB port the camera is ?
Because by default I use 0 and 1, but the camera can be in a different number ?
try putting the set(FOURCC) call last. maybe it didn’t correctly try to switch into MJPEG mode. I’ve seen people have issues with the order of these calls.
I think something isn’t USB 3 here, even though it should be. hubs are active devices. they must support USB 3, not just USB in general. a USB 2 hub will work for USB 3 devices, but they’ll run at USB 2 speeds then.
not with OpenCV. VideoCapture’s device number assignment is somewhat opaque and utterly unaware of a device’s identity or “where” a device was plugged in.
it will always assign IDs from 0 onwards. if you have another camera, even a virtual one, then it might be a good idea to test higher numbers. if not, then 0 and 1 are the only useful ones.