From 861539e8b5610283d0f5d7934e1a3b3cda0124d0 Mon Sep 17 00:00:00 2001 From: blakeblackshear Date: Sat, 16 Feb 2019 15:05:58 -0600 Subject: [PATCH] require a minimum of 3 consecutive motion frames to try and reduce false positives from rain --- detect_objects.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/detect_objects.py b/detect_objects.py index ff6ddd22e..3cd222a06 100644 --- a/detect_objects.py +++ b/detect_objects.py @@ -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 - shared_motion.value = 1 + # 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()