From b9d4bd11b33b872378eab1d9ad77fc83316992e2 Mon Sep 17 00:00:00 2001 From: jetson Date: Tue, 17 Nov 2026 11:15:35 +0700 Subject: [PATCH] feat(counting): align max_step_dy (160) and unload_confirm (1) with FCP main --- AGENTS.md | 2 +- CHANGELOG.md | 6 +++--- README.md | 4 ++-- config.yaml | 4 ++-- src/config.py | 4 ++-- src/counting.py | 8 ++++---- tests/test_counting.py | 16 ++++++++-------- tests/test_pipeline.py | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 7258957..d24edf7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -21,7 +21,7 @@ Feedmill Recounter: AI video analysis for counting sacks/boxes in feedmill video - `src/counting.py`: `LineCrossCounter` — the FCP counting gates (single count, corridor, ID switch, unload confirm). - Zone editor: `GET /calibrate` (`templates/calibrate.html`, `static/calibrate.js`); writes go through `POST /api/zones/` and `POST /api/zones//reset` (localhost only). - Zone writes go through `POST /api/zones/` (localhost-only, validated, atomic). Do not hand-edit `zones.json` while the web app runs — the editor merges over the stored preset. -- The counting gates live in `config.yaml` under `counting:` and match FCP `main` (`capture_below_px=100`, `max_step_dy_px=120`, `max_gap_frames=15`, `unload_confirm_frames=3`). +- The counting gates live in `config.yaml` under `counting:` and match FCP `main` (`capture_below_px=100`, `max_step_dy_px=160`, `max_gap_frames=15`, `unload_confirm_frames=1`). - `tools/calibrate_zone.py` and the `/calibrate` page produce the same geometry; keep their count-line derivation in sync (`x_start=min`, `x_end=max`, `y=round(mean(ys))`). - Config: `config.yaml` (tunables), `zones.json` (fixed zones, 1280x720 analysis space), `.env` (paths/secrets). diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b89e8f..6b5929a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -92,9 +92,9 @@ version tags are cut in this repo — `main` is the release line). - **Align corridor filter and default palet zone with FCP main (`91d8b48`)**: the corridor filter in `src/counting.py` now keeps `_initial_zone` when a detection sits deep in the truck bed (matching FCP `main`), while - `counting.max_step_dy_px` (120) and `counting.unload_confirm_frames` (3) - remain aligned with FCP's runtime `CountingConfig` - (`src/config_loader.py:104-107`). Recalibrated `presets.default.palet` in + `counting.max_step_dy_px` (120→160) and `counting.unload_confirm_frames` (3→1) + now match FCP `main`'s `CountingConfig` (`src/config_loader.py:104-107`). + Recalibrated `presets.default.palet` in `zones.json` and `DEFAULT_ZONES` to `[[408, 1], [893, 1], [893, 178], [405, 178]]` (scaled from FCP's 1920×1080 `[[612, 1], [1340, 1], [1340, 267], [608, 267]]`). `fcp-2026-10-15` stays unchanged. diff --git a/README.md b/README.md index 2343c3b..af44a42 100644 --- a/README.md +++ b/README.md @@ -148,10 +148,10 @@ Edit `config.yaml` instead of the code for these values; restart the job / re-ru - `capture_below_px` (100) — corridor below the line: a sack deep in the truck bed never counts. -- `max_step_dy_px` (120) — a per-step vertical jump of this size is an ID +- `max_step_dy_px` (160) — a per-step vertical jump of this size is an ID switch: the track's history resets. - `max_gap_frames` (15) — frames a track may vanish before its history resets. -- `unload_confirm_frames` (3) — consecutive "above" frames needed to confirm +- `unload_confirm_frames` (1) — consecutive "above" frames needed to confirm an unload. A track counts at most once. The unload branch is unreachable by design diff --git a/config.yaml b/config.yaml index 13986d3..fc07ad2 100644 --- a/config.yaml +++ b/config.yaml @@ -43,9 +43,9 @@ batch: # Counting gates (FCP main, src/config_loader.py:104-107). counting: capture_below_px: 100 # corridor below the line: deep truck bed, never counts - max_step_dy_px: 120 # per-step vertical jump = ID switch -> reset track history + max_step_dy_px: 160 # per-step vertical jump = ID switch -> reset track history max_gap_frames: 15 # frames a track may vanish before its history resets - unload_confirm_frames: 3 # consecutive "above" frames needed to confirm an unload + unload_confirm_frames: 1 # consecutive "above" frames needed to confirm an unload pipeline: detect_interval: 1 # detection+tracking every N frames (1 = every frame, most accurate) diff --git a/src/config.py b/src/config.py index 4cb8726..f8de411 100644 --- a/src/config.py +++ b/src/config.py @@ -55,9 +55,9 @@ DEFAULTS: dict = { "counting": { # FCP main, src/config_loader.py:104-107. "capture_below_px": 100, - "max_step_dy_px": 120, + "max_step_dy_px": 160, "max_gap_frames": 15, - "unload_confirm_frames": 3, + "unload_confirm_frames": 1, }, "pipeline": { "detect_interval": 1, diff --git a/src/counting.py b/src/counting.py index 3754ecb..e870606 100644 --- a/src/counting.py +++ b/src/counting.py @@ -60,9 +60,9 @@ class LineCrossCounter: margin: int = 20, dedup_radius: float = 30.0, capture_below: float = 100.0, - max_step_dy: float = 120.0, + max_step_dy: float = 160.0, max_gap_frames: int = 15, - unload_confirm_frames: int = 3, + unload_confirm_frames: int = 1, ) -> None: self._line_y = line_y self._line_x_start = line_x_start @@ -392,9 +392,9 @@ class MultiClassLineCounter: margin: int = 20, dedup_radius: float = 30.0, capture_below: float = 100.0, - max_step_dy: float = 120.0, + max_step_dy: float = 160.0, max_gap_frames: int = 15, - unload_confirm_frames: int = 3, + unload_confirm_frames: int = 1, ) -> None: self._sack = LineCrossCounter( line_y=line_y, diff --git a/tests/test_counting.py b/tests/test_counting.py index b39d9dc..d531690 100644 --- a/tests/test_counting.py +++ b/tests/test_counting.py @@ -79,9 +79,9 @@ def test_constructor_defaults_match_fcp_config(): """Defaults mirror FCP's runtime config values (config_loader.py CountingConfig).""" c = LineCrossCounter(line_y=220, line_x_start=0, line_x_end=1280) assert c._capture_below == 100.0 - assert c._max_step_dy == 120.0 + assert c._max_step_dy == 160.0 assert c._max_gap_frames == 15 - assert c._unload_confirm_frames == 3 + assert c._unload_confirm_frames == 1 def test_corridor_below_capture_below_never_counts(): @@ -182,13 +182,13 @@ def test_update_line_keeps_existing_track_history(): def test_multiclass_forwards_gates_and_update_line(): """Both class counters get the same gates and the same line geometry.""" c = MultiClassLineCounter(line_y=220, line_x_start=0, line_x_end=1280, - capture_below=100.0, max_step_dy=120.0, - max_gap_frames=15, unload_confirm_frames=3) + capture_below=100.0, max_step_dy=160.0, + max_gap_frames=15, unload_confirm_frames=1) for counter in (c._sack, c._box): assert counter._capture_below == 100.0 - assert counter._max_step_dy == 120.0 + assert counter._max_step_dy == 160.0 assert counter._max_gap_frames == 15 - assert counter._unload_confirm_frames == 3 + assert counter._unload_confirm_frames == 1 c.update_line(500, 10, 1200) assert c._sack.line_y == 500 and c._box.line_y == 500 assert c._sack.line_x_start == 10 and c._box.line_x_end == 1200 @@ -202,9 +202,9 @@ def test_counting_config_section_matches_fcp_values(): cfg = load_config() counting = cfg["counting"] assert counting["capture_below_px"] == 100 - assert counting["max_step_dy_px"] == 120 + assert counting["max_step_dy_px"] == 160 assert counting["max_gap_frames"] == 15 - assert counting["unload_confirm_frames"] == 3 + assert counting["unload_confirm_frames"] == 1 assert DEFAULTS["counting"] == counting diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 05af243..028cd8b 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -1397,7 +1397,7 @@ def _patch_real_counter(monkeypatch, pipe_mod): return counters # A sack that crosses the count line (y=360 in the 1280x720 analysis frame). -# The y1 jump stays inside the FCP gates: <= max_step_dy (120 px) per frame and +# The y1 jump stays inside the FCP gates: <= max_step_dy (160 px) per frame and # below the corridor bound (line_y + capture_below = 460 px). SACK_ABOVE = Detection( bbox=(600.0, 280.0, 640.0, 320.0), confidence=0.9, class_id=0,