From 72e8551c62006c0a39538dca8224dac4bc4f398e Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Fri, 2 Feb 2024 06:17:43 -0700 Subject: [PATCH] Implement scaling factor --- frigate/config.py | 10 ++++++++++ frigate/output.py | 12 +++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/frigate/config.py b/frigate/config.py index 6760ea5e6..fbbf9fefa 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -528,6 +528,13 @@ class BirdseyeModeEnum(str, Enum): return list(cls)[index] +class BirdseyeLayoutConfig(FrigateBaseModel): + scaling_factor: float = Field( + default=2.0, title="Birdseye Scaling Factor", gt=1.0, le=5.0 + ) + max_cameras: Optional[int] = Field(default=None, title="Max cameras") + + class BirdseyeConfig(FrigateBaseModel): enabled: bool = Field(default=True, title="Enable birdseye view.") restream: bool = Field(default=False, title="Restream birdseye via RTSP.") @@ -542,6 +549,9 @@ class BirdseyeConfig(FrigateBaseModel): mode: BirdseyeModeEnum = Field( default=BirdseyeModeEnum.objects, title="Tracking mode." ) + layout: BirdseyeLayoutConfig = Field( + default_factory=BirdseyeLayoutConfig, title="Birdseye Layout Config" + ) # uses BaseModel because some global attributes are not available at the camera level diff --git a/frigate/output.py b/frigate/output.py index 343cbfb3a..0e5d276e7 100644 --- a/frigate/output.py +++ b/frigate/output.py @@ -76,7 +76,13 @@ def get_canvas_shape(width: int, height: int) -> tuple[int, int]: class Canvas: - def __init__(self, canvas_width: int, canvas_height: int) -> None: + def __init__( + self, + canvas_width: int, + canvas_height: int, + scaling_factor: int, + ) -> None: + self.scaling_factor = scaling_factor gcd = math.gcd(canvas_width, canvas_height) self.aspect = get_standard_aspect_ratio( (canvas_width / gcd), (canvas_height / gcd) @@ -90,7 +96,7 @@ class Canvas: return (self.aspect[0] * coefficient, self.aspect[1] * coefficient) def get_coefficient(self, camera_count: int) -> int: - return self.coefficient_cache.get(camera_count, 2) + return self.coefficient_cache.get(camera_count, self.scaling_factor) def set_coefficient(self, camera_count: int, coefficient: int) -> None: self.coefficient_cache[camera_count] = coefficient @@ -278,7 +284,7 @@ class BirdsEyeFrameManager: self.frame_shape = (height, width) self.yuv_shape = (height * 3 // 2, width) self.frame = np.ndarray(self.yuv_shape, dtype=np.uint8) - self.canvas = Canvas(width, height) + self.canvas = Canvas(width, height, config.birdseye.layout.scaling_factor) self.stop_event = stop_event self.camera_metrics = camera_metrics