-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackgroundReduction.py
More file actions
29 lines (20 loc) · 828 Bytes
/
backgroundReduction.py
File metadata and controls
29 lines (20 loc) · 828 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
import cv2
import numpy as np
# MOG Background removal
# to remove the backgriound, we'll read the changes in each successive frame and
# then will treat the changing objects as the foreground.
# The places that don't change will be the Background
# capturing the video from the camera
cap = cv2.VideoCapture(0)
# creating an instance of the MOG Background Subtractor
fgbg = cv2.createBackgroundSubtractorMOG2()
while True:
ret, frame = cap.read() # Read frames of the video
fgmask = fgbg.apply(frame) # apply the background reduction on the frame
cv2.imshow('inst',frame) # shouwing the instantaneous frame (simple video)
cv2.imshow('fg', fgmask) # showing the instantaneous bg reduced frame
k = cv2.waitKey(30) & 0xff # Esc key
if k == 27:
break
cap.release()
cv2.destroyAllWindows()