# 1hemmem/algerian-license-plates-recegnition-system architecture

> Architecture diagram of the GitHub repository 1hemmem/algerian-license-plates-recegnition-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/1hemmem/algerian-license-plates-recegnition-system
- Repository: https://github.com/1hemmem/algerian-license-plates-recegnition-system

## Overview

##### Project type and purpose
- This is a specialized data-processing pipeline written in Python for end-to-end license-plate recognition on video streams.
- It ingests a video, detects cars and license plates per frame (YOLO), tracks objects across frames (DeepSORT), selects the best plate images, runs OCR on them, and persists results (images, text, timestamps).

##### File structure
- Top-level:
- README.md – project overview and usage
- models/ – saved YOLO model weights (best.pt, yolov10n.pt)
- src/requirements.txt – Python dependencies
- src/prod/ – production pipeline
- app.py – entry point, orchestrates the pipeline
- Filter.py – logic to discard duplicate detections, keep best frame
- GeminiOcr.py – wrapper around OCR engine
- Utils.py – shared utilities (e.g., frame I/O, timestamping)
- src/train/ – training pipeline (data splitting, formatting, training scripts)

##### Key insights from README
- The emphasis on:
- Object detection (YOLO) without duplicate suppression
- Object tracking & re-identification (DeepSORT) to handle repeated detections
- Frame quality assessment to feed OCR the clearest plate image
- No frontend/UI – this is purely a back-end processing service.

##### Main components
a. Video Input Module
- Reads video frames from file or stream
b. Frame Extraction & Preprocessing
- Optional resizing, normalization (in Utils)
c. Object Detection Service
- YOLO model (models/*.pt)
d. Object Tracking Service
- DeepSORT tracker instance (manages object IDs across frames)
e. Duplicate Filter / Best-Frame Selector
- Filter.py: logic to decide which frame(s) to OCR per tracked object
f. OCR Engine
- GeminiOcr.py: calls OCR library (local or external service)
g. Persistence Layer
- Stores:
- Cropped plate images (file system or blob storage)
- Full-car images
- Extracted text + timestamp (could be a database or CSV)
h. Training Subsystem (side-by-side)

##### Relationships & data flow
Video Input → Frame Extraction → Detection → Tracking → Duplicate Filtering → OCR → Persistence

##### Architectural patterns & principles
- Modular pipeline: each step is a distinct module/service
- OOP design: each component encapsulated in a class or module
- Separation of concerns: detection, tracking, filtering, OCR, and storage are decoupled

##### Detail level
- Don’t just show “ML module” – break it into YOLO Detector + DeepSORT Tracker + Filter + OCR

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Production Inference Pipeline
    subgraph "Production Inference Pipeline"
        direction TB
        VideoInput["Video Input Module"]:::inference
        Preprocessing["Frame Extraction & Preprocessing"]:::utility
        Detection["Object Detection Service\n(YOLO Detector)"]:::inference
        Tracking["Object Tracking Service\n(DeepSORT Tracker)"]:::inference
        Filter["Duplicate Filter / Best-Frame Selector"]:::utility
        OCR["OCR Engine"]:::inference
        Persistence["Persistence Layer\n(Images, Text, Timestamps)"]:::datastore
        subgraph "Model Registry" 
            direction TB
            BestPT["best.pt"]:::datastore
            Yolov10["yolov10n.pt"]:::datastore
        end
    end

    %% Training Pipeline
    subgraph "Training Pipeline" 
        direction TB
        DataSplit["DataSplit.py"]:::training
        YoloFormatter["Yolo_file_formatter.py"]:::training
        TrainScript["train.py"]:::training
    end

    %% Data Flow
    VideoInput -->|frames| Preprocessing
    Preprocessing -->|normalized frames| Detection
    Detection -->|bounding boxes| Tracking
    Tracking -->|tracked objects| Filter
    Filter -->|best plate images| OCR
    OCR -->|text & plate images| Persistence
    Persistence -->|new data| DataSplit
    DataSplit --> YoloFormatter
    YoloFormatter --> TrainScript
    TrainScript -->|updated models| BestPT
    TrainScript -->|updated models| Yolov10

    %% Click Events
    click VideoInput "https://github.com/1hemmem/algerian-license-plates-recegnition-system/blob/main/src/prod/app.py"
    click Preprocessing "https://github.com/1hemmem/algerian-license-plates-recegnition-system/blob/main/src/prod/Utils.py"
    click Detection "https://github.com/1hemmem/algerian-license-plates-recegnition-system/blob/main/models/best.pt"
    click Detection "https://github.com/1hemmem/algerian-license-plates-recegnition-system/blob/main/models/yolov10n.pt"
    click Tracking "https://github.com/1hemmem/algerian-license-plates-recegnition-system/blob/main/src/prod/app.py"
    click Filter "https://github.com/1hemmem/algerian-license-plates-recegnition-system/blob/main/src/prod/Filter.py"
    click OCR "https://github.com/1hemmem/algerian-license-plates-recegnition-system/blob/main/src/prod/GeminiOcr.py"
    click Persistence "https://github.com/1hemmem/algerian-license-plates-recegnition-system/blob/main/src/prod/Utils.py"
    click DataSplit "https://github.com/1hemmem/algerian-license-plates-recegnition-system/blob/main/src/train/DataSplit.py"
    click YoloFormatter "https://github.com/1hemmem/algerian-license-plates-recegnition-system/blob/main/src/train/Yolo_file_formatter.py"
    click TrainScript "https://github.com/1hemmem/algerian-license-plates-recegnition-system/blob/main/src/train/train.py"

    %% Styles
    classDef inference fill:#add8e6,stroke:#000
    classDef datastore fill:#98fb98,stroke:#000
    classDef utility fill:#ffa500,stroke:#000
    classDef training fill:#fffacd,stroke:#000,stroke-dasharray:5 5
```
