Browse Source

improve contrast

Blake Blackshear 3 years ago
parent
commit
08ddfc100f
1 changed files with 7 additions and 1 deletions
  1. 7 1
      frigate/motion.py

+ 7 - 1
frigate/motion.py

@@ -36,7 +36,13 @@ class MotionDetector:
             interpolation=cv2.INTER_LINEAR,
         )
 
-        # TODO: can I improve the contrast of the grayscale image here?
+        # Improve contrast
+        minval = np.percentile(resized_frame, 5)
+        maxval = np.percentile(resized_frame, 95)
+        resized_frame = np.clip(resized_frame, minval, maxval)
+        resized_frame = (((resized_frame - minval) / (maxval - minval)) * 255).astype(
+            np.uint8
+        )
 
         # convert to grayscale
         # resized_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2GRAY)