-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.py
More file actions
38 lines (29 loc) · 778 Bytes
/
camera.py
File metadata and controls
38 lines (29 loc) · 778 Bytes
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
import cv2
import time
cap = cv2.VideoCapture(0)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
recorder = cv2.VideoWriter('capture.mp4', cv2.VideoWriter_fourcc(*'VIDX'), 20, (width, height))
while True:
_, frame = cap.read()
cv2.imshow("Camera", frame)
recorder.write(frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
recorder.release()
cap.release()
cv2.destroyAllWindows()
cap = cv2.VideoCapture('capture.mp4')
if not cap.isOpened():
print("Error")
while True:
ret, frame = cap.read()
if ret:
time.sleep(1/20)
cv2.imshow("Camera", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()