From b1a2b0cda2c5860765aca80e9fd0e8b7ec99156b Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Thu, 10 Mar 2022 07:43:12 -0600 Subject: [PATCH] make dynamic contrast optional and disable by default --- docs/docs/configuration/index.md | 6 +++++- frigate/config.py | 1 + frigate/motion.py | 17 +++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/docs/docs/configuration/index.md b/docs/docs/configuration/index.md index 0863f3643..4f1765192 100644 --- a/docs/docs/configuration/index.md +++ b/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 diff --git a/frigate/config.py b/frigate/config.py index c210713a2..e89b43003 100644 --- a/frigate/config.py +++ b/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") diff --git a/frigate/motion.py b/frigate/motion.py index a3142b69b..9264191b2 100644 --- a/frigate/motion.py +++ b/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]