feat(vision): add recognize CLI + verify fast-alpr end-to-end
Add a dev CLI (uv run python -m vision_service.cli <image>) that runs a recognizer on an image file and prints the parsed plate(s) + confidence + region — fast feedback with no HTTP. Also a package.json `recognize` script and a vision-recognize entry point. Verified fast-alpr for real: installed the `alpr` extra, downloaded the YOLOv9 + CCT ONNX weights (~11MB, cached offline under ~/.cache), and ran recognition on the project's test image → "5AU5341" at 1.000 confidence, region "Czech Republic", ~40ms on CPU, via both the CLI and POST /analyze. Fixes result parsing against the actual fast-alpr API: ocr.confidence is a LIST of per-character confidences (not a scalar) — reduced to one plate confidence via the MIN (a plate is only as trustworthy as its weakest character); also surface ocr.region. Extracted the per-result mapping into a pure plate_from_alpr_result + _reduce_confidence and unit-tested them (no model weights needed). 7 tests pass; ruff + mypy strict clean; full turbo build/lint/test green. Claude-Session: https://claude.ai/code/session_01Xcm6ikLgGoCxxHrxtjkk5V
This commit is contained in:
@@ -30,6 +30,20 @@ uv sync --extra alpr # installs fast-alpr + onnxruntime (downloa
|
||||
VISION_RECOGNIZER=fast_alpr uv run uvicorn vision_service.app:app --port 8089
|
||||
```
|
||||
|
||||
Model weights (~11 MB: a YOLOv9 detector + CCT OCR) download on first use and cache under
|
||||
`~/.cache/open-image-models` + `~/.cache/fast-plate-ocr` — offline after that.
|
||||
|
||||
### Quick test against an image (CLI, no HTTP)
|
||||
|
||||
```bash
|
||||
uv run python -m vision_service.cli path/to/car.jpg # or: pnpm --filter @parking/vision recognize -- car.jpg
|
||||
uv run python -m vision_service.cli car.jpg --ocr cct-s-v2-global-model # try another OCR model
|
||||
```
|
||||
|
||||
Prints the parsed plate(s) + confidence + region as JSON. Confidence is the **min** of fast-alpr's
|
||||
per-character confidences (a plate is only as trustworthy as its weakest character). Example output on
|
||||
the fast-alpr test image: `5AU5341 (1.000) region "Czech Republic"` in ~40 ms on CPU.
|
||||
|
||||
`fast-alpr` is MIT (YOLOv9 detector + CCT OCR on ONNX Runtime). Swap `VISION_OCR_MODEL` to the 40+
|
||||
country European model to benchmark Albanian plates. For GPU/NPU, install `onnxruntime-gpu` /
|
||||
`-openvino` / `-directml` instead of `onnxruntime`.
|
||||
|
||||
Reference in New Issue
Block a user