-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinference.py
More file actions
51 lines (37 loc) · 1.26 KB
/
inference.py
File metadata and controls
51 lines (37 loc) · 1.26 KB
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
50
import cv2
def save_webcam(outPath,fps,mirror=False):
# Capturing video from webcam:
cap = cv2.VideoCapture(0)
currentFrame = 0
# Get current width of frame
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH) # float
# Get current height of frame
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) # float
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*"XVID")
out = cv2.VideoWriter(outPath, fourcc, fps, (int(width), int(height)))
while (cap.isOpened()):
# Capture frame-by-frame
ret, frame = cap.read()
if ret == True:
if mirror == True:
# Mirror the output video frame
frame = cv2.flip(frame, 1)
# Saves for video
out.write(frame)
# Display the resulting frame
cv2.imshow('frame', frame)
else:
break
if cv2.waitKey(1) & 0xFF == ord('r'): # if 'q' is pressed then quit
break
# To stop duplicate images
currentFrame += 1
# When everything done, release the capture
cap.release()
out.release()
cv2.destroyAllWindows()
def main():
save_webcam('output.avi', 24.0,mirror=True)
if __name__ == '__main__':
main()