I'm trying to create 3 real-time capture frames with webcams into a USB hub into my laptop. Using the "camera" app on Windows, I can change the camera source one at a time and confirm that all 3 webcams are working. However, my OpenCV Python code can only ever find two.
(Quick notes on the USB - it's a USB 3.0 hub, laptop port is USB 3, and I even have an active USB female-to-male cable going into the laptop, so given this and the Windows app working, I generally trust the hardware.)
Below I did some raw testing of cv2.VideoCapture(src)
with the results below:
cams_test = 10
for i in range(0, cams_test):
cap = cv2.VideoCapture(i)
test, frame = cap.read()
print("i : "+str(i)+" /// result: "+str(test))
That first argument, test
, returns True/False depending on if the frame can be read. Results:
i : 0 /// result: True
i : 1 /// result: True
i : 2 /// result: False
i : 3 /// result: False
i : 4 /// result: False
i : 5 /// result: False
i : 6 /// result: False
i : 7 /// result: False
i : 8 /// result: False
i : 9 /// result: False
As with other sample code I tested, only 2 webcams can be registered and show frames in Python. And the Windows 10 camera app lets me scroll between all 3 working and connected webcam feeds.
I know I can create multiple, like 3+, cv2.imshow()
frames if I use the cap
s that work. My project involves doing this to show realtime USB webcam feeds on the laptop from multiple cameras.
Any help and advice appreciated; also potentially interested in (Python-based) alternative solutions. Cheers.
Do your webcams support USB3? Based on my practical experience with webcams and OpenCV, most common cameras only transmit on the USB2 standard, at 480 MBit/s. The exact details of how many cameras you can support on one USB channel depend on the resolution, framerate, and video compression technology. In my experience, with 1080p color video at 30 fps and H.264 encoding, only one camera stream fit onto a single USB controller.
An easy test to see if you are bandwidth limited would be to modify your program to explicitly close each stream after it is tested (cap.release()
), so that your test program only opens one camera at a time, like the Windows camera app. If that works, then you may very well be looking at a bandwidth limitation.
When debugging video capture issues on Windows, it can also be useful to open the camera streams with VLC. VLC can enumerate all of the cameras available from DirectShow, which is the same API that OpenCV's VideoCapture
uses by default. You can also start multiple VLC instances to attempt simultaneous streams.
If you click on "Advanced Options" and then check "Device Properties," VLC will show which settings (exposure, focus, etc...) can be tweaked through DirectShow. These settings are usually accessible in OpenCV through VideoCapture.set()
.
having two video input devices does not automatically mean that their IDs are 0 and 10. Try to access the all cameras by increasing to about 500 or more instead of 10
cams_test = 500
for i in range(0, cams_test):
cap = cv2.VideoCapture(i)
test, frame = cap.read()
if test:
print("i : "+str(i)+" /// result: "+str(test))
I think you are only testing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With