mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-02 17:25:22 +03:00
Process parameter to mqtt toggle improve_contrast
This commit is contained in:
parent
949b26fd63
commit
6b408876fd
@ -86,6 +86,9 @@ class FrigateApp:
|
||||
"detection_enabled": mp.Value(
|
||||
"i", self.config.cameras[camera_name].detect.enabled
|
||||
),
|
||||
"improve_contrast_enabled": mp.Value(
|
||||
"i", self.config.cameras[camera_name].motion.improve_contrast
|
||||
),
|
||||
"detection_fps": mp.Value("d", 0.0),
|
||||
"detection_frame": mp.Value("d", 0.0),
|
||||
"read_start": mp.Value("d", 0.0),
|
||||
|
||||
@ -25,7 +25,7 @@ class MotionDetector:
|
||||
self.mask = np.where(resized_mask == [0])
|
||||
self.save_images = False
|
||||
|
||||
def detect(self, frame):
|
||||
def detect(self, frame, improve_contrast):
|
||||
motion_boxes = []
|
||||
|
||||
gray = frame[0 : self.frame_shape[0], 0 : self.frame_shape[1]]
|
||||
@ -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 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]
|
||||
|
||||
@ -98,12 +98,14 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics):
|
||||
motion_settings = config.cameras[camera_name].motion
|
||||
|
||||
if payload == "ON":
|
||||
if not motion_settings.improve_contrast:
|
||||
if not camera_metrics[camera_name]["improve_contrast_enabled"].value:
|
||||
logger.info(f"Turning on improve contrast for {camera_name} via mqtt")
|
||||
camera_metrics[camera_name]["improve_contrast_enabled"].value = True
|
||||
motion_settings.improve_contrast = True
|
||||
elif payload == "OFF":
|
||||
if motion_settings.improve_contrast:
|
||||
if camera_metrics[camera_name]["improve_contrast_enabled"].value:
|
||||
logger.info(f"Turning off improve contrast for {camera_name} via mqtt")
|
||||
camera_metrics[camera_name]["improve_contrast_enabled"].value = False
|
||||
motion_settings.improve_contrast = False
|
||||
else:
|
||||
logger.warning(f"Received unsupported value at {message.topic}: {payload}")
|
||||
|
||||
@ -348,6 +348,7 @@ def track_camera(
|
||||
|
||||
frame_queue = process_info["frame_queue"]
|
||||
detection_enabled = process_info["detection_enabled"]
|
||||
improve_contrast_enabled = process_info["improve_contrast_enabled"]
|
||||
|
||||
frame_shape = config.frame_shape
|
||||
objects_to_track = config.objects.track
|
||||
@ -377,6 +378,7 @@ def track_camera(
|
||||
objects_to_track,
|
||||
object_filters,
|
||||
detection_enabled,
|
||||
improve_contrast_enabled,
|
||||
stop_event,
|
||||
)
|
||||
|
||||
@ -458,6 +460,7 @@ def process_frames(
|
||||
objects_to_track: List[str],
|
||||
object_filters,
|
||||
detection_enabled: mp.Value,
|
||||
improve_contrast_enabled: mp.Value,
|
||||
stop_event,
|
||||
exit_on_empty: bool = False,
|
||||
):
|
||||
@ -492,7 +495,7 @@ def process_frames(
|
||||
continue
|
||||
|
||||
# look for motion
|
||||
motion_boxes = motion_detector.detect(frame)
|
||||
motion_boxes = motion_detector.detect(frame, improve_contrast_enabled.value)
|
||||
|
||||
regions = []
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user