How 25thmello/anrp_dip works
1. This repository is a single Python package, anpr_tn, centered on an end-to-end Automatic Number Plate Recognition pipeline for Tamil Nadu plates. The architecture is split into inference/runtime code, training code, and persisted data/artifacts.
2. The primary runtime entrypoint is anpr_tn/main.py. It orchestrates two modes: full evaluation over a prepared image set, and single-image inference. It also owns result writing and comparison against ground truth, so it is the main boundary between pipeline outputs and persisted evaluation artifacts.
3. The inference pipeline is explicitly three-stage:
- Stage 1: pipeline/stage1_detection.py runs YOLO-based license plate detection.
- Stage 2: pipeline/stage2_enhancement.py applies OpenCV preprocessing to produce OCR-friendly plate crops/candidates.
- Stage 3: pipeline/stage3_ocr.py uses PaddleOCR to read text and then normalizes it toward the Tamil Nadu plate pattern.
Data flows left-to-right through these stages: image input → detected plate region → enhanced candidates → recognized text.
4. anpr_tn/config.py is the central coordination point for filesystem paths, thresholds, and shared constants. Architecturally, it decouples the pipeline stages from hardcoded locations such as model files, datasets, evaluation metadata, and output directories.
5. Model assets are kept under anpr_tn/models/. The tree includes yolo_best.pt and yolov8n.pt, indicating the detector is based on Ultralytics YOLO weights. Detection is therefore a pretrained-model boundary, while OCR is handled by a separate external engine rather than being trained in this repo.
6. Training is isolated from inference in anpr_tn/training/. training/train.py and training/data.yaml define the detector training workflow, which consumes the YOLO-formatted dataset under datasets/indian_lpr_yolo/. This is a separate subsystem whose output is a detector checkpoint used by the runtime pipeline.
7. The dataset layout follows standard YOLO conventions: images and labels are separated into train and val partitions, with label cache files present. This indicates the training boundary expects object-detection annotations rather than OCR labels, reinforcing that the learned model is only for plate localization.
8. Evaluation inputs live under metadata/tamil_nadu_eval/, and the corresponding ground truth is stored in metadata/ground_truth.csv. The main runtime likely joins detector/OCR outputs with this ground truth to compute or record performance. This makes metadata/ the evaluation contract for the pipeline.
9. Generated artifacts are written into results/, which is subdivided into crops/, detections/, and enhanced/, plus a logs.csv. That structure mirrors the three pipeline stages and is useful for diagramming where intermediate products are persisted between processing and evaluation.
10. The external technology boundaries are important: Python is the runtime, Ultralytics YOLO handles detection, OpenCV handles image enhancement, and PaddleOCR handles text recognition. The repository’s architecture is therefore a staged CV pipeline with a trained detector, deterministic preprocessing, and OCR-based text extraction, all coordinated by a thin orchestration layer in main.py.
Main entry points: results Results · main.py Main · stage1_detection.py Detect · stage2_enhancement.py Enhance
Components 17
Runtime
Inference, orchestration, and shared configuration
- Main · Entry point for single-image inference and batch evaluation; writes results and compares against ground truth
anpr_tn/main.py - Config · Central filesystem, threshold, and constant coordination for the package
anpr_tn/config.py - Detect · Stage 1 license-plate detection using Ultralytics YOLO weights
anpr_tn/pipeline/stage1_detection.py - Enhance · Stage 2 plate crop preprocessing and candidate enhancement
anpr_tn/pipeline/stage2_enhancement.py - OCR · Stage 3 text recognition and Tamil Nadu plate normalization
anpr_tn/pipeline/stage3_ocr.py
Training
Detector training workflow and YOLO dataset
- Train · Detector training entrypoint for the plate-localization model
anpr_tn/training/train.py - Data YAML · YOLO dataset configuration for training and validation splits
anpr_tn/training/data.yaml - YOLO Dataset · Train/val images and labels in YOLO detection format
anpr_tn/datasets/indian_lpr_yolo
Data & Artifacts
Evaluation metadata, model weights, and generated outputs
- YOLO Weights · Detector model assets used at runtime
anpr_tn/models/yolo_best.pt - Base Weights · Additional YOLO weight file present in the repo
anpr_tn/models/yolov8n.pt - Eval Set · Prepared evaluation image set used by the runtime pipeline
anpr_tn/metadata/tamil_nadu_eval - Ground Truth · CSV ground truth used for comparison and reporting
anpr_tn/metadata/ground_truth.csv - Results · Persisted detections, crops, enhanced images, and logs
anpr_tn/results - Crops · Saved plate-region crops from detection
anpr_tn/results/crops - Detections · Saved detection outputs and summaries
anpr_tn/results/detections - Enhanced · Saved OCR-friendly intermediate images
anpr_tn/results/enhanced - Logs · Run logs and evaluation records
anpr_tn/results/logs.csv
Connections 18
- Main → Config: reads paths · Main uses shared configuration for inputs, outputs, and thresholds
- Main → Detect: runs stage 1 · Main invokes the detection stage on each image
- Detect → YOLO Weights: loads model · Detection stage uses trained YOLO weights
- Detect → Enhance: crops plates · Detected plate regions are passed to preprocessing
- Enhance → OCR: feeds candidates · Enhanced plate crops are sent to OCR
- OCR → Results: writes output · Recognized text and normalized predictions are persisted
- Detect → Results: writes detections · Detection outputs are saved for inspection and evaluation
- Enhance → Results: writes crops · Preprocessed intermediate images are saved
- Results → Crops: contains · Crops are stored under the results directory
- Results → Detections: contains · Detection records are stored under the results directory
- Results → Enhanced: contains · Enhanced intermediates are stored under the results directory
- Results → Logs: contains · Run logs are stored alongside outputs
- Main → Eval Set: evaluates on · Batch evaluation reads prepared evaluation images
- Main → Ground Truth: compares with · Evaluation joins predictions against ground truth
- Train → Data YAML: uses config · Training is driven by YOLO dataset configuration
- Data YAML → YOLO Dataset: points to · Training config references the annotated dataset
- Train → YOLO Weights: produces · Training outputs the detector checkpoint used by runtime
- Base Weights → Train: initializes · Additional YOLO weights are present for training or baseline use