1import cv2
2
3def camera_amount():
4 '''Returns int value of available camera devices connected to the host device'''
5 camera = 0
6 while True:
7 if (cv2.VideoCapture(camera).grab()) is True:
8 camera = camera + 1
9 else:
10 cv2.destroyAllWindows()
11 return(int(camera))
1import cv2
2
3def clearCapture(capture):
4 capture.release()
5 cv2.destroyAllWindows()
6
7def countCameras():
8 n = 0
9 for i in range(10):
10 try:
11 cap = cv2.VideoCapture(i)
12 ret, frame = cap.read()
13 cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
14 clearCapture(cap)
15 n += 1
16 except:
17 clearCapture(cap)
18 break
19 return n
20
21print countCameras()
22