make contour_area dynamic

This commit is contained in:
Blake Blackshear 2021-07-01 07:47:22 -05:00
parent 2a41a9d3ff
commit b4e7e51e63
2 changed files with 34 additions and 4 deletions

View File

@ -82,7 +82,7 @@ class MotionConfig(BaseModel):
ge=1, ge=1,
le=255, 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") delta_alpha: float = Field(default=0.2, title="Delta Alpha")
frame_alpha: float = Field(default=0.2, title="Frame Alpha") frame_alpha: float = Field(default=0.2, title="Frame Alpha")
frame_height: Optional[int] = Field(title="Frame Height") frame_height: Optional[int] = Field(title="Frame Height")
@ -99,7 +99,11 @@ class RuntimeMotionConfig(MotionConfig):
frame_shape = config.get("frame_shape", (1, 1)) frame_shape = config.get("frame_shape", (1, 1))
if "frame_height" not in config: 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", "") mask = config.get("mask", "")
config["raw_mask"] = mask config["raw_mask"] = mask

View File

@ -451,7 +451,7 @@ class TestConfig(unittest.TestCase):
runtime_config = frigate_config.runtime_config runtime_config = frigate_config.runtime_config
assert runtime_config.cameras["back"].detect.max_disappeared == 5 * 5 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 = { config = {
"mqtt": {"host": "mqtt"}, "mqtt": {"host": "mqtt"},
@ -475,7 +475,33 @@ class TestConfig(unittest.TestCase):
assert config == frigate_config.dict(exclude_unset=True) assert config == frigate_config.dict(exclude_unset=True)
runtime_config = frigate_config.runtime_config 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__": if __name__ == "__main__":