# mohinik7/automatic-number-plate-recognition-python-yolov8 architecture

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

- Interactive diagram: https://gitdiagram.com/mohinik7/automatic-number-plate-recognition-python-yolov8
- Repository: https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8

## Overview

##### Project type and purpose
- This is an open-source, Python-based Automatic Number Plate Recognition (ANPR) system.
- Its primary function is a real-time video-processing pipeline that:
- Detects vehicles and license plates via YOLOv8
- Runs OCR (EasyOCR) on detected plates
- Validates and matches plate text against a SQLite “stolen vehicles” database
- Emits alerts, saves annotated frames, and logs detections
- It also provides CLI tools for database management (add/update/search/list) and for resetting/importing data.

##### File structure
- Top-level scripts form two logical groups:
a. Core detection pipeline
- main.py (orchestrates video input → detection → OCR → DB matching → output)
- add_missing_data.py, database_utils.py, reset_database.py (DB init/import/reset)
- util.py (plate-format validation, OCR error correction)
- stolen_vehicles.csv, test.csv (sample data)
- requirements.txt, LICENSE, .gitignore
b. CLI management
- manage_vehicles.py (add/list/update/search vehicles & detections)
c. Tests
- test_db_detection.py
- README also references these directories (models/, output/, sort/) where:
- models/ holds YOLOv8 weights
- sort/ contains the SORT tracker code
- output/ stores annotated frames & detection logs

##### README for additional insights
- The README outlines the 7-step pipeline (vehicle detection → plate detection → OCR → format validation → DB matching → alerting → tracking).
- It lists dependencies: Python 3.8+, Ultralytics YOLOv8, EasyOCR, SORT, SQLite.
- It highlights database-centric design and command-line extensibility.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Pipeline
    subgraph "Video Processing Pipeline"
        direction TB
        VideoInput["Video Input\n(file or stream)"]:::pipeline
        Preprocessing["Preprocessing Module\n(frame extraction, resizing)"]:::pipeline
        subgraph "Detection Engine"
            direction TB
            VehicleDet["YOLOv8 Vehicle Detector"]:::ml
            PlateDet["YOLOv8 Plate Detector"]:::ml
            OCR["OCR Module\n(EasyOCR)"]:::ml
            Validation["Plate Validation & Correction"]:::pipeline
        end
    end

    %% Services & Storage
    subgraph "Services & Storage"
        direction TB
        Tracking["Tracking Service\n(SORT)"]:::ml
        Alert["Alert & Logging Service\n(console alerts, annotated frames, CSV logs)"]:::logging
        AnnotatedOutput["Annotated Frames & Logs\n(output/)"]:::logging
        Database["SQLite Database"]:::db
    end

    %% Database Management
    subgraph "Database Management"
        direction TB
        DBLayer["Database Layer\n(CRUD & matching)"]:::db
        InitImport["DB Init & Import\n(add_missing_data.py, reset_database.py)"]:::db
    end

    %% CLI Interface
    CLI["CLI Management Interface\n(add/list/update/search)"]:::cli

    %% Sample Data & Dependencies
    subgraph "Artifacts & Config"
        direction TB
        SampleData["Sample Data Files\n(stolen_vehicles.csv, test.csv)"]:::data
        Requirements["Dependency Manifest\n(requirements.txt)"]:::data
    end

    %% Data Flow
    VideoInput -->|frames| Preprocessing
    Preprocessing -->|preprocessed frames| VehicleDet
    VehicleDet -->|vehicle bboxes| PlateDet
    PlateDet -->|plate bboxes| OCR
    OCR -->|OCR text| Validation
    Validation -->|validated plates| DBLayer
    DBLayer -->|SQL queries| Database
    Database -->|match results| DBLayer
    DBLayer -->|alerts| Alert
    DBLayer -->|logs| AnnotatedOutput

    VehicleDet <-->|tracking IDs| Tracking
    Tracking -->|tracked vehicles| Alert

    CLI <-->|CRUD ops| DBLayer

    InitImport -->|initial data| Database
    SampleData -->|import| InitImport

    %% Click Events
    click VideoInput "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/main.py"
    click Preprocessing "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/main.py"
    click VehicleDet "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/main.py"
    click PlateDet "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/main.py"
    click OCR "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/main.py"
    click Validation "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/util.py"
    click DBLayer "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/database_utils.py"
    click InitImport "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/add_missing_data.py"
    click InitImport "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/reset_database.py"
    click CLI "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/manage_vehicles.py"
    click Alert "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/visualize.py"
    click SampleData "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/stolen_vehicles.csv"
    click SampleData "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/test.csv"
    click Requirements "https://github.com/mohinik7/automatic-number-plate-recognition-python-yolov8/blob/main/requirements.txt"

    %% Styles
    classDef ml fill:#E0F7FA,stroke:#006064,color:#006064
    classDef pipeline fill:#E3F2FD,stroke:#1E88E5,color:#1E88E5
    classDef db fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32
    classDef cli fill:#C8E6C9,stroke:#388E3C,color:#388E3C
    classDef logging fill:#FFF3E0,stroke:#EF6C00,color:#E65100
    classDef data fill:#F3E5F5,stroke:#6A1B9A,color:#6A1B9A
```
