# sampath123123/automatic-number-plate-recognition architecture

> Architecture diagram of the GitHub repository sampath123123/automatic-number-plate-recognition, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sampath123123/automatic-number-plate-recognition
- Repository: https://github.com/sampath123123/automatic-number-plate-recognition

## Overview

This repository is a video-based automatic licence-plate recognition and vehicle-speed application. Its main workflow reads camera, RTSP, or file frames; detects vehicles; tracks them across frames; detects plates within vehicle crops; recognizes and confidence-votes plate text; then emits one record per vehicle when its track expires. A separate calibration tool builds a view-specific road ruler used for speed estimates. The excerpts show the main orchestration and core algorithms; optional display, recording, and saved plate crops are documented in the README.

Main entry points: [`alpr.py`](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/alpr.py) (ALPR runner), [`road_ruler.py`](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/road_ruler.py) (Road ruler), [`speed_estimator.py`](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/speed_estimator.py) (Speed estimator), [`road_calib.json`](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/road_calib.json) (Road ruler data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pipeline["Frame pipeline"]
  node_alpr["ALPR runner<br/>[alpr.py]"]
  node_annotated_video["Annotated video"]
  node_display["Live display"]
end

subgraph group_recognition["Detection and OCR"]
  node_vehicle_detector["Vehicle detector<br/>[detectors.py]"]
  node_plate_detector["Plate detector<br/>[detectors.py]"]
  node_ocr["Plate OCR<br/>[ppocr_rec.py]"]
end

subgraph group_records["Tracking and output"]
  node_tracker["IoU tracker<br/>[tracker.py]"]
  node_vehicle_record["Vehicle vote record<br/>[alpr.py]"]
  node_csv["Detection CSV"]
  node_plate_images["Saved plate crops"]
end

subgraph group_speed["Speed calibration"]
  node_calibrator["Road calibration<br/>[calibrate_road.py]"]
  node_calibration["Road ruler data<br/>[road_calib.json]"]
  node_ruler["Road ruler<br/>[road_ruler.py]"]
  node_speed_estimator["Speed estimator<br/>[speed_estimator.py]"]
end

node_source(("Camera or video"))

node_source -->|"provides frames"| node_alpr
node_alpr -->|"detects vehicles"| node_vehicle_detector
node_alpr -->|"updates tracks"| node_tracker
node_alpr -->|"detects on crops"| node_plate_detector
node_alpr -->|"reads plate crops"| node_ocr
node_alpr -->|"accumulates readings"| node_vehicle_record
node_vehicle_record -->|"writes on exit"| node_csv
node_vehicle_record -->|"saves best crop"| node_plate_images
node_alpr -->|"records frames"| node_annotated_video
node_alpr -->|"shows frames"| node_display
node_calibrator -->|"writes ruler data"| node_calibration
node_calibration -->|"loads calibration"| node_ruler
node_alpr -->|"loads calibration"| node_ruler
node_alpr -->|"adds road samples"| node_speed_estimator
node_ruler -->|"converts row to distance"| node_speed_estimator
node_speed_estimator -->|"supplies speed"| node_vehicle_record

click node_alpr "https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/alpr.py"
click node_vehicle_detector "https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/detectors.py"
click node_plate_detector "https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/detectors.py"
click node_ocr "https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/ppocr_rec.py"
click node_tracker "https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/tracker.py"
click node_vehicle_record "https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/alpr.py"
click node_calibrator "https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/calibrate_road.py"
click node_calibration "https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/road_calib.json"
click node_ruler "https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/road_ruler.py"
click node_speed_estimator "https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/speed_estimator.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_alpr,node_annotated_video,node_display toneBlue
class node_vehicle_detector,node_plate_detector,node_ocr toneAmber
class node_tracker,node_vehicle_record,node_csv,node_plate_images toneMint
class node_calibrator,node_calibration,node_ruler,node_speed_estimator toneRose
class node_source toneIndigo
```

## Components

### Frame pipeline

- [ALPR runner](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/alpr.py): `alpr.py`
- **Annotated video**
- **Live display**

### Detection and OCR

- [Vehicle detector](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/detectors.py): `detectors.py`
- [Plate detector](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/detectors.py): `detectors.py`
- [Plate OCR](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/ppocr_rec.py): `ppocr_rec.py`

### Tracking and output

- [IoU tracker](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/tracker.py): `tracker.py`
- [Vehicle vote record](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/alpr.py): `alpr.py`
- **Detection CSV**
- **Saved plate crops**

### Speed calibration

- [Road calibration](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/calibrate_road.py): `calibrate_road.py`
- [Road ruler data](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/road_calib.json): `road_calib.json`
- [Road ruler](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/road_ruler.py): `road_ruler.py`
- [Speed estimator](https://github.com/sampath123123/automatic-number-plate-recognition/blob/main/speed_estimator.py): `speed_estimator.py`

### Other components

- **Camera or video**

## Connections

- Camera or video → ALPR runner: provides frames (evidence: `README.md`)
- ALPR runner → Vehicle detector: detects vehicles (evidence: `alpr.py`)
- ALPR runner → IoU tracker: updates tracks (evidence: `alpr.py`)
- ALPR runner → Plate detector: detects on crops (evidence: `README.md`)
- ALPR runner → Plate OCR: reads plate crops (evidence: `README.md`)
- ALPR runner → Vehicle vote record: accumulates readings (evidence: `alpr.py`)
- Vehicle vote record → Detection CSV: writes on exit (evidence: `alpr.py`)
- Vehicle vote record → Saved plate crops: saves best crop (evidence: `alpr.py`)
- ALPR runner → Annotated video: records frames (evidence: `README.md`)
- ALPR runner → Live display: shows frames (evidence: `README.md`)
- Road calibration → Road ruler data: writes ruler data (evidence: `calibrate_road.py`)
- Road ruler data → Road ruler: loads calibration (evidence: `road_ruler.py`)
- ALPR runner → Road ruler: loads calibration (evidence: `alpr.py`)
- ALPR runner → Speed estimator: adds road samples (evidence: `alpr.py`)
- Road ruler → Speed estimator: converts row to distance (evidence: `README.md`)
- Speed estimator → Vehicle vote record: supplies speed (evidence: `alpr.py`)
