diff --git a/frigate/motion/improved_motion.py b/frigate/motion/improved_motion.py index 77135a690..e05da58a1 100644 --- a/frigate/motion/improved_motion.py +++ b/frigate/motion/improved_motion.py @@ -121,13 +121,13 @@ class ImprovedMotionDetector(MotionDetector): if self.save_images: contrasted_saved = resized_frame.copy() + resized_frame = gaussian_filter(resized_frame, sigma=1, radius=self.blur_radius) + # mask frame - # this has to come after contrast improvement + # this has to come after contrast improvement and masking to avoid the mask bleeding into non-masked area. # Setting masked pixels to zero, to match the average frame at startup resized_frame[self.mask] = [0] - resized_frame = gaussian_filter(resized_frame, sigma=1, radius=self.blur_radius) - if self.save_images: blurred_saved = resized_frame.copy() @@ -194,10 +194,11 @@ class ImprovedMotionDetector(MotionDetector): # once the motion is less than 5% and the number of contours is < 4, assume its calibrated if pct_motion < 0.05 and len(motion_boxes) <= 4: + motion_boxes = [] # ignore small movements self.calibrating = False # if calibrating or the motion contours are > 80% of the image area (lightning, ir, ptz) recalibrate - if self.calibrating or pct_motion > self.config.lightning_threshold: + if not self.calibrating and pct_motion > self.config.lightning_threshold: self.calibrating = True if self.save_images: diff --git a/frigate/test/test_motion.py b/frigate/test/test_motion.py index 69ea166fc..ed9e14ce8 100644 --- a/frigate/test/test_motion.py +++ b/frigate/test/test_motion.py @@ -51,6 +51,9 @@ class TestMotion(unittest.TestCase): default_motion_config, [[190, 307]], ), + TestMotionVideo( + "testdata/test_motion_video-3.mp4", default_mask, default_motion_config + ), ] def get_motion_detector(self, test_clip):