0

I'm using opencv-python to access any of multiple usb webcam available. Each webcam has a different id of course. Any webcam can be disabled or unplugged at any time. Thus, it is often difficult to know what id is available or not. At the same time the code has to be written once. When calling cap = cv2.VideoCapture(0) for instance while the webcam with id 0 is not available, this message is raised : [ WARN:0] global /tmp/pip-req-build-h45n7_hz/opencv/modules/videoio/src/cap_v4l.cpp (890) open VIDEOIO(V4L2:/dev/video0): can't open camera by index. Is there any way to turn this warning into an error such that I can apply try except clause and go through all possible webcam ? I will also welcome any other solution applicable. The official python documentation on warning is not quite clear on this.

0 Answers0