-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaptureVideoFromCamera.py
49 lines (37 loc) · 1.17 KB
/
captureVideoFromCamera.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
43
44
45
46
47
48
49
# https://www.youtube.com/watch?v=-RtVZsCvXAQ
import cv2
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
exit()
# forcc = cv2.VideoWriter_forcc(*'XVID')
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
framPerSecond = 20
# Define the codec and create VideoWriter object
out = cv2.VideoWriter('output.mp4', fourcc, framPerSecond, (640,480))
print(cap.isOpened())
# while loop use for frame continue
while(cap.isOpened()):
# Capture frame-by-frame
ret, frame = cap.read()
# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
if ret == True:
# getting frame width and height
print(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
print(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
out.write(frame)
# Display the resulting frame
# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# cv2.imshow('frame', gray)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()