Browse Source

make dynamic contrast optional and disable by default

Blake Blackshear 3 năm trước cách đây
mục cha
commit
b1a2b0cda2
3 tập tin đã thay đổi với 15 bổ sung9 xóa
  1. 5 1
      docs/docs/configuration/index.md
  2. 1 0
      frigate/config.py
  3. 9 8
      frigate/motion.py

+ 5 - 1
docs/docs/configuration/index.md

@@ -171,7 +171,7 @@ detect:
     # It can also be used to disable stationary object tracking. For example, you may want to set a value for person, but leave
     # car at the default.
     # WARNING: Setting these values overrides default behavior and disables stationary object tracking.
-    #          There are very few situations where you would want it disabled. It is NOT recommended to  
+    #          There are very few situations where you would want it disabled. It is NOT recommended to
     #          copy these values from the example config into your config unless you know they are needed.
     max_frames:
       # Optional: Default for all object types (default: not set, track forever)
@@ -236,6 +236,10 @@ motion:
   # Optional: motion mask
   # NOTE: see docs for more detailed info on creating masks
   mask: 0,900,1080,900,1080,1920,0,1920
+  # Optional: improve contrast (default: shown below)
+  # Enables dynamic contrast improvement. This should help improve night detections at the cost of making motion detection more sensitive
+  # for daytime.
+  improve_contrast: False
 
 # Optional: Record configuration
 # NOTE: Can be overridden at the camera level

+ 1 - 0
frigate/config.py

@@ -122,6 +122,7 @@ class MotionConfig(FrigateBaseModel):
         ge=1,
         le=255,
     )
+    improve_contrast: bool = Field(default=False, title="Improve Contrast")
     contour_area: Optional[int] = Field(default=30, title="Contour Area")
     delta_alpha: float = Field(default=0.2, title="Delta Alpha")
     frame_alpha: float = Field(default=0.2, title="Frame Alpha")

+ 9 - 8
frigate/motion.py

@@ -38,14 +38,15 @@ class MotionDetector:
         )
 
         # Improve contrast
-        minval = np.percentile(resized_frame, 4)
-        maxval = np.percentile(resized_frame, 96)
-        # 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)
+        if self.config.improve_contrast:
+            minval = np.percentile(resized_frame, 4)
+            maxval = np.percentile(resized_frame, 96)
+            # 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]