# abhigyanvarma/crowd-detection architecture

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

- Interactive diagram: https://gitdiagram.com/abhigyanvarma/crowd-detection
- Repository: https://github.com/abhigyanvarma/crowd-detection

## Overview

##### Project Type and Purpose
- This is a video-processing full-stack (single-application) tool with GUI. It loads video files, runs object detection (YOLOv8), applies DBSCAN clustering, assesses crowd risk, and displays results in a Tkinter window.
- Key purpose: real-time detection of people, group clustering for crowd density, and risk categorization.

##### File Structure
- Top level:
- LICENSE, README.md, requirements.txt
- Directory “c analysis” contains the core Python script (crowddetect.py), model files (yolov8n.pt, yolov3.cfg), and a sample output video.
- No separate “frontend” or “backend” folders; the application is monolithic with GUI and processing in one codebase.
- Dependencies and configurations are in requirements.txt and model/config files.

##### README Insights
- Main components described: video loader, YOLOv8 detection, DBSCAN clustering, risk assessment, Tkinter GUI.
- External dependencies are OpenCV, Ultralytics YOLO, numpy, pillow, scikit-learn.

##### Main Components
a. Video Input Module
- File selector in Tkinter GUI
- OpenCV VideoCapture for frame extraction
b. Detection Module
- Ultralytics YOLOv8 model loader (yolov8n.pt)
- Inference on frames to detect persons
c. Clustering Module
- DBSCAN algorithm (scikit-learn)
d. Risk Assessment Module
- Logic to assign low/medium/high risk based on cluster count/density
e. Visualization Module
- Processed frames in Tkinter window
f. Configuration/Model Layer
- yolov3.cfg (legacy YOLOv3 support if needed)
- yolov8n.pt (current model weights)
g. Dependency Layer (side note)
- External libraries (OpenCV, numpy, pillow, ultralytics, scikit-learn)

##### Relationships and Interactions
- Start at GUI → User clicks “Load Video”
→ Video Input Module reads frames
→ For each frame: pass to Detection Module → Detection results to Clustering Module → clusters to Risk Assessment → annotated frame to Visualization Module → back to GUI display

##### Architectural Patterns and Design Principles
- Modular separation of concerns: input, detection, clustering, assessment, visualization.
- Pipeline pattern: a linear processing chain per frame.
- Dependency injection: model and config files loaded once, reused for each frame.

##### Technologies, Frameworks, and Libraries
- OpenCV: video I/O and drawing
- Ultralytics YOLOv8: object detection engine
- scikit-learn DBSCAN: clustering engine
- Tkinter: GUI
- numpy/pillow: data processing and image handling

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Actors
    User((User)):::external -->|Clicks Load Video| VideoInput

    %% Processing Pipeline
    subgraph "Processing Pipeline"
        VideoInput[/Video Input Module/]:::io -->|raw frame| Detection
        Detection[Detection Module]:::process -->|detections| Clustering
        Clustering[Clustering Module]:::process -->|clusters| Risk
        Risk[Risk Assessment Module]:::process -->|risk labels| Visualization
        Visualization[Visualization Module]:::process -->|annotated frame| VideoInput
    end

    %% Model and Config Files
    yolov8[(yolov8n.pt)]:::config -->|model weights| Detection
    yolov3[(yolov3.cfg)]:::config -->|legacy config| Detection

    %% Output and Supporting Files
    outputVid[(output_video.mp4)]:::io
    Visualization -->|saves output| outputVid

    %% Dependency and Metadata
    Req[/requirements.txt/]:::io -.->|provides libraries| VideoInput
    Lic[/LICENSE/]:::io
    Read[/README.md/]:::io

    %% Click Events
    click VideoInput "https://github.com/abhigyanvarma/crowd-detection/blob/main/c analysis/crowddetect.py"
    click Detection "https://github.com/abhigyanvarma/crowd-detection/blob/main/c analysis/crowddetect.py"
    click Clustering "https://github.com/abhigyanvarma/crowd-detection/blob/main/c analysis/crowddetect.py"
    click Risk "https://github.com/abhigyanvarma/crowd-detection/blob/main/c analysis/crowddetect.py"
    click Visualization "https://github.com/abhigyanvarma/crowd-detection/blob/main/c analysis/crowddetect.py"
    click yolov8 "https://github.com/abhigyanvarma/crowd-detection/blob/main/c analysis/yolov8n.pt"
    click yolov3 "https://github.com/abhigyanvarma/crowd-detection/blob/main/c analysis/yolov3.cfg"
    click outputVid "https://github.com/abhigyanvarma/crowd-detection/blob/main/c analysis/output_video.mp4"
    click Req "https://github.com/abhigyanvarma/crowd-detection/blob/main/requirements.txt"
    click Lic "https://github.com/abhigyanvarma/crowd-detection/tree/main/LICENSE"
    click Read "https://github.com/abhigyanvarma/crowd-detection/blob/main/README.md"

    %% Styles
    classDef external fill:#fff2cc,stroke:#d6b656
    classDef io fill:#ADD8E6,stroke:#333
    classDef process fill:#90EE90,stroke:#333
    classDef config fill:#d3d3d3,stroke:#333
```
