Browse Source

make contour_area dynamic

Blake Blackshear 3 years ago
parent
commit
b4e7e51e63
2 changed files with 34 additions and 4 deletions
  1. 6 2
      frigate/config.py
  2. 28 2
      frigate/test/test_config.py

+ 6 - 2
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

+ 28 - 2
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__":