How to count cameras in OpenCV 2.3?

后端 未结 6 1172
难免孤独
难免孤独 2020-12-01 14:36

I want to get the number of available cameras.

I tried to count cameras like this:

for(int device = 0; device<10; device++) 
{
    VideoCapture ca         


        
6条回答
  •  遥遥无期
    2020-12-01 14:42

    Python 3.6:

    import cv2
    
    # Get the number of cameras available
    def count_cameras():
        max_tested = 100
        for i in range(max_tested):
            temp_camera = cv2.VideoCapture(i)
            if temp_camera.isOpened():
                temp_camera.release()
                continue
            return i
    
    print(count_cameras())
    

提交回复
热议问题