# abhay-0103/helmet-and-object-detection architecture

> Architecture diagram of the GitHub repository abhay-0103/helmet-and-object-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhay-0103/helmet-and-object-detection
- Repository: https://github.com/abhay-0103/helmet-and-object-detection

## Overview

##### Project type and purpose
- This is a lightweight, single-machine Python application for real-time helmet and object detection.

##### File structure
Top-level files:
- README.md – project description and usage instructions
- 1100.wav – sound file for beep alerts
- helmet.pt, yolov8n.pt – model weights
- Helmet-Detection.py – CLI for image inference
- Helmet-Object-Detection.py – CLI for video/webcam inference
- Helmet-Detection-BeepSound.py – variant that plays a beep on detection

##### README for additional insights
- Confirms dependencies: PyTorch, OpenCV, ultralytics (YOLOv8)
- Describes 4 usage modes: image, video file, webcam, custom models
- Mentions real-time performance and customization via retraining

##### Main components & interactions
a. Input Sources
- Image files (path argument)
- Video files
- Webcam stream
b. Inference Engine
- YOLOv8 model loader (loads helmet.pt or yolov8n.pt)
- PyTorch backend
- Ultralytics YOLOv8 APIs
c. Post-processing & Alerts
- Optional beep sound (plays 1100.wav via simple audio library)
d. Output
- Window with overlaid detections
- Console logs (counts, frame rates)

##### Architectural patterns & design principles
- Modular CLI scripts: each script handles a single I/O mode
- Separation of concerns: model loading, inference, drawing, I/O, and alerting in distinct code blocks
- Lightweight, single-process real-time pipeline

- Input modules: parallelograms labeled “Image Reader,” “Video Reader,” “Webcam Capture”
- Inference Engine: rectangle labeled “YOLOv8 Inference (PyTorch + ultralytics)”
- Alert Service: rectangle labeled “Beep Sound Player (1100.wav)”
- Output: parallelogram labeled “Display Window / Console”
1. Input → Inference Engine
2. Model Store → Inference Engine (model load)
3. Inference Engine → Post-Processor
4. Post-Processor → Output
5. Inference Engine → Alert Service (on helmet detected) → Output (audio)
- I/O components in blue
- Inference & model in green
- Post-processing & alerting in orange
d. Labels & details

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Input Sources"
        ImgIn["/Image Reader/"]:::io
        VidIn["/Video Reader/"]:::io
        CamIn["/Webcam Capture/"]:::io
    end

    subgraph "Inference Engine"
        YOLO["YOLOv8 Inference\n(PyTorch + ultralytics)"]:::compute
    end

    subgraph "Model Store"
        HelmMod[(helmet.pt)]:::compute
        NanoMod[(yolov8n.pt)]:::compute
    end

    subgraph "Post-Processing & Alerting"
        PostProc["Bounding-Box Overlay\n(OpenCV)"]:::post
        AlertServ["Beep Sound Player"]:::post
        SoundRes["1100.wav"]:::post
    end

    Output["Display Window / Console"]:::io

    PyTorch((PyTorch)):::ext
    Ultralytics((Ultralytics YOLOv8)):::ext
    OpenCV((OpenCV)):::ext
    ProjectDoc["README.md"]:::extDoc

    ImgIn -->|"Image Array"| YOLO
    VidIn -->|"Video Frame"| YOLO
    CamIn -->|"Video Frame"| YOLO

    HelmMod -->|"Model Load"| YOLO
    NanoMod -->|"Model Load"| YOLO

    YOLO -->|"Detection Boxes"| PostProc
    PostProc -->|"Annotated Frame"| Output

    YOLO -->|"Helmet Detected"| AlertServ
    AlertServ -->|"Beep Audio"| SoundRes
    SoundRes -->|"Audio Output"| Output

    YOLO -->|"Frame Rate Info"| Output

    YOLO -->|uses| PyTorch
    YOLO -->|uses| Ultralytics
    PostProc -->|uses| OpenCV

    click ImgIn "https://github.com/abhay-0103/helmet-and-object-detection/blob/main/Helmet-Detection.py"
    click VidIn "https://github.com/abhay-0103/helmet-and-object-detection/blob/main/Helmet-Object-Detection.py"
    click AlertServ "https://github.com/abhay-0103/helmet-and-object-detection/blob/main/Helmet-Detection-BeepSound.py"
    click HelmMod "https://github.com/abhay-0103/helmet-and-object-detection/blob/main/helmet.pt"
    click NanoMod "https://github.com/abhay-0103/helmet-and-object-detection/blob/main/yolov8n.pt"
    click SoundRes "https://github.com/abhay-0103/helmet-and-object-detection/blob/main/1100.wav"
    click ProjectDoc "https://github.com/abhay-0103/helmet-and-object-detection/blob/main/README.md"

    classDef io fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef compute fill:#90EE90,stroke:#333,stroke-width:2px
    classDef post fill:#FFD580,stroke:#333,stroke-width:2px
    classDef ext fill:#D3D3D3,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
    classDef extDoc fill:#E0E0E0,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
```
