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(
|
"detection_enabled": mp.Value(
|
||||||
"i", self.config.cameras[camera_name].detect.enabled
|
"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_fps": mp.Value("d", 0.0),
|
||||||
"detection_frame": mp.Value("d", 0.0),
|
"detection_frame": mp.Value("d", 0.0),
|
||||||
"read_start": 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.mask = np.where(resized_mask == [0])
|
||||||
self.save_images = False
|
self.save_images = False
|
||||||
|
|
||||||
def detect(self, frame):
|
def detect(self, frame, improve_contrast):
|
||||||
motion_boxes = []
|
motion_boxes = []
|
||||||
|
|
||||||
gray = frame[0 : self.frame_shape[0], 0 : self.frame_shape[1]]
|
gray = frame[0 : self.frame_shape[0], 0 : self.frame_shape[1]]
|
||||||
@ -38,14 +38,15 @@ class MotionDetector:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Improve contrast
|
# Improve contrast
|
||||||
minval = np.percentile(resized_frame, 4)
|
if improve_contrast:
|
||||||
maxval = np.percentile(resized_frame, 96)
|
minval = np.percentile(resized_frame, 4)
|
||||||
# don't adjust if the image is a single color
|
maxval = np.percentile(resized_frame, 96)
|
||||||
if minval < maxval:
|
# don't adjust if the image is a single color
|
||||||
resized_frame = np.clip(resized_frame, minval, maxval)
|
if minval < maxval:
|
||||||
resized_frame = (
|
resized_frame = np.clip(resized_frame, minval, maxval)
|
||||||
((resized_frame - minval) / (maxval - minval)) * 255
|
resized_frame = (
|
||||||
).astype(np.uint8)
|
((resized_frame - minval) / (maxval - minval)) * 255
|
||||||
|
).astype(np.uint8)
|
||||||
|
|
||||||
# mask frame
|
# mask frame
|
||||||
resized_frame[self.mask] = [255]
|
resized_frame[self.mask] = [255]
|
||||||
|
|||||||
@ -98,12 +98,14 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics):
|
|||||||
motion_settings = config.cameras[camera_name].motion
|
motion_settings = config.cameras[camera_name].motion
|
||||||
|
|
||||||
if payload == "ON":
|
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")
|
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
|
motion_settings.improve_contrast = True
|
||||||
elif payload == "OFF":
|
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")
|
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
|
motion_settings.improve_contrast = False
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Received unsupported value at {message.topic}: {payload}")
|
logger.warning(f"Received unsupported value at {message.topic}: {payload}")
|
||||||
|
|||||||
@ -348,6 +348,7 @@ def track_camera(
|
|||||||
|
|
||||||
frame_queue = process_info["frame_queue"]
|
frame_queue = process_info["frame_queue"]
|
||||||
detection_enabled = process_info["detection_enabled"]
|
detection_enabled = process_info["detection_enabled"]
|
||||||
|
improve_contrast_enabled = process_info["improve_contrast_enabled"]
|
||||||
|
|
||||||
frame_shape = config.frame_shape
|
frame_shape = config.frame_shape
|
||||||
objects_to_track = config.objects.track
|
objects_to_track = config.objects.track
|
||||||
@ -377,6 +378,7 @@ def track_camera(
|
|||||||
objects_to_track,
|
objects_to_track,
|
||||||
object_filters,
|
object_filters,
|
||||||
detection_enabled,
|
detection_enabled,
|
||||||
|
improve_contrast_enabled,
|
||||||
stop_event,
|
stop_event,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -458,6 +460,7 @@ def process_frames(
|
|||||||
objects_to_track: List[str],
|
objects_to_track: List[str],
|
||||||
object_filters,
|
object_filters,
|
||||||
detection_enabled: mp.Value,
|
detection_enabled: mp.Value,
|
||||||
|
improve_contrast_enabled: mp.Value,
|
||||||
stop_event,
|
stop_event,
|
||||||
exit_on_empty: bool = False,
|
exit_on_empty: bool = False,
|
||||||
):
|
):
|
||||||
@ -492,7 +495,7 @@ def process_frames(
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# look for motion
|
# look for motion
|
||||||
motion_boxes = motion_detector.detect(frame)
|
motion_boxes = motion_detector.detect(frame, improve_contrast_enabled.value)
|
||||||
|
|
||||||
regions = []
|
regions = []
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user