41 lines
4.4 KiB
Markdown
41 lines
4.4 KiB
Markdown
# AGENTS.md
|
|
|
|
Feedmill Recounter: AI video analysis for counting sacks/boxes in feedmill videos. Flask web UI + CLI, file-backed (no DB).
|
|
|
|
## Commands
|
|
- Python >=3.10 required.
|
|
- Install: `pip install -e ".[dev]"`
|
|
- Tests: `pytest` (config in `pyproject.toml`: testpaths = `tests`)
|
|
- Single test: `pytest tests/test_app.py::test_name` or `pytest -k name`
|
|
- CLI: `recounter --video input.mp4 --model v4-best.pt --filter sack --output-dir ./output`
|
|
- Web UI: `recounter-web` (default port 9050; `WEB_PORT` overrides)
|
|
- List models: `recounter --list-models --models-dir ./models`
|
|
|
|
## Architecture
|
|
- `app.py`: Flask routes, job queue, model upload/conversion endpoints.
|
|
- `src/pipeline.py`: `run_pipeline` / `run_merged_pipeline`; analysis space is fixed 1280x720; pre-stabilizer conf/area filtering + post-polygon box-over-sack suppression; `run_merged_pipeline` selects the first `sack` engine as primary `ByteTrackTracker` (`iou.sack_nms=0.45`) and runs a dedicated per-frame `box_tracker` (`iou.box_nms=0.7`) when a separate engine covers `box`.
|
|
- `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.
|
|
- `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).
|
|
- Zone writes go through `POST /api/zones/<preset>` (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=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, native 1920x1080 scaled to 1280x720 at runtime), `.env` (paths/secrets).
|
|
|
|
## Quirks
|
|
- Model weights and `.engine` files are gitignored; local models required for real runs.
|
|
- `numpy<2.0` pinned for Jetson torch.
|
|
- Tests auto-isolate `job_queue` output dir via `tests/conftest.py`; do not point tests at real `output/`.
|
|
- 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.
|
|
- Zones live in `zones.json` natively in **1920x1080** (`reference_resolution` `[1920, 1080]`, matching FCP `main`), and `src/zone_config.py` scales them to the `1280x720` analysis space at runtime via `int(round(v * scale))`. `sync_fcp_zones` automatically updates `"default"` from FCP's `zones.json` (`FCP_ZONES_PATH` or `/home/jetson/feedmill_semarang_project/karung_counter_semarang/zones.json`) whenever FCP's file has a newer `mtime`.
|
|
- Two presets ship: `default` (synced to FCP `main` `91d8b48`: `palet` `[[612, 1], [1340, 1], [1340, 267], [608, 267]]`, `truck_area` `[[600, 290], [609, 1076], [1404, 1078], [1381, 290]]`, `counting_area` `[[574, 50], [586, 1077], [1418, 1076], [1397, 50]]`, `count_line` `y=215` -> runtime `143` at `720p`) and `fcp-2026-10-15` (pre-recalibration, `count_line` `y=330` -> runtime `220` at `720p` matching `7beb820`).
|
|
- Zone writes are localhost-only; remote operators use an SSH tunnel (`ssh -L 9050:127.0.0.1:9050 jetson@<host>`). Both `POST /api/zones/<preset>` and `/calibrate` (Import JSON) accept FCP 1920x1080 flat JSON as well as recounter preset JSON (and scale legacy `1280x720` inputs up to `1920x1080`).
|
|
- `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).
|
|
- The `/calibrate` editor and `tools/calibrate_zone.py` both accept a pasted JSON preset (Import / Export JSON panel), so zones can be shared over chat or email and applied by paste.
|