# pozapas/crowd-analyzer architecture

> Architecture diagram of the GitHub repository pozapas/crowd-analyzer, 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/pozapas/crowd-analyzer
- Repository: https://github.com/pozapas/crowd-analyzer

## Overview

##### Project Overview & Type
- This is a Python desktop GUI application that uses computer vision and machine learning for analyzing pedestrian and crowd mobility patterns. It integrates object detection (YOLO), tracking (Kalman filters), crowd density/speed analysis (Voronoi and classic methods), trajectory analysis via PedPy, and real-time plot interpretation via LlamaVision using the Groq API.
- The purpose is to load a video, process it for detecting and tracking objects (pedestrians), and then perform further crowd analytics through various modules, finally presenting the results on a GUI built with PyQt6.

##### Analyzing the File Structure
- Top-Level Files:
- CrowdAnalyzer.py: Serves as the main entry point, contains the GUI code and core orchestration.
- Tracker.py: Contains the tracking logic, density estimation functions (likely including Kalman filter handling), and possibly integration with analysis modules.
- requirements.txt: Lists the required Python packages and dependencies.
- .env.sample: Template for environment variables (e.g., Groq API key) needed for external API integration.
- README.md: Provides directions and context.
- Asset Directories:
- img: Stores screenshots and GUI images that illustrate the interface.
- video: Contains demo video files which can serve as inputs to the system.
- This simple structure indicates a tightly coupled application where the core logic is divided between GUI management (CrowdAnalyzer.py) and the processing/tracking module (Tracker.py).

a. GUI Layer:
- Represented by the PyQt6 interface in CrowdAnalyzer.py.
- Elements: “Load Video”, “Settings”, “Start Processing” buttons and panels for displaying video, tracked overlays, and analysis plots.
b. Video Input Module:
- Video file loader reading from user-selected video files.
c. Object Detection Component:
- YOLO usage — could be a dedicated sub-module within CrowdAnalyzer.py or integrated into the processing pipeline.
d. Tracking & Analysis Module:
- Tracker.py should be mapped as the module handling tracking (Kalman filters), density estimation, and speed calculation.
e. External Integration Modules:
- PedPy Integration: For analyzing pedestrian trajectories.
- LlamaVision Integration: For real-time interpretation of PedPy output plots via the Groq API.
- This integration depends on external libraries and the Groq API key from the .env configuration.
f. Configuration & Environment Management:
- The .env file for storing sensitive configuration such as the API key.
g. Output/Visualization Layer:
- The GUI output sections where trajectories, density, speed estimation plots, and analysis results are visualized.
h. Data Flow & Control:

##### Relationships and Interactions
- User initiates the process via the GUI.
- The video file selected by the user is passed down to the processing pipeline.
- The detection module (YOLO) identifies objects and passes data to the tracking module (Kalman filter based in Tracker.py).
- The Tracker module further computes density/speed estimation and integrates with PedPy for trajectory analytics.
- Analysis results are then optionally enhanced by real-time interpretations from LlamaVision, using the Groq API (ensured by proper configuration through the .env file).
- Finally, processed results and plots are rendered back in the GUI.

##### Architectural Patterns and Design Principles
- Layered Architecture: Separation between the user interface (GUI), business logic (tracking and analysis in Tracker.py), and external service integrations.
- Modular Design: Clear modular separation between video processing, object detection, tracking & analysis, and external API integration.
- Dependency Injection/Configuration Management: Usage of environment variables (.env file) for injecting configuration like API keys.
- Event-Driven UI: The GUI is likely event-driven (buttons to load video, configure settings, etc.), triggering the processing pipeline.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Main Application (GUI - CrowdAnalyzer.py)"]:::ui
    B["Video Input Module"]:::processing
    C["Detection Module (YOLO)"]:::processing
    D["Tracking & Analysis Module (Tracker.py)"]:::processing
    E["PedPy Integration"]:::external
    F["LlamaVision Integration via Groq API"]:::external
    G["Configuration (.env)"]:::external
    H["Results/Visualization"]:::ui

    A -->|"initiates"| B
    B -->|"loads-video"| C
    C -->|"detects-objects"| D
    D -->|"tracks-&-estimates"| E
    D -->|"tracks-&-estimates"| F
    G -->|"configures"| E
    G -->|"configures"| F
    E -->|"outputs-analysis"| H
    F -->|"outputs-analysis"| H
    H -->|"renders-results"| A

    click A "https://github.com/pozapas/crowd-analyzer/blob/main/CrowdAnalyzer.py"
    click B "https://github.com/pozapas/crowd-analyzer/tree/main/video"
    click C "https://github.com/pozapas/crowd-analyzer/blob/main/CrowdAnalyzer.py"
    click D "https://github.com/pozapas/crowd-analyzer/blob/main/Tracker.py"
    click E "https://github.com/pozapas/crowd-analyzer/blob/main/.env.sample"
    click F "https://github.com/pozapas/crowd-analyzer/blob/main/.env.sample"
    click G "https://github.com/pozapas/crowd-analyzer/blob/main/.env.sample"
    click H "https://github.com/pozapas/crowd-analyzer/tree/main/img"

    classDef ui fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef processing fill:#90EE90,stroke:#008000,stroke-width:2px;
    classDef external fill:#FFDAB9,stroke:#FFA500,stroke-width:2px;
```
