# mftnakrsu/automatic_number_plate_recognition_yolo_ocr architecture

> Architecture diagram of the GitHub repository mftnakrsu/automatic_number_plate_recognition_yolo_ocr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr
- Repository: https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr

## Overview

##### Main Components Identification
- Detection Module:
- Contains the YOLO models in the "models" directory, as well as configuration files (YAML files in data/hyps and models/hub) and pretrained weights in the "model" directory.
- The detection workflow is primarily invoked via main.py (or app.py) which calls the YOLOv5-based object detection routines.
- OCR Module:
- Found in the "ai" directory with files like ai_model.py and ocr_model.py. These files handle the OCR operations using EasyOCR and PaddleOCR.
- Data Management:
- CSV and database operations are handled (e.g., writing to ocr_results.csv) and possibly invoking helper functions found under "helper" and "utils" directories.
- The project also maintains configuration files and dataset YAML’s within the "data" directory.
- Web/API Frontend:
- The Flask-related integration is hinted at by app.py, the "templates" directory (index.html), and the "static" directory (style.css).
- Additional REST API components are available in "utils/flask_rest_api" for exposing endpoints.
- Utilities & Auxiliary Components:
- A range of utility modules (such as general utilities, augmentations, docker-related files, logging, and Google App Engine support) organize auxiliary functionalities.

##### Relationship and Interactions
- The flow begins with image input processing. Input images (or video feed) are received by the main entry point (main.py or app.py).
- The Detection Module (YOLO-based) locates the license plate and crops the image accordingly.
- The cropped image is passed to the OCR Module, which employs OCR techniques to extract and recognize the textual content.
- Detected text is then filtered and sanitized, with outcomes written into a CSV/database (see output files like ocr_results.csv).
- The results are served and possibly visualized via the Flask web interface (using templates and static assets).

##### Architectural Patterns and Design Principles
- Separation of Concerns: Each module (detection, OCR, API/Frontend, utilities) operates largely independently.
- Pipeline Architecture: A clear sequential flow—from image detection through OCR to final presentation—ensures modularity.
- Reusability and Extensibility: The presence of multiple utility modules (in “utils” and “helper”) indicates a design that encourages reusable code blocks and easy integration with external services (like AWS or Google App Engine).

##### Relevant Technologies, Frameworks, and Libraries
- YOLOv5 and related custom object detection code (models common/experimental, etc.).
- OCR libraries, specifically EasyOCR and PaddleOCR.
- Flask for the web interface.
- Python-based utility modules handling tasks such as logging, Docker containerization, and dataset management.
- Configuration and hyperparameter YAML files for model tuning.

##### Elements
- Each component (Detection Module, OCR Module, Data Management, and Web/API Layer) should be clearly labeled.
- Annotations to reference relevant configuration and dataset directories (e.g., “data” for YAML configuration, “models/hub” for model architectures).

d. Next, indicate two parallel processes (or a fork) representing “EasyOCR” and “PaddleOCR”; these can be represented as two contained modules in the “OCR Module”.
e. Merge these results into a “Text Filtering & Post Processing” block.
f. Then, funnel the final recognized text to “Data Storage” (CSV/Database) and mark this as the persistent output.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global nodes
    Input["Image/Video Input"]:::input

    %% Detection Module Subgraph
    subgraph "Detection Module"
        DetectionEntry["Detection Entry"]:::detection
        ModelsConfig["Models and Configurations"]:::detection
        Weights["Pretrained Weights"]:::detection
    end

    %% Plate Cropping/Preprocessing Node
    PlateCropping["Plate Cropping/Preprocessing"]:::processing

    %% OCR Module Subgraph
    subgraph "OCR Module"
        EasyOCR["EasyOCR"]:::ocr
        PaddleOCR["PaddleOCR"]:::ocr
    end

    %% Text Filtering & Post Processing Node
    TextFilter["Text Filtering & Post Processing"]:::processing

    %% Data Management Subgraph
    subgraph "Data Management"
        CSVStorage["Data Storage (CSV/DB)"]:::data
        HelperFuncs["Helper Functions"]:::data
        Configurations["Configurations & Datasets"]:::data
    end

    %% Web/API Frontend Subgraph
    subgraph "Web/API Frontend"
        FlaskApp["Flask Web Interface"]:::web
        HTMLTemplates["HTML Templates"]:::web
        StaticAssets["Static Assets"]:::web
        RESTAPI["REST API Endpoints"]:::web
    end

    %% Utilities & Auxiliary Subgraph (Side Component)
    subgraph "Utilities & Auxiliary"
        GenUtils["General Utilities"]:::util
        DockerCloud["Docker/Cloud Support"]:::util
        Logging["Logging"]:::util
        Metrics["Metrics"]:::util
    end

    %% Flow Connections
    Input -->|"start"| DetectionEntry
    DetectionEntry -->|"invokes"| PlateCropping
    PlateCropping -->|"passes image"| EasyOCR
    PlateCropping -->|"passes image"| PaddleOCR
    EasyOCR -->|"outputs OCR"| TextFilter
    PaddleOCR -->|"outputs OCR"| TextFilter
    TextFilter -->|"stores result"| CSVStorage
    CSVStorage -->|"feeds data"| FlaskApp

    %% Auxiliary dashed connections (supporting roles)
    GenUtils ---|"supports"| DetectionEntry
    Logging ---|"aids"| HelperFuncs
    DockerCloud ---|"assists"| FlaskApp
    Metrics ---|"monitors"| RESTAPI

    %% Click Events for Detection Module
    click DetectionEntry "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/blob/main/main.py"
    click ModelsConfig "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/tree/main/models/"
    click Weights "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/tree/main/model/"

    %% Click Events for OCR Module
    click EasyOCR "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/blob/main/ai/ocr_model.py"
    click PaddleOCR "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/blob/main/ai/ai_model.py"

    %% Click Events for Data Management
    click CSVStorage "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/blob/main/ocr_results.csv"
    click HelperFuncs "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/tree/main/helper/"
    click Configurations "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/tree/main/data/"

    %% Click Events for Web/API Frontend
    click FlaskApp "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/blob/main/app.py"
    click HTMLTemplates "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/blob/main/templates/index.html"
    click StaticAssets "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/blob/main/static/style.css"
    click RESTAPI "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/tree/main/utils/flask_rest_api/"

    %% Click Events for Utilities & Auxiliary
    click GenUtils "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/tree/main/utils/"
    click DockerCloud "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/tree/main/utils/docker/"
    click Logging "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/tree/main/utils/loggers/"
    click Metrics "https://github.com/mftnakrsu/automatic_number_plate_recognition_yolo_ocr/blob/main/utils/metrics.py"

    %% Class definitions for styling
    classDef input fill:#f4f4f4,stroke:#333,stroke-width:2px;
    classDef detection fill:#cce5ff,stroke:#339,stroke-width:2px;
    classDef processing fill:#e6ffe6,stroke:#393,stroke-width:2px;
    classDef ocr fill:#d1e7dd,stroke:#2a6,stroke-width:2px;
    classDef data fill:#fff3cd,stroke:#cc9,stroke-width:2px;
    classDef web fill:#f8d7da,stroke:#d33,stroke-width:2px;
    classDef util fill:#e2e3e5,stroke:#aaa,stroke-dasharray: 5 5,stroke-width:2px;
```
