require a minimum of 3 consecutive motion frames to try and reduce false positives from rain

This commit is contained in:
blakeblackshear 2019-02-16 15:05:58 -06:00
parent 225f434718
commit 861539e8b5

View File

@ -396,6 +396,7 @@ def detect_motion(shared_arr, shared_frame_time, ready_for_frame, shared_motion,
avg_frame = None
last_motion = -1
frame_time = 0.0
motion_frames = 0
while True:
now = datetime.datetime.now().timestamp()
# if it has been long enough since the last motion, clear the flag
@ -459,11 +460,16 @@ def detect_motion(shared_arr, shared_frame_time, ready_for_frame, shared_motion,
# loop over the contours
for c in cnts:
# if the contour is big enough report motion
if cv2.contourArea(c) > min_motion_area:
last_motion = now
# if the contour is big enough, count it as motion
contour_area = cv2.contourArea(c)
if contour_area > min_motion_area:
motion_frames += 1
# if there have been enough consecutive motion frames, report motion
if motion_frames >= 3:
shared_motion.value = 1
last_motion = now
break
motion_frames = 0
if __name__ == '__main__':
mp.freeze_support()