# mr-aicoder/automatic-number-plate-detection-system architecture

> Architecture diagram of the GitHub repository mr-aicoder/automatic-number-plate-detection-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mr-aicoder/automatic-number-plate-detection-system
- Repository: https://github.com/mr-aicoder/automatic-number-plate-detection-system

## Overview

##### Project Type and Purpose
- Type: A real-time computer-vision pipeline implemented in Python.

##### File Structure
Top level files:
- main.py (entry point for detection & tracking)
- add_missing_data.py (post-processing/interpolation)
- util.py (OCR, formatting, CSV export helpers)
- yolov8n.pt & license_plate_detector.pt (pretrained YOLOv8 models)
- requirements.txt (dependencies)
Patterns:
– A linear pipeline: Model loading → frame processing → detection → OCR → storage → visualization
– Separation of concerns across scripts (main vs. utils vs. post-processing vs. visualization)

##### Extract Insights from README.md
- Core steps: model loading, video reading, vehicle detection+tracking (SORT), plate detection, OCR (EasyOCR), result storage (CSV), missing-data interpolation, visualization.
- Dependencies: Ultralytics YOLOv8, SORT (external repo), EasyOCR, OpenCV, pandas/csv.

##### Main System Components
A. Input Module
– Video Reader (OpenCV VideoCapture)
B. Detection & Tracking
– Vehicle Detector (YOLOv8 pretrained `yolov8n.pt`)
– SORT Tracker (external module)
C. Plate Detection
– License Plate Detector (YOLOv8 `license_plate_detector.pt`)
D. OCR & Formatting
– OCR Engine (EasyOCR in util.py)
– Plate Text Formatter (util.py helpers)
E. Data Storage
– CSV Logger (pandas or csv writer in util.py)
F. Post-Processing
– Data Interpolator (add_missing_data.py)
G. Visualization

##### Component Interactions
1. Video Source → Video Reader
5. Plate crops → OCR → text
6. Combine (frame#, vehicleID, coords, text) → CSV Logger
7. Once base CSV is written → add_missing_data.py interpolates gaps → new CSV

##### Architectural Patterns & Design Principles
- Pipeline / staged processing: Each script is a stage.
- Modularity & separation of concerns: detection, tracking, OCR, storage, visualization are decoupled.
- Reusability: util.py functions are shared; models loaded once.
- Batch vs. streaming: main.py handles streaming frames in real time.

##### Putting It All Together
[Video Source]
↓
[Video Reader]
↓
[YOLOv8 Vehicle Detector] ──→ [SORT Tracker]
↓                           │
[License Plate Detector]        ↓
↓                    [util.py → CSV Logger]
[EasyOCR Engine]                ↓
↓                    [add_missing_data.py]
[Data Formatter]                ↓
[CSV File] ─────────────────────→ [Output Video]

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Inference Layer
    subgraph "Inference Layer"
        VS["Video Source\n(Pexels URL)"]:::external
        VR["Video Reader\n(OpenCV VideoCapture)"]:::inference
        VD["YOLOv8 Vehicle Detector\n(yolov8n.pt)"]:::inference
        ST["SORT Tracker"]:::tracking
        PD["License Plate Detector\n(license_plate_detector.pt)"]:::inference
        OCR["EasyOCR Engine"]:::inference
        TF["Plate Text Formatter"]:::inference
    end

    %% Post-Processing
    subgraph "Post-Processing & Storage"
        CL["CSV File"]:::storage
        DI["Data Interpolator\n(add_missing_data.py)"]:::tracking
    end

    %% Visualization
    subgraph "Visualization"
        AN["Annotator & Video Writer\n(visualize.py)"]:::viz
        OV["Output Video"]:::viz
    end

    %% Dependencies
    RM["requirements.txt"]:::external

    %% Flow
    VS --> VR
    VR --> VD
    VD --> ST
    ST --> PD
    PD --> OCR
    OCR --> TF
    TF --> CL
    CL --> DI
    DI --> AN
    AN --> OV
    RM -.-> VR

    %% Click Events
    click VR "https://github.com/mr-aicoder/automatic-number-plate-detection-system/blob/main/main.py"
    click VD "https://github.com/mr-aicoder/automatic-number-plate-detection-system/blob/main/main.py"
    click ST "https://github.com/mr-aicoder/automatic-number-plate-detection-system/blob/main/main.py"
    click PD "https://github.com/mr-aicoder/automatic-number-plate-detection-system/blob/main/main.py"
    click OCR "https://github.com/mr-aicoder/automatic-number-plate-detection-system/blob/main/util.py"
    click TF "https://github.com/mr-aicoder/automatic-number-plate-detection-system/blob/main/util.py"
    click CL "https://github.com/mr-aicoder/automatic-number-plate-detection-system/blob/main/util.py"
    click DI "https://github.com/mr-aicoder/automatic-number-plate-detection-system/blob/main/add_missing_data.py"
    click AN "https://github.com/mr-aicoder/automatic-number-plate-detection-system/blob/main/visualize.py"
    click RM "https://github.com/mr-aicoder/automatic-number-plate-detection-system/blob/main/requirements.txt"

    %% Styles
    classDef inference fill:#D0E8FF,stroke:#0066CC,stroke-width:2px;
    classDef tracking fill:#FFF0D0,stroke:#CC6600,stroke-width:2px;
    classDef storage fill:#E0E0E0,stroke:#666666,stroke-width:2px,stroke-dasharray: 5 5;
    classDef viz fill:#DFF2D8,stroke:#339933,stroke-width:2px;
    classDef external fill:#F0D0F0,stroke:#993399,stroke-width:2px,stroke-dasharray: 2 2;
```
