docs: zone calibration workflow, counting gates and the 1280x720 zone space

This commit is contained in:
jetson committed 2026-11-12 14:39:17 +07:00
1 parent 5c295c5849
commit 0e76c096bb
3 files changed
+102 -2

No files matched your search

+10 -2
View File
@@ -16,7 +16,10 @@ Feedmill Recounter: AI video analysis for counting sacks/boxes in feedmill video
- `src/job.py`: in-memory `JobQueue`; jobs die on restart, output dirs survive.
- `src/model_registry.py`: scans `models/` by stem; formats `.engine` > `.pt` > `.onnx`.
- `src/model_conversion.py`: background conversion (`.pt` -> `.onnx`, then `.pt` -> `.engine`; Ultralytics cannot export an engine from ONNX); only one at a time and blocks analysis.
- Config: `config.yaml` (tunables), `zones.json` (fixed zones), `.env` (paths/secrets).
- `src/zone_config.py`: loads, validates and atomically saves the zone presets (`.bak` + temp file + `os.replace`).
- `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/<preset>` and `POST /api/zones/<preset>/reset` (localhost only).
- Config: `config.yaml` (tunables), `zones.json` (fixed zones, 1280x720 analysis space), `.env` (paths/secrets).
## Quirks
- Model weights and `.engine` files are gitignored; local models required for real runs.
@@ -25,4 +28,9 @@ Feedmill Recounter: AI video analysis for counting sacks/boxes in feedmill video
- Web process currently `python app.py`; restart it after code changes.
- `README.md` says port 9000 in `.env.example`, but code defaults to 9050.
- Conversion to `.engine` must start from `.pt`; Ultralytics cannot export from ONNX.
- `.engine` conversion may take minutes on Jetson.
- `.engine` conversion may take minutes on Jetson.
- Zones live in `zones.json` in the **1280x720 analysis space**; `reference_resolution` is `[1280, 720]`, so the scale factor is 1.0. Never introduce a second coordinate space (the editor maps client -> source in the same 1280x720 space).
- Two presets ship: `default` (the live counter's `95c031b` recalibration, count line y=182 — the active preset) and `fcp-2026-10-15` (pre-recalibration, count line y=220 — matches what the deployed live counter counts with today, because its `predict.py` hardcodes the line).
- The unload branch in `src/counting.py` is unreachable by design (parity with the live system): `unloading` is always 0 and `net` equals the gross count. Do not "fix" it into a counted unload.
- Zone writes are localhost-only; remote operators use an SSH tunnel (`ssh -L 9050:127.0.0.1:9050 jetson@<host>`).
- `tools/record_rtsp.sh` records an RTSP stream to a file for live-vs-recounter parity runs; the recounter stays file-based (no RTSP input path).
+34
View File
@@ -47,6 +47,14 @@ version tags are cut in this repo — `main` is the release line).
sanctioned path.
- `docs/ai-handoff-fcp-recount.md`: AI handoff for the FCP-side phase 2.
- `ERD.md` (Mermaid ERD) + this changelog (`97507f8`).
- **Interactive zone editor** at `/calibrate`: drag the counting ROI, the truck
ROI and the count line over a frame of an uploaded video, then save. Zone
writes are localhost-only and atomic (`zones.json.bak` + temp file +
`os.replace`).
- **Zone write API**: `POST /api/zones/<preset>` and
`POST /api/zones/<preset>/reset` validate, save and restore a zone preset.
- `tools/record_rtsp.sh` records an RTSP stream to a file, so the live counter
and the recounter can be compared on the same footage.
### Fixed
- **Overlapping sacks of one model were dropped** (`ac2a235`): the merged
@@ -69,6 +77,10 @@ version tags are cut in this repo — `main` is the release line).
looked filters up by `ModelConfig.filename` while UI/API store them by
`stem` — `filter_<stem>` now honored on single-model jobs (stem-first,
filename fallback for legacy callers).
- `tools/calibrate_zone.py` now writes coordinates in the 1280×720 analysis
space (the frame is resized before the clicks are taken, so the native video
resolution does not matter) and derives the count line the way the live
counter does (horizontal at the mean y of its two endpoints).
### Changed
- **A finished job leaves ONE compressed video** (`5e2a317`): the annotated
@@ -191,6 +203,28 @@ version tags are cut in this repo — `main` is the release line).
- **Auto-resize uploads to 720p, 720p default output** — only transcoded when
source is taller than 720p; default output height option set to 720p
(`89a265c`).
- **`zones.json` now carries the calibration in the 1280×720 analysis space**
(`reference_resolution: [1280, 720]`, scale factor 1.0), matching the live
counter's geometry. Two presets ship: `default` (the live counter's
`95c031b` recalibration, count line y=182 — the active preset) and
`fcp-2026-10-15` (the pre-recalibration geometry, count line y=220), which is
what the deployed live counter counts with today, because its `predict.py`
still hardcodes the line and does not read `zones.json`. **Published counts
change**: the previous preset was a 1920×1080 approximation.
- **Counting gates ported from the live counter's `feat/interactive-roi-line`
branch**: a track counts at most once, a sack deep in the truck bed never
counts, an ID switch drops the track's history, an unload needs three
consecutive frames above the line. New `counting:` keys in `config.yaml`
(`capture_below_px`, `max_step_dy_px`, `max_gap_frames`,
`unload_confirm_frames`).
- **`unloading` is 0 on every batch and `net` equals the gross count.** The
unload branch is unreachable by design (parity with the live system): the
gates were ported literally, including the live counter's own unreachable
unload branch — a track that already counted as a loading can never count a
second time — and the live system publishes `unloading = 0` on every batch.
Unloadings are not counted.
- The annotated output draws the calibrated counting and truck polygons
instead of a plain bounding box.
### Added
- Plan doc for fixed-zone mode (`.opencode/plans/fixed-zone-mode.md`).
+58
View File
@@ -97,6 +97,11 @@ recounter --video PATH Input video file
| `/api/jobs/<job_id>` | GET | Job detail (JSON) |
| `/api/jobs/<job_id>/cancel` | POST | Cancel a running job |
| `/api/jobs/<job_id>/samples` | GET | Sample frame paths (JSON) |
| `/calibrate` | GET | Interactive zone editor |
| `/api/zones` | GET | Zone preset list (JSON) |
| `/api/zones/<preset>` | GET | One zone preset (JSON) |
| `/api/zones/<preset>` | POST | Save a zone preset (localhost only) |
| `/api/zones/<preset>/reset` | POST | Restore a preset to its shipped default (localhost only) |
## Configuration
@@ -167,6 +172,59 @@ The web upload form offers three zone modes:
In multi-model runs, model #1 (primary, alphabetical order) is tracked every frame; supplementary models run every 5th frame; detections from supplementary models get synthetic track IDs so counts and overlays stay stable.
### Calibrating counting zone
The counting line, the counting ROI and the truck ROI are calibrated in
**1280×720** pixels — the frame the pipeline analyses, and the frame the live
counter uses. The editor, `zones.json` and the analysis frame are one
coordinate space; there is no second scale factor.
Open `http://<host>:9050/calibrate`:
1. Pick an uploaded video and scrub to a frame where the truck is in place.
2. Press **Unlock Edit**.
3. Drag the vertices of the counting ROI (blue), the truck ROI (orange) and the
two ends of the count line (green). The line stays horizontal; the shaded
band is the ±20 px trigger zone.
4. **Save Zones**.
Two presets ship:
- `default` — the live counter's `95c031b` recalibration (count line y=182).
It is the active preset (`active_preset`).
- `fcp-2026-10-15` — the pre-recalibration geometry (count line y=220). The
deployed live counter counts with this geometry today: its `predict.py`
hardcodes the line and never reads `zones.json`. Pick this preset to
reproduce today's live numbers.
The write API (`POST /api/zones/<preset>`, `POST /api/zones/<preset>/reset`) is
**localhost-only**. From another machine, tunnel the port over SSH:
```bash
ssh -L 9050:127.0.0.1:9050 jetson@<host>
```
Writes are atomic: the previous file is copied to `zones.json.bak`, the new
one is written to a temp file, and the temp file replaces `zones.json`.
### Counting gates
`config.yaml` carries the counting gates ported from the live counter's
`feat/interactive-roi-line` branch, under `counting:`:
- `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
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
an unload.
A track counts at most once. The unload branch is unreachable by design
(parity with the live system, which runs the same gates): a track that already
counted as a loading can never count a second time. `unloading` is therefore
always 0 and `net` equals the gross count — unloadings are not counted.
## Comparing with the live system (RTSP)
The recounter analyses files. The live counter streams over RTSP, so compare