From b4e7e51e630b659627d3921e6a74d738e9a51f46 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Thu, 1 Jul 2021 07:47:22 -0500 Subject: [PATCH] make contour_area dynamic --- frigate/config.py | 8 ++++++-- frigate/test/test_config.py | 30 ++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/frigate/config.py b/frigate/config.py index d95dfc3d4..5b524abad 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -82,7 +82,7 @@ class MotionConfig(BaseModel): ge=1, le=255, ) - contour_area: int = Field(default=100, title="Contour Area") + contour_area: Optional[int] = Field(title="Contour Area") delta_alpha: float = Field(default=0.2, title="Delta Alpha") frame_alpha: float = Field(default=0.2, title="Frame Alpha") frame_height: Optional[int] = Field(title="Frame Height") @@ -99,7 +99,11 @@ class RuntimeMotionConfig(MotionConfig): frame_shape = config.get("frame_shape", (1, 1)) if "frame_height" not in config: - config["frame_height"] = max(frame_shape[0] // 6, 180) + config["frame_height"] = max(frame_shape[0] // 6, 120) + + if "contour_area" not in config: + frame_width = frame_shape[1] * config["frame_height"] / frame_shape[0] + config["contour_area"] = config["frame_height"] * frame_width * 0.003912363 mask = config.get("mask", "") config["raw_mask"] = mask diff --git a/frigate/test/test_config.py b/frigate/test/test_config.py index 35ba86a5b..6a91a2814 100644 --- a/frigate/test/test_config.py +++ b/frigate/test/test_config.py @@ -451,7 +451,7 @@ class TestConfig(unittest.TestCase): runtime_config = frigate_config.runtime_config assert runtime_config.cameras["back"].detect.max_disappeared == 5 * 5 - def test_motion_frame_height_wont_go_below_180(self): + def test_motion_frame_height_wont_go_below_120(self): config = { "mqtt": {"host": "mqtt"}, @@ -475,7 +475,33 @@ class TestConfig(unittest.TestCase): assert config == frigate_config.dict(exclude_unset=True) runtime_config = frigate_config.runtime_config - assert runtime_config.cameras["back"].motion.frame_height >= 180 + assert runtime_config.cameras["back"].motion.frame_height >= 120 + + def test_motion_contour_area_dynamic(self): + + config = { + "mqtt": {"host": "mqtt"}, + "cameras": { + "back": { + "ffmpeg": { + "inputs": [ + { + "path": "rtsp://10.0.0.1:554/video", + "roles": ["detect"], + }, + ] + }, + "height": 1080, + "width": 1920, + } + }, + } + + frigate_config = FrigateConfig(**config) + assert config == frigate_config.dict(exclude_unset=True) + + runtime_config = frigate_config.runtime_config + assert round(runtime_config.cameras["back"].motion.contour_area) == 225 if __name__ == "__main__":