# mahdihedayati01/drowsiness-detection architecture

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

- Interactive diagram: https://gitdiagram.com/mahdihedayati01/drowsiness-detection
- Repository: https://github.com/mahdihedayati01/drowsiness-detection

## Overview

##### Core Components

a. Input Layer:
- Webcam Input Component
- Video Frame Capture (OpenCV)

b. Processing Layer:
- MediaPipe FaceMesh Module
- Eye Aspect Ratio (EAR) Calculator
- Drowsiness Detection Logic

c. Output Layer:
- Visual Display Component
- Alert System (Audio & Visual)

##### Data Flow Connections
- Webcam → Frame Capture → FaceMesh Processing → EAR Calculation → Drowsiness Detection → Alerts

##### Detailed Component Specifications

For each component, include these details:
- Input/Output data types
- Key parameters (e.g., EAR_THRESH, WAIT_TIME)
- Processing functions

##### Technical Details
- MediaPipe FaceMesh landmarks (468 points)
- EAR calculation formula
- Alert thresholds and timing parameters
- Real-time processing loop

**[Webcam] → [Frame Capture (OpenCV)]**
- ↓
- [MediaPipe FaceMesh]
- ↓
- [Facial Landmark Detection]
- ↓
- [EAR Calculation Module]
- ↓
- [Drowsiness Detection Logic] → [Alert System]
- ↓                      ↓
- [Visual Display] ←------ [Audio Alert]

Additional Considerations:

##### Performance Flow
- Frame processing rate
- Real-time processing paths
- Parallel processing if any

##### System Requirements
- Hardware dependencies
- Software version requirements
- Optional components (like 'sox' for audio)

##### Error Handling
- Feedback loops
- Fallback paths
- Error notification flows

##### Integration Points
- Library dependencies
- API boundaries
- Configuration points

This design should effectively communicate both the data flow and the processing logic of the drowsiness detection system while maintaining clarity and technical accuracy.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        WC[Webcam Input]
        FC[Frame Capture]:::opencv
    end

    subgraph Processing
        MP[MediaPipe FaceMesh]:::processing
        FLD[Facial Landmark Detection]:::processing
        EAR[EAR Calculator]:::processing
        DDL[Drowsiness Detection Logic]:::logic
    end

    subgraph Output
        AS[Alert System]:::alert
        VD[Visual Display]:::output
        AA[Audio Alert]:::alert
    end

    WC --> FC
    FC --> MP
    MP --> FLD
    FLD --> EAR
    EAR --> DDL
    DDL --> AS
    DDL --> VD
    AS --> AA
    AS --> VD

    %% Component Mappings
    click DDL "https://github.com/MahdiHedayati01/drowsiness-detection/blob/main/main.py"

    %% Styles
    classDef opencv fill:#3498db,stroke:#2980b9,color:white
    classDef processing fill:#2ecc71,stroke:#27ae60,color:white
    classDef logic fill:#f1c40f,stroke:#f39c12,color:white
    classDef alert fill:#e74c3c,stroke:#c0392b,color:white
    classDef output fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        L1[Input Components]:::opencv
        L2[Processing Components]:::processing
        L3[Decision Logic]:::logic
        L4[Alert Components]:::alert
        L5[Output Display]:::output
    end
```
