From 1ebb8a54bfd6939cfaeea33a71c885cf19e584a2 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Wed, 17 Nov 2021 07:29:23 -0600 Subject: [PATCH] avoid divide by zero --- frigate/motion.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frigate/motion.py b/frigate/motion.py index 9d6b9a6ca..a3142b69b 100644 --- a/frigate/motion.py +++ b/frigate/motion.py @@ -40,10 +40,12 @@ class MotionDetector: # Improve contrast minval = np.percentile(resized_frame, 4) maxval = np.percentile(resized_frame, 96) - resized_frame = np.clip(resized_frame, minval, maxval) - resized_frame = (((resized_frame - minval) / (maxval - minval)) * 255).astype( - np.uint8 - ) + # don't adjust if the image is a single color + if minval < maxval: + resized_frame = np.clip(resized_frame, minval, maxval) + resized_frame = ( + ((resized_frame - minval) / (maxval - minval)) * 255 + ).astype(np.uint8) # mask frame resized_frame[self.mask] = [255]