# yash42828/yolo-object-detection-with-opencv architecture

> Architecture diagram of the GitHub repository yash42828/yolo-object-detection-with-opencv, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yash42828/yolo-object-detection-with-opencv
- Repository: https://github.com/yash42828/yolo-object-detection-with-opencv

## Overview

##### Project Type and Purpose
- The project is a computer vision application focused on object detection. It demonstrates how to detect objects in images, video files, and real-time streams using the YOLOv3 object detector (pre-trained on the COCO dataset). In addition, there’s a module showing real-time object detection using a MobileNetSSD model.
- The purpose is to enable object detection with deep learning via OpenCV, processing both static images and video streams.

##### File Structure
- There are separate directories for different detection approaches:
- “Object dection using image”: Contains the image-based detection script (yolo.py) and an images subfolder.
- “Object detection using video”: Contains the video-based detection script (yolo_video.py), a videos subfolder with source videos, and an output folder to store the processed video outputs.
- “real-time-object-detection”: Contains files (including MobileNetSSD deploy model and prototxt) for the real-time detection variant.
- “yolo-coco”: Stores the YOLOv3 configuration file (yolov3.cfg), weights (yolov3.weights), and label names (coco.names) that are essential for detection.
- Other files like .gitattributes and README provide documentation and version tracking.

##### Key Components
a. Input Sources:
- Static Images (from “Object dection using image/images”)
- Video Files (from “Object detection using video/videos”)
- Real-Time Video Stream (from “real-time-object-detection”)

b. Pre-Trained Model Assets:
- YOLOv3 assets from the “yolo-coco” folder (includes weights, configuration, and class names)
- MobileNetSSD assets from the “real-time-object-detection” folder (deploy models and prototxt)

c. Processing Modules / Detection Engine:
- YOLO Detection Module for images and videos (based on yolo.py and yolo_video.py).
- Real-Time Processing Module (real_time_object_detection.py) utilizing MobileNetSSD alongside OpenCV’s video capture.

d. Dependencies and Libraries:
- OpenCV (for image/video processing and deep learning integration)
- NumPy (for numerical operations)
- imutils (for additional image processing utilities)

e. Output:
- Processed images with detected objects
- Annotated videos saved in the “output” directory
- On-screen display or live streaming results in the real-time module

##### Relationships and Interactions
- Each detection script begins by acquiring input from either an image, a video file, or a live stream.
- The input is pre-processed (resizing, normalization) and then fed into the respective deep learning model (YOLOv3 for images and videos; MobileNetSSD in one case for real-time).
- The deep neural network model references its configuration files and pre-trained weights (located in “yolo-coco” or “real-time-object-detection”).

##### Architectural Patterns and Design Principles
- Separation of Concerns: Different directories and scripts represent distinct detection modes (image-based, video-based, real-time).
- Modularity: The design treats model files, configuration files, and input/output handlers as separate modules that interact via well-defined data flows.
- Reusability: The same YOLO model and OpenCV dependencies are used across different detection modes.

##### Final Advice
- That every important module (image detection, video detection, real-time detection) is represented.
- Don’t shy away from showing even the smaller “helper” modules or utilities if they are key to data flow or system operations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Inputs
    subgraph "Inputs"
        A1["Static Images"]:::input
        A2["Video Files"]:::input
        A3["Real-Time Video Stream"]:::input
    end

    %% Pre-Processing
    subgraph "Pre-Processing Layer"
        B1["Pre-Processing"]
    end

    %% Detection Modules
    subgraph "Detection Modules"
        C1["YOLO Detection (Image)"]:::detection
        C2["YOLO Detection (Video)"]:::detection
        C3["Real-Time Detection (MobileNetSSD)"]:::detection
    end

    %% Model Assets
    subgraph "Model Assets"
        D1["YOLOv3 Config"]:::assets
        D2["YOLOv3 Weights"]:::assets
        D3["YOLOv3 Labels"]:::assets
        D4["MobileNetSSD Caffe Model"]:::assets
        D5["MobileNetSSD Prototxt"]:::assets
    end

    %% Post-Processing and Output
    subgraph "Output Layer"
        E1["Post-Processing"]:::processing
        E2["Output Display/Storage"]:::storage
    end

    %% External Dependencies
    subgraph "Dependencies"
        F1["OpenCV"]:::dep
        F2["NumPy"]:::dep
        F3["imutils"]:::dep
    end

    %% Data Flow: Inputs to Pre-Processing
    A1 --> B1
    A2 --> B1
    A3 --> B1

    %% Pre-Processing to Detection Modules
    B1 --> C1
    B1 --> C2
    B1 --> C3

    %% Model Assets connection
    D1 --> C1
    D2 --> C1
    D3 --> C1

    D1 --> C2
    D2 --> C2
    D3 --> C2

    D4 --> C3
    D5 --> C3

    %% Detection Modules to Post-Processing and Output
    C1 --> E1
    C2 --> E1
    C3 --> E1

    E1 --> E2

    %% External Dependencies connected to Processing Components
    F1 --- B1
    F1 --- C1
    F1 --- C2
    F1 --- C3

    F2 --- B1
    F2 --- C1
    F2 --- C2
    F2 --- C3

    F3 --- B1
    F3 --- C1
    F3 --- C2
    F3 --- C3

    %% Output Storage for Video
    E2 -->|"store_videos"| O1["Annotated Videos"]:::storage

    %% Click Events for Component Mapping
    click A1 "https://github.com/yash42828/yolo-object-detection-with-opencv/tree/master/Object dection using image/images"
    click C1 "https://github.com/yash42828/yolo-object-detection-with-opencv/blob/master/Object dection using image/yolo.py"
    click A2 "https://github.com/yash42828/yolo-object-detection-with-opencv/tree/master/Object detection using video/videos"
    click C2 "https://github.com/yash42828/yolo-object-detection-with-opencv/blob/master/Object detection using video/yolo_video.py"
    click C3 "https://github.com/yash42828/yolo-object-detection-with-opencv/blob/master/real-time-object-detection/real_time_object_detection.py"
    click D4 "https://github.com/yash42828/yolo-object-detection-with-opencv/blob/master/real-time-object-detection/MobileNetSSD_deploy.caffemodel"
    click D5 "https://github.com/yash42828/yolo-object-detection-with-opencv/blob/master/real-time-object-detection/MobileNetSSD_deploy.prototxt.txt"
    click D1 "https://github.com/yash42828/yolo-object-detection-with-opencv/blob/master/yolo-coco/yolov3.cfg"
    click D2 "https://github.com/yash42828/yolo-object-detection-with-opencv/blob/master/yolo-coco/yolov3.weights"
    click D3 "https://github.com/yash42828/yolo-object-detection-with-opencv/blob/master/yolo-coco/coco.names"
    click O1 "https://github.com/yash42828/yolo-object-detection-with-opencv/tree/master/Object detection using video/output"

    %% Styling Classes
    classDef input fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef detection fill:#99CCFF,stroke:#333,stroke-width:2px;
    classDef assets fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef processing fill:#EEEEEE,stroke:#333,stroke-width:2px;
    classDef storage fill:#CCCCFF,stroke:#333,stroke-width:2px;
    classDef dep fill:#FFCCCC,stroke:#333,stroke-width:2px;
```
