Skip to content

Commit

Permalink
make dynamic contrast optional and disable by default
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeblackshear committed Mar 11, 2022
1 parent 0dfba6e commit b1a2b0c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 5 additions & 1 deletion docs/docs/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions frigate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 9 additions & 8 deletions frigate/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ def detect(self, frame):
)

# 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]
Expand Down

0 comments on commit b1a2b0c

Please sign in to comment.