20a3cb3e80
Fills /analyze vehicle.body_type + confidence (car / motorcycle / bus / truck from COCO, mapped to the shared vocabulary) for the Car Wash desk's category suggestion (venue-modules.md §Vehicle category from vision). Advisory: the operator decides, a confident downgrade is flagged, nothing is gated on it. - vision_service/vehicle.py: pure numpy/cv2 letterbox (pad 114, raw BGR), stride-grid decode, class-agnostic NMS, one vehicle per frame (the box holding the plate's centre, else the largest); YoloxVehicleDetector on onnxruntime CPU, 2 intra-op threads. - recognizer.py: WithVehicle composes the stage over any plate recognizer (stub included); a failing stage yields vehicle=null + a "vehicle: …" note in /health.detail — never costs the plate read. model_version reads "<plate>+yolox:yolox_s.onnx@640". - settings: VISION_VEHICLE_MODEL_PATH (unset = off), _INPUT_SIZE (640), _MIN_CONFIDENCE (0.4, the detector's floor; the flag threshold is site config). - Dockerfile bakes yolox_s.onnx (best-effort curl at build; no network → stage off) and sets the path; compose forwards it (empty = off); .env.example documents it. - Measured on four real dev entry frames (DS-2CD1047G3H, 2560×1440): car at 0.83–0.88 in ~240–330 ms; empty lane with a person → none. - tests/test_vehicle.py: decode/NMS/pick/letterbox on synthetic tensors, the composition, and a missing-model /health. Wiki: opencv-anpr-service, venue-modules, log. Claude-Session: https://claude.ai/code/session_01FWncR69HgGPuei1dLrW3cU
48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
"""Runtime configuration, from environment (prefix VISION_).
|
|
|
|
Offline-first: every default is local and works with no network. The recognizer is
|
|
chosen by `recognizer` — "stub" (no models, deterministic placeholder) or "fast_alpr"
|
|
(the real MIT YOLOv9+CCT/ONNX stack, installed via the `alpr` extra).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Literal
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_prefix="VISION_", env_file=".env", extra="ignore")
|
|
|
|
host: str = "0.0.0.0"
|
|
port: int = 8089
|
|
|
|
# Which recognizer to load. "stub" needs no model weights (boots anywhere, for
|
|
# dev/CI); "fast_alpr" loads the real models (requires the `alpr` extra installed).
|
|
recognizer: Literal["stub", "fast_alpr"] = "stub"
|
|
|
|
# fast-alpr model names (only used when recognizer="fast_alpr"). Defaults match the
|
|
# library defaults; swap the OCR for the 40+country EU model to benchmark Albanian
|
|
# plates. See wiki/entities/opencv-anpr-service.md "Recognizer evaluation".
|
|
detector_model: str = "yolo-v9-t-384-license-plate-end2end"
|
|
ocr_model: str = "cct-xs-v2-global-model"
|
|
|
|
# Below this OCR confidence the read is returned but flagged low_confidence, so the
|
|
# Node side can fall back to the ticket path rather than trust it.
|
|
min_confidence: float = 0.5
|
|
|
|
# Vehicle stage (phase A — venue-modules.md §Vehicle category from vision): a YOLOX
|
|
# ONNX graph (Apache-2.0) run beside the plate recognizer. Unset = stage off (the
|
|
# response's `vehicle` stays null). Bake the file into the image (models/), never a
|
|
# path an operator can write (vision-service-hardening.md).
|
|
vehicle_model_path: str | None = None
|
|
vehicle_input_size: int = 640
|
|
# Detection score floor for a vehicle box to count at all (the Node side applies the
|
|
# site's own, stricter threshold before it FLAGS anything).
|
|
vehicle_min_confidence: float = 0.4
|
|
|
|
|
|
def get_settings() -> Settings:
|
|
return Settings()
|