From d9d3937a0f05310bb4768b5035226ca97525e0f4 Mon Sep 17 00:00:00 2001 From: blakeblackshear Date: Sun, 17 Feb 2019 08:00:35 -0600 Subject: [PATCH] reset motion counter when no contours exist --- detect_objects.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/detect_objects.py b/detect_objects.py index e3e8fd2e1..d0e6052fa 100644 --- a/detect_objects.py +++ b/detect_objects.py @@ -473,6 +473,11 @@ def detect_motion(shared_arr, shared_frame_time, ready_for_frame, shared_motion, cv2.CHAIN_APPROX_SIMPLE) cnts = imutils.grab_contours(cnts) + # if there are no contours, there is no motion + if len(cnts) < 1: + motion_frames = 0 + continue + # loop over the contours for c in cnts: # if the contour is big enough, count it as motion @@ -489,6 +494,7 @@ def detect_motion(shared_arr, shared_frame_time, ready_for_frame, shared_motion, last_motion = now break motion_frames = 0 + if debug and motion_frames > 0: cv2.imwrite("/lab/debug/motion-{}-{}-{}.jpg".format(region_x_offset, region_y_offset, datetime.datetime.now().timestamp()), thresh)