-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcapture.py
46 lines (34 loc) · 1.1 KB
/
capture.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
import cv2
import numpy as np
import time
# Object for video capturing
# Passing value '0' or '-1' is for first (default) external camera (webcam)
# Passing value '1' is for second external camera
video = cv2.VideoCapture(0)
# Variable 'milliSeconds' represents the streamed milliseconds
milliSeconds = 0
# Video codec
fourcc = cv2.VideoWriter_fourcc(*'XVID')
# output = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480))
output = cv2.VideoWriter('output.mp4', fourcc, 20.0, (640, 480))
# Loop stream
while True:
milliSeconds = milliSeconds + 1
ret, frame = video.read()
print(ret) # print recognition in array format
print(frame) # print image representation
# Display video in grayscale real-time
color = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# Frame output
output.write(frame)
# Display frame real-time
cv2.imshow("OpenCV", frame)
# User controls
ctrlAbort = cv2.waitKey(1)
if ctrlAbort == ord('z'):
break
video.release()
output.release()
print(milliSeconds)
video.release()
cv2.destroyAllWindows