📜  如何检查有多少相机连接到python中的设备\ - Python代码示例

📅  最后修改于: 2022-03-11 14:45:37.747000             🧑  作者: Mango

代码示例1
import cv2

def clearCapture(capture):
    capture.release()
    cv2.destroyAllWindows()

def countCameras():
    n = 0
    for i in range(10):
        try:
            cap = cv2.VideoCapture(i)
            ret, frame = cap.read()
            cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            clearCapture(cap)
            n += 1
        except:
            clearCapture(cap)
            break
    return n

print countCameras()