-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideocap.py
52 lines (36 loc) · 1.01 KB
/
videocap.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
50
51
52
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 19 19:24:30 2019
@author: oscar
"""
import cv2
import numpy as np
global circles
cam = cv2.VideoCapture(0)
backSub = cv2.createBackgroundSubtractorMOG2()
while True:
# Read each frame in video stream
ret, frame = cam.read()
# Display each frame in video stream
cap_cnt=0
fgMask = backSub.apply(frame)
cv2.imshow('Frame', frame)
cv2.imshow('FG Mask', fgMask)
if not ret:
break
# Monitor keystrokes
k = cv2.waitKey(1)
if k & 0xFF == ord('q'):
# q key pressed so quit
print("Quitting...")
cv2.destroyAllWindows()
break
elif k & 0xFF == ord('c'):
# c key pressed so capture frame to image file
cap_name = "capture_{}.png".format(cap_cnt)
cv2.imwrite(cap_name, frame)
print("Saving {}!".format(cap_name))
# Increment Capture Counter for next frame to capture
cap_cnt += 1
cam.release()
print('Released')