-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencv3-video.py
More file actions
41 lines (29 loc) · 745 Bytes
/
opencv3-video.py
File metadata and controls
41 lines (29 loc) · 745 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
39
40
41
import cv2
cap = cv2.VideoCapture(-1)
if cap.isOpened() == False:
print("Can't Open Camera")
cv2.destroyAllWindows()
ret, img_frame = cap.read()
if ret == False:
print("Fail to Capture")
exit(1)
codec = cv2.VideoWriter_fourcc('M','J','P','G')
fps = 10.0
h,w = img_frame.shape[:2]
writer = cv2.VideoWriter('/home/pi/onuput.avi', codec, fps, (w,h))
if writer.isOpened() == False:
print("Can't ready the video file")
exit(1)
while(True):
ret, img_frame = cap.read()
if ret == False:
print("Capture Failed")
break
writer.write(img_frame)
cv2.imshow('Color', img_frame)
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
writer.release()
cv2.destroyAllWindows()