-
Notifications
You must be signed in to change notification settings - Fork 0
/
Camera.py
42 lines (38 loc) · 1.03 KB
/
Camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import numpy as np
import cv2
#Get the most recent working camera
def getNumCam():
num = 0
while True:
cp = cv2.VideoCapture(num)
if cp.isOpened():
num += 1
else:
break
return num
currCam = 0;
cap = cv2.VideoCapture(currCam)
cap.set(3,1920)
cap.set(4,1080)
capNum = 0
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Display the resulting frame and perform various operations based on user input (like take an image or switch cameras)
cv2.imshow('frame', frame)
k = cv2.waitKey(1)
if k & 0xFF == ord('q'):
break
if k & 0xFF == ord('c'):
cv2.imwrite("frame%d.jpg" % capNum, frame)
capNum += 1;
if k & 0xFF == ord('n'):
cap.release()
currCam += 1
if currCam >= getNumCam():
currCam = 0
cap = cv2.VideoCapture(currCam)
cap.set(3,1920)
cap.set(4,1080)
# When everything done, release the capture
cv2.destroyAllWindows()