forked from andrew/feedmill-recounter
4.4 KiB
4.4 KiB
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 inpyproject.toml: testpaths =tests) - Single test:
pytest tests/test_app.py::test_nameorpytest -k name - CLI:
recounter --video input.mp4 --model v4-best.pt --filter sack --output-dir ./output - Web UI:
recounter-web(default port 9050;WEB_PORToverrides) - 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_pipelineselects the firstsackengine as primaryByteTrackTracker(iou.sack_nms=0.45) and runs a dedicated per-framebox_tracker(iou.box_nms=0.7) when a separate engine coversbox.src/job.py: in-memoryJobQueue; jobs die on restart, output dirs survive.src/model_registry.py: scansmodels/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 throughPOST /api/zones/<preset>andPOST /api/zones/<preset>/reset(localhost only). - Zone writes go through
POST /api/zones/<preset>(localhost-only, validated, atomic). Do not hand-editzones.jsonwhile the web app runs — the editor merges over the stored preset. - The counting gates live in
config.yamlundercounting:and match FCPmain(capture_below_px=100,max_step_dy_px=160,max_gap_frames=15,unload_confirm_frames=1). tools/calibrate_zone.pyand the/calibratepage 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
.enginefiles are gitignored; local models required for real runs. numpy<2.0pinned for Jetson torch.- Tests auto-isolate
job_queueoutput dir viatests/conftest.py; do not point tests at realoutput/. - Web process currently
python app.py; restart it after code changes. README.mdsays port 9000 in.env.example, but code defaults to 9050.- Conversion to
.enginemust start from.pt; Ultralytics cannot export from ONNX. .engineconversion may take minutes on Jetson.- Zones live in
zones.jsonnatively in 1920x1080 (reference_resolution[1920, 1080], matching FCPmain), andsrc/zone_config.pyscales them to the1280x720analysis space at runtime viaint(round(v * scale)).sync_fcp_zonesautomatically updates"default"from FCP'szones.json(FCP_ZONES_PATHor/home/jetson/feedmill_semarang_project/karung_counter_semarang/zones.json) whenever FCP's file has a newermtime. - Two presets ship:
default(synced to FCPmain91d8b48: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_liney=215-> runtime143at720p) andfcp-2026-10-15(pre-recalibration,count_liney=330-> runtime220at720pmatching7beb820). - Zone writes are localhost-only; remote operators use an SSH tunnel (
ssh -L 9050:127.0.0.1:9050 jetson@<host>). BothPOST /api/zones/<preset>and/calibrate(Import JSON) accept FCP 1920x1080 flat JSON as well as recounter preset JSON (and scale legacy1280x720inputs up to1920x1080). tools/record_rtsp.shrecords an RTSP stream to a file for live-vs-recounter parity runs; the recounter stays file-based (no RTSP input path).- The
/calibrateeditor andtools/calibrate_zone.pyboth accept a pasted JSON preset (Import / Export JSON panel), so zones can be shared over chat or email and applied by paste.