# otienta/project_computer_vision architecture

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

- Interactive diagram: https://gitdiagram.com/otienta/project_computer_vision
- Repository: https://github.com/otienta/project_computer_vision

## Overview

##### Project type and purpose
- This is a Python-based, single-container (monolithic) “full-stack” application with an interactive web UI (Streamlit) on the front end and a video processing/detection/tracking pipeline on the back end.

##### File structure
- Top-level files:
– app.py: Streamlit UI and orchestration of the processing pipeline
– detector.py: wraps YOLOv8 inference for object detection
– track.py: implements multi-object tracking logic and writes tracking_log.csv
– audio.py: audio-based emergency signal detection
– evaluator.py: computes metrics or comparison against ground truth
– fine_tune.py: script to fine-tune YOLOv8 on custom classes
– generate_report.py: builds PDF reports (via reportlab) and aggregates CSV logs
– utils.py: shared helper functions (video I/O, heatmap generation, etc.)
– requirements.txt / packages.txt: dependencies (Streamlit, OpenCV, ultralytics, numpy, pandas, reportlab, scipy)
- Directories:
– sample_video/: test inputs & ground-truth CSV
– output/: processed videos, heatmaps, PDF reports, CSV logs
- Models: yolov8n.pt, yolov8s.pt, yolov8n_finetuned.pt
- Logs: detection_system.log, test_tracking.csv

##### README for additional insights
- Confirms technology stack (Streamlit, OpenCV, YOLOv8, reportlab, pandas).
- Describes features (real-time detection/tracking, emergency mode, heatmaps, PDF/CSV output).
- Usage flow: streamlit run app.py → upload/select video → choose classes/mode → view/download.

##### Main components & interactions
a. Frontend (Streamlit UI)
– app.py
– Accepts user inputs: video file, object classes, emergency mode toggle
– Displays live video frames with detection/tracking overlay, heatmap preview, download buttons
b. Video Processing Pipeline
– Video Reader (OpenCV)
– Detector (YOLOv8 model in detector.py)
– Tracker (track.py)
– Audio Detector (audio.py)—optional branch when emergency mode enabled
– Evaluator (evaluator.py)—optional, for ground-truth comparison
– Heatmap Generator (utils.py)
c. Report & Logging Subsystem
– CSV Logger (track.py writes tracking_log.csv)
– PDF Report Generator (generate_report.py using reportlab & pandas)
d. Storage Outputs
– Video outputs (.mp4) with overlays in output/
– Heatmap images or embedded in PDF
– Report PDFs in output/
– CSV logs in output/
– detection_system.log for system-level logs
e. External Services/Resources
– Pretrained YOLOv8 weights (yolov8n.pt, etc.)
– Python packages (Streamlit, ultralytics, OpenCV)

##### Architectural patterns & design principles
- Monolithic, modular Python application—each feature in its own module
- Pipeline pattern for video processing (reader → detector → tracker → post-processors)
- Model abstraction: detector.py encapsulates all YOLO inference details
- Separation of concerns: UI vs. core processing vs. reporting vs. logging
- Dependency injection via function parameters / utils module for shared code

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Frontend Layer"
        UI["Streamlit UI\n(app.py)"]:::frontend
    end

    subgraph "Video Processing Pipeline"
        VR["Video Reader\n(utils.py)"]:::pipeline
        DET["YOLOv8 Detector\n(detector.py)"]:::pipeline
        TRK["Multi-Object Tracker\n(track.py)"]:::pipeline
        AD["Audio-Based Emergency Detector\n(audio.py)"]:::pipeline
        EVAL["Evaluator\n(evaluator.py)"]:::pipeline
        HM["Heatmap Generator\n(utils.py)"]:::pipeline
    end

    subgraph "Reporting & Storage"
        CSV["CSV Logger\n(track.py)"]:::report
        PDF["PDF Report Generator\n(generate_report.py)"]:::report
        LOG["System Log File\n(detection_system.log)"]:::report
        OUT["Storage\n(output/)"]:::report
    end

    subgraph "External Resources"
        subgraph "Pretrained Model Weights"
            YN["yolov8n.pt"]:::external
            YS["yolov8s.pt"]:::external
            YFT["yolov8n_finetuned.pt"]:::external
        end
        subgraph "Sample Videos & Ground Truth"
            SV1["traffic.mp4"]:::external
            SV2["traffic-sign-test.mp4"]:::external
            SV3["test_gt.csv"]:::external
        end
        FT["Fine-Tuning Script\n(fine_tune.py)"]:::external
        UTIL["Shared Utilities\n(utils.py)"]:::external
        DEPS["Dependencies\n(requirements.txt, packages.txt)"]:::external
    end

    UI --> VR
    VR --> DET
    DET --> TRK
    TRK --> HM
    HM --> UI
    TRK --> CSV
    CSV --> PDF
    PDF --> OUT
    TRK --> LOG
    DET --> AD
    AD --> UI
    VR --> EVAL
    EVAL --> UI
    EVAL --> PDF
    DET --> YN
    DET --> YS
    DET --> YFT
    VR --> SV1
    VR --> SV2
    VR --> SV3
    UI --> DEPS
    UTIL -.-> VR
    UTIL -.-> HM

    click UI "https://github.com/otienta/project_computer_vision/blob/main/app.py"
    click VR "https://github.com/otienta/project_computer_vision/blob/main/utils.py"
    click DET "https://github.com/otienta/project_computer_vision/blob/main/detector.py"
    click TRK "https://github.com/otienta/project_computer_vision/blob/main/track.py"
    click AD "https://github.com/otienta/project_computer_vision/blob/main/audio.py"
    click EVAL "https://github.com/otienta/project_computer_vision/blob/main/evaluator.py"
    click HM "https://github.com/otienta/project_computer_vision/blob/main/utils.py"
    click PDF "https://github.com/otienta/project_computer_vision/blob/main/generate_report.py"
    click FT "https://github.com/otienta/project_computer_vision/blob/main/fine_tune.py"
    click UTIL "https://github.com/otienta/project_computer_vision/blob/main/utils.py"
    click LOG "https://github.com/otienta/project_computer_vision/blob/main/detection_system.log"
    click YN "https://github.com/otienta/project_computer_vision/blob/main/yolov8n.pt"
    click YS "https://github.com/otienta/project_computer_vision/blob/main/yolov8s.pt"
    click YFT "https://github.com/otienta/project_computer_vision/blob/main/yolov8n_finetuned.pt"
    click SV1 "https://github.com/otienta/project_computer_vision/blob/main/sample_video/traffic.mp4"
    click SV2 "https://github.com/otienta/project_computer_vision/blob/main/sample_video/traffic-sign-test.mp4"
    click SV3 "https://github.com/otienta/project_computer_vision/blob/main/sample_video/test_gt.csv"
    click DEPS "https://github.com/otienta/project_computer_vision/blob/main/requirements.txt"
    classDef frontend fill:#AED6F1,stroke:#1B4F72,color:#154360
    classDef pipeline fill:#A9DFBF,stroke:#1D8348,color:#196F3D
    classDef report fill:#F9E79F,stroke:#B7950B,color:#7D6608
    classDef external fill:#D5D8DC,stroke:#566573,color:#2C3E50
```
