diff --git a/config.yaml b/config.yaml index 6b52030..151e453 100644 --- a/config.yaml +++ b/config.yaml @@ -8,7 +8,8 @@ detection: box_conf: 0.35 # detector confidence for box truck_conf: 0.45 # truck detector confidence -# Per-class minimum bbox area (px^2) — drops tiny false positives. +# Per-class minimum bbox area (px^2) — authored in platform's 1280x720 +# reference space; pipeline scales to actual frame size (physical parity). min_bbox_area: sack: 1500 box: 1500 diff --git a/src/pipeline.py b/src/pipeline.py index ca19a97..71a408c 100644 --- a/src/pipeline.py +++ b/src/pipeline.py @@ -346,7 +346,7 @@ def run_pipeline( tracked_sacks, iou_threshold=cfg["iou"]["suppress_sack_box"] ) tracked_sacks = _apply_class_confs(tracked_sacks, sack_conf, box_conf) - tracked_sacks = _apply_min_area(tracked_sacks, cfg["min_bbox_area"]) + tracked_sacks = _apply_min_area(tracked_sacks, _scaled_min_areas(cfg, w, h)) counter.update(countable_detections(tracked_sacks)) # Annotate frame @@ -509,6 +509,18 @@ def _apply_min_area(dets, areas): ] +# Platform (karung_counter_semarang) force-resizes frames to 1280x720 before +# detection, so its min_bbox_area values are authored in that space. Scale by +# frame area so the physical-size threshold matches on native 1080p input. +PLATFORM_REF_AREA = 1280 * 720 + + +def _scaled_min_areas(cfg, frame_w: int, frame_h: int) -> dict: + """min_bbox_area scaled from platform's 1280x720 reference to frame size.""" + scale = (frame_w * frame_h) / PLATFORM_REF_AREA + return {k: v * scale for k, v in cfg["min_bbox_area"].items()} + + def run_merged_pipeline( video_path: str, model_configs: list[ModelConfig], @@ -738,7 +750,7 @@ def run_merged_pipeline( tracked, iou_threshold=cfg["iou"]["suppress_sack_box"] ) tracked = _apply_class_confs(tracked, sack_conf, box_conf) - tracked = _apply_min_area(tracked, cfg["min_bbox_area"]) + tracked = _apply_min_area(tracked, _scaled_min_areas(cfg, w, h)) # Count using only detections with track_id (tracker results) counter.update(countable_detections([d for d in tracked if d.track_id is not None])) diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 187ffb1..6a43f6a 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -371,6 +371,22 @@ def test_apply_min_area_per_class_thresholds(): ] +def test_scaled_min_areas_platform_parity(): + """1080p frames scale thresholds 2.25x; 720p stays at platform reference.""" + from src.pipeline import _scaled_min_areas + + cfg = {"min_bbox_area": {"sack": 1500, "box": 1500, "truck": 5000}} + + # Native 720p == platform's reference resolution → unchanged + at_720p = _scaled_min_areas(cfg, 1280, 720) + assert at_720p == {"sack": 1500, "box": 1500, "truck": 5000} + + # 1080p: area ratio 2.25 → 1500 -> 3375, 5000 -> 11250 + at_1080p = _scaled_min_areas(cfg, 1920, 1080) + assert at_1080p["sack"] == 3375 + assert at_1080p["truck"] == 11250 + + # ── Perf/output tuning params (signature contracts) ────────────────────