$ show mftnakrsu/Automatic_Number_Plate_Recognition_YOLO_OCR
This repository implements a modern Automatic Number Plate Recognition (ANPR) pipeline as a production-ready application. It ingests images (via HTTP upload or WebSocket stream), runs detection using the `fast-alpr` library (YOLO-based ONNX model), performs OCR with `fast-plate-ocr`, applies post-processing (confusion-pair correction, Turkish plate format parsing, temporal majority voting), optionally tracks vehicles via an IoU-based multi-object tracker, and stores only HMAC-SHA256 hashed plate texts for privacy compliance. The system is exposed through a FastAPI REST API with WebSocket support and a HTMX web UI, plus a Typer CLI for inference and server management. It is containerized with Docker and publishes to PyPI and GHCR. The repository also contains a legacy directory (`legacy/`) with a complete YOLOv5 training pipeline for license plate detection, but that code is explicitly unmaintained and serves as historical reference only. The modern codebase is actively maintained, well-tested, and demonstrates strong software engineering practices including protocol-based abstractions, structured logging, Prometheus metrics, and privacy-by-design persistence.
The LLM identified 5 files worth highlighting for reuse:
Implements a confidence-weighted per-character majority voter for smoothing OCR results over a temporal window. It takes a list of (char, confidence) tuples from multiple frames and produces the most likely character string. Self-contained and could be reused in any sequential OCR pipeline requiring temporal smoothing.
Corrects common OCR confusion pairs (e.g., '0' vs 'O', '1' vs 'I' vs 'L') using a rule-based mapping. The logic is dataset-agnostic and can be extracted to improve OCR accuracy in any alphanumeric recognition system.
Provides `hash_plate()` which computes an HMAC-SHA256 digest of a plate string using a configurable pepper. This enables deterministic but non-reversible storage of plate texts, complying with data protection regulations. The implementation is standalone and can be reused in any system requiring privacy-preserving identifier storage.
A lightweight, dependency-free IoU-based multi-object tracker that assigns detections to tracks using a greedy Hungarian algorithm. It maintains track IDs across frames with configurable thresholds for birth/death. The entire module is a single file with no internal imports, making it easily extractable for any object tracking application.
Defines a `Detector` protocol class that specifies the interface for detection backends (e.g., `FastAlprDetector`). This abstraction decouples the pipeline from any specific detection library, enabling easy swapping of backends (e.g., to ByteTrack or custom ONNX models) without modifying pipeline logic. Demonstrates clean dependency inversion suitable for reuse in modular vision pipelines.