6933406ae3
Skeleton of the host-side vision service per the packaging decision: a Python/FastAPI app at apps/vision/, uv-managed, wired into the Turbo graph via a thin package.json shim (dev/lint/test/build → uv/uvicorn/ruff/pytest). A per-package turbo.json sets build outputs [] so the no-op build is warning-free. Endpoints: GET /health (readiness + model version) and POST /analyze (raw octet-stream body, so Node POSTs Snapshot.bytes directly; empty→400, oversize→413, recognizer-not-ready→503). The recognizer is a Protocol with a StubRecognizer (no models, boots/tests offline — the dev/CI default) and a FastAlprRecognizer (the real MIT YOLOv9+CCT/ONNX stack, lazily imported; missing models ⇒ ready=False, not a crash) — the device-adapter pattern applied to the model. fast-alpr + onnxruntime are an optional `alpr` extra, so `uv sync` needs no model download. Verified: turbo run lint|test|build includes @parking/vision and stays green; uv run mypy strict-clean; uvicorn boots and serves /health + /analyze live; pnpm workspace 6→7. Not built yet: the Node VisionClient adapter, a Dockerfile + model fetch, and Job 2 (vehicle verification). Updates the packaging decision (As-scaffolded) + log. Claude-Session: https://claude.ai/code/session_01Xcm6ikLgGoCxxHrxtjkk5V
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
"""The /analyze response contract — the shape the Node VisionClient adapter consumes.
|
|
|
|
Mirrors the first-cut API in wiki/entities/opencv-anpr-service.md:
|
|
{ plate: {text, confidence, bbox}|null, vehicle: {...}|null, modelVersion, tookMs }
|
|
Job 2 (vehicle attributes) is scaffolded as an optional field, not yet populated —
|
|
fast-alpr is plate-only; the vehicle stage is built later on the same ONNX runtime.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class BBox(BaseModel):
|
|
"""Plate bounding box in pixels (top-left origin)."""
|
|
|
|
x1: int
|
|
y1: int
|
|
x2: int
|
|
y2: int
|
|
|
|
|
|
class PlateResult(BaseModel):
|
|
text: str
|
|
confidence: float = Field(ge=0.0, le=1.0)
|
|
bbox: BBox | None = None
|
|
|
|
|
|
class VehicleResult(BaseModel):
|
|
"""Job 2 — vehicle attributes / fingerprint (anti-spoofing). Not yet produced."""
|
|
|
|
colour: str | None = None
|
|
body_type: str | None = None
|
|
make: str | None = None
|
|
model: str | None = None
|
|
|
|
|
|
class AnalyzeResponse(BaseModel):
|
|
# The single best plate, or null when none was found.
|
|
plate: PlateResult | None = None
|
|
# All plates found (a frame may contain several vehicles).
|
|
plates: list[PlateResult] = Field(default_factory=list)
|
|
vehicle: VehicleResult | None = None
|
|
# True when the best plate is below the confidence floor — Node should treat the
|
|
# read as advisory only and prefer the ticket path. See fail-state-safety.
|
|
low_confidence: bool = False
|
|
model_version: str
|
|
took_ms: float
|
|
|
|
|
|
class HealthResponse(BaseModel):
|
|
status: str
|
|
recognizer: str
|
|
ready: bool
|
|
model_version: str
|
|
detail: str | None = None
|