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.
Is there any way to turn a warning to an error such that it can be handled with a try except clause?
Asked
Active
Viewed 70 times
0

Donald MOUAFO
- 21
- 3
-
Does this answer your question? https://stackoverflow.com/questions/5644836/in-python-how-does-one-catch-warnings-as-if-they-were-exceptions – Tajinder Singh Sep 19 '22 at 10:00
-
Please provide enough code so others can better understand or reproduce the problem. – Community Sep 19 '22 at 10:01