forked from matiyau/ParaShoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicMotionDetector.py
50 lines (43 loc) · 1.61 KB
/
BasicMotionDetector.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
# import the necessary packages
import imutils
import cv2
class BasicMotionDetector:
def __init__(self, accumWeight=0.5, deltaThresh=5, minArea=5000):
# determine the OpenCV version, followed by storing the
# the frame accumulation weight, the fixed threshold for
# the delta image, and finally the minimum area required
# for "motion" to be reported
self.isv2 = imutils.is_cv2()
self.accumWeight = accumWeight
self.deltaThresh = deltaThresh
self.minArea = minArea
# initialize the average image for motion detection
self.avg = None
# import the necessary packages
import imutils
import cv2
class BasicMotionDetector:
def __init__(self, accumWeight=0.5, deltaThresh=5, minArea=5000):
# determine the OpenCV version, followed by storing the
# the frame accumulation weight, the fixed threshold for
# the delta image, and finally the minimum area required
# for "motion" to be reported
self.isv2 = imutils.is_cv2()
self.accumWeight = accumWeight
self.deltaThresh = deltaThresh
self.minArea = minArea
# initialize the average image for motion detection
self.avg = None
def update(self, image):
# initialize the list of locations containing motion
locs = []
# if the average image is None, initialize it
if self.avg is None:
self.avg = image.astype("float")
return locs
# otherwise, accumulate the weighted average between
# the current frame and the previous frames, then compute
# the pixel-wise differences between the current frame
# and running average
cv2.accumulateWeighted(image, self.avg, self.accumWeight)
frameDelta = cv2.absdiff(image, cv2.convertScaleAbs(self.avg)