How to correctly check if a camera is available?

后端 未结 4 412
情歌与酒
情歌与酒 2021-01-12 06:46

I am using OpenCV to open and read from several webcams. It all works fine, but I cannot seem to find a way to know if a camera is available.

I tried this code (cam

4条回答
  •  情书的邮戳
    2021-01-12 07:37

    Another solution, which is available in Linux is to use the /dev/videoX device in the VideoCapture() call. The devices are there when the cam is plugged in. Together with glob(), it is trivial to get all the cameras:

    import cv2, glob
    
    for camera in glob.glob("/dev/video?"):
        c = cv2.VideoCapture(camera)
    

    Of course a check is needed on c using isOpened(), but you are sure you only scan the available cameras.

提交回复
热议问题