# manojbaniya444/minor-project-bct-iii-ii architecture

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

- Interactive diagram: https://gitdiagram.com/manojbaniya444/minor-project-bct-iii-ii
- Repository: https://github.com/manojbaniya444/minor-project-bct-iii-ii

## Overview

##### Project Type and Purpose
- This is a standalone, desktop-based computer vision/ML application (written in Python) that:
- Captures video or images via OpenCV
- Runs a YOLOv8 model for license-plate detection
- Performs character segmentation
- Classifies characters with a TensorFlow CNN
- Records results in a local SQLite database
- Presents a GUI front end with Tkinter

##### File Structure
- Top-level directories “ANPR FINAL” (production code) and “ANPR TEST” (development/test sandbox) each contain:
- app.py − application entry point and UI launcher
- actions.py / backup_actions.py − business-logic wrappers
- yolo_detect.py / yolo_predict.py − YOLO inference modules (using PyTorch)
- segment.py − plate-region segmentation routines
- classify.py / classify_class.py − character-classification logic (TensorFlow saved model)
- db.py − SQLite read/write layer (lpr.db)
- utils.py − shared helper functions
- images/ − sample inputs
- trained_models/ − YOLO weights (best.pt) and TF SavedModel artifacts

##### Extract Additional Architectural Insights from README
- Workflow description:
1. Video capture → YOLOv8 object detection
2. ROI extraction & plate cropping
3. Image transforms & contour-based character segmentation
4. CNN-based character classification (17 Nepali classes)
5. Persistence to SQLite via db.py
6. Real-time UI updates in Tkinter

##### Main Components
a. User Interface Layer
- Tkinter GUI (app.py)
- Displays video feed, detections, character outputs, status
b. Data Acquisition Layer
- OpenCV VideoCapture module (inside app.py or actions.py)
- Optionally file/image loader (images/ folder)
c. Detection Module
- YOLOv8 inference (yolo_detect.py / yolo_predict.py)
d. Segmentation Module
- segment.py
- Steps: perspective transform, cleaning, contour detection, character ROI isolation
e. Classification Module
- classify.py / classify_class.py
- TensorFlow SavedModel under trained_models/classification_model
- Outputs: character labels
f. Persistence Layer
- SQLite DB (lpr.db) via db.py
- Tables: plate metadata, character sequences, timestamps
g. Utility Layer
- utils.py for logging, image I/O, config parsing

##### Relationships and Data Flows
User → GUI → Video Stream → Detector → Plate ROI → Segmenter → Character ROIs → Classifier → Result → DB → GUI update
- Utils.py as a side component supplying helpers to all modules
- Bidirectional link between app.py (controller) and each module script

##### Architectural Patterns
- Pipeline pattern: each stage (capture, detect, segment, classify) forms a pipeline
- Modular code organization: separation of concerns (detection vs segmentation vs classification vs DB)
- MVC-like layering:
- Model: trained_models + db.py
- View: Tkinter GUI
- Controller: actions.py / app.py

##### Technologies and Frameworks
- GUI: Python Tkinter
- CV: OpenCV
- Detection: PyTorch + YOLOv8 (best.pt)
- Classification: TensorFlow SavedModel
- Storage: SQLite
- Scripting: Python 3.x (scripts in ANPR FINAL/*.py)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface Layer"
        App["Tkinter GUI"]:::ui
    end

    subgraph "Controller Layer"
        Act["actions.py"]:::controller
        Back["backup_actions.py"]:::controller
    end

    subgraph "Data Acquisition Layer"
        Vid["VideoCapture"]:::cv
        Images["Sample Images Folder"]:::data
    end

    subgraph "Detection Module"
        YD["yolo_detect.py"]:::ml
        YP["yolo_predict.py"]:::ml
        WP["YOLOv8 Weights (best.pt)"]:::model
    end

    subgraph "Segmentation Module"
        Seg["segment.py"]:::ml
    end

    subgraph "Classification Module"
        C1["classify.py"]:::ml
        C2["classify_class.py"]:::ml
        SM["SavedModel Artifacts (classification_model/)"]:::model
    end

    subgraph "Persistence Layer"
        DBi["db.py"]:::db
        DBf[(lpr.db)]:::db
    end

    Utils["utils.py"]:::util

    App --> Act
    App --> Back
    Act --> Vid
    Act --> YD
    Act --> YP
    Vid -->|"Frame"| YD
    YD -->|"Bounding Boxes"| Seg
    Seg -->|"Cropped Plates"| C1
    Seg -->|"Character ROIs"| C2
    C1 -->|"Character Labels"| DBi
    C2 -->|"Character Labels"| DBi
    DBi -->|"Persisted Results"| DBf
    DBf -->|"Data Update"| App

    Utils -.-> App
    Utils -.-> Act
    Utils -.-> Vid
    Utils -.-> YD
    Utils -.-> Seg
    Utils -.-> C1
    Utils -.-> DBi

    click App "https://github.com/manojbaniya444/minor-project-bct-iii-ii/blob/main/ANPR FINAL/app.py"
    click Act "https://github.com/manojbaniya444/minor-project-bct-iii-ii/blob/main/ANPR FINAL/actions.py"
    click Back "https://github.com/manojbaniya444/minor-project-bct-iii-ii/blob/main/ANPR FINAL/backup_actions.py"
    click Images "https://github.com/manojbaniya444/minor-project-bct-iii-ii/tree/main/ANPR FINAL/images/"
    click YD "https://github.com/manojbaniya444/minor-project-bct-iii-ii/blob/main/ANPR FINAL/yolo_detect.py"
    click YP "https://github.com/manojbaniya444/minor-project-bct-iii-ii/blob/main/ANPR FINAL/yolo_predict.py"
    click WP "https://github.com/manojbaniya444/minor-project-bct-iii-ii/blob/main/ANPR FINAL/trained_models/best.pt"
    click Seg "https://github.com/manojbaniya444/minor-project-bct-iii-ii/blob/main/ANPR FINAL/segment.py"
    click C1 "https://github.com/manojbaniya444/minor-project-bct-iii-ii/blob/main/ANPR FINAL/classify.py"
    click C2 "https://github.com/manojbaniya444/minor-project-bct-iii-ii/blob/main/ANPR FINAL/classify_class.py"
    click SM "https://github.com/manojbaniya444/minor-project-bct-iii-ii/tree/main/ANPR FINAL/trained_models/classification_model/"
    click DBi "https://github.com/manojbaniya444/minor-project-bct-iii-ii/blob/main/ANPR FINAL/db.py"
    click DBf "https://github.com/manojbaniya444/minor-project-bct-iii-ii/blob/main/ANPR FINAL/lpr.db"
    click Utils "https://github.com/manojbaniya444/minor-project-bct-iii-ii/blob/main/ANPR FINAL/utils.py"

    classDef ui fill:#DAE8FC,stroke:#6C8EBF,color:#000
    classDef controller fill:#E1D5E7,stroke:#9673A6,color:#000
    classDef cv fill:#D5E8D4,stroke:#82B366,color:#000
    classDef ml fill:#E2F0D9,stroke:#82B366,color:#000
    classDef model fill:#FFF2CC,stroke:#D6B656,color:#000
    classDef db fill:#F8CECC,stroke:#B85450,color:#000
    classDef util fill:#F2F2F2,stroke:#999999,color:#000
    classDef data fill:#FCE5CD,stroke:#E69138,color:#000
```
