# kishan-shr/computer-vision-based-facemask-detection-with-alert-system architecture

> Architecture diagram of the GitHub repository kishan-shr/computer-vision-based-facemask-detection-with-alert-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kishan-shr/computer-vision-based-facemask-detection-with-alert-system
- Repository: https://github.com/kishan-shr/computer-vision-based-facemask-detection-with-alert-system

## Overview

##### Project Type and Purpose
- This is a standalone, real-time computer vision application (an open-source tool) whose purpose is to detect whether people are wearing face masks in live video or static images and to trigger an audio alert if a violation is detected.

##### High-Level Component Identification
a. Video/Image Input
- Webcam (live capture) or static images/videos from disk
b. Face Detection Module
- OpenCV DNN using Caffe model (`deploy.prototxt` + `res10_300x300_ssd_iter_140000.caffemodel`)
c. Mask Classification Module
- TensorFlow/Keras model (`fmd_model.h5`)
d. Alert System
- Audio files in `Alarm/` or root directory (WAV/MP3) played via Pygame or simple audio playback library
e. User Interface / Control Scripts
- `detect_mask_live.ipynb` or `detect_mask.py` / `detect_mask_video.py`
- `login.py` (optional UI/log-in workflow)
f. Supporting Assets
- Test frames in `Test/`, example images in `Images/`
- `requirements.txt` for environment setup

##### Component Interactions & Data Flow
1. The system initializes by loading the face detector model and the mask classifier model.
2. Video Capture continuously grabs frames.
4. For each detected face, crop & preprocess → Mask Classification Module → outputs “Mask” or “No Mask” probability.
5. Decision logic:
– If “No Mask” exceeds threshold → invoke Alert System (play sound).
6. Annotated frame in UI window.
7. Optionally, log events or save snapshots in `Test/`.

##### Architectural Patterns & Design Principles
- Pipeline pattern: clear stages (Capture → Detect → Classify → Alert → Display)
- Modular separation: each stage is its own Python module/script
- Single-process, event-driven loop for real-time performance
- Extensibility: swap face detector models or mask classifier models without touching alert code

##### Technologies & Frameworks
- Python 3.8+
- OpenCV for video I/O and DNN face detection
- TensorFlow/Keras for mask classification
- Pygame or native audio library for alert playback
- NumPy, imutils, customtkinter or tkinter for UI controls
- Caffe model files for face detection

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Authentication
    subgraph "Authentication Phase"
        Login["Login Script (login.py)"]:::control
    end

    %% Initialization
    subgraph "Initialization Phase"
        FDModel["Face Detector<br/>(Caffe SSD)"]:::cv
        FDProto["deploy.prototxt"]:::cv
        FDWeights["res10_300x300_ssd_iter_140000.caffemodel"]:::cv
        MCModel["Mask Classifier<br/>(Keras/TensorFlow)"]:::dl
    end

    %% Runtime Pipeline
    subgraph "Runtime Pipeline"
        Input["Video/Image Input<br/>(Webcam / Disk)"]:::io
        Detection["Face Detection Module"]:::cv
        Classification["Mask Classification Module"]:::dl
        Decision["Decision Logic"]:::logic
        AlertSys["Alert System"]:::alert
        Display["Display Annotated Frame"]:::io
    end

    %% Supporting Assets
    subgraph "Supporting Assets"
        TestDir["Test Frames / Snapshots"]:::asset
        ImagesDir["Example Images"]:::asset
        Req["requirements.txt"]:::asset
        Readme["README.md"]:::asset
        License["LICENSE"]:::asset
    end

    %% Workflow Connections
    Login -->|"authenticate"| Input
    FDProto -.-> FDModel
    FDWeights -.-> FDModel
    MCModel -.-> Classification

    Input -->|"frame data"| Detection
    Detection -->|"cropped faces"| Classification
    Classification -->|"mask/no-mask probabilities"| Decision
    Decision -->|"overlay frame"| Display
    Decision -->|"no-mask alert"| AlertSys
    AlertSys -->|"audio playback"| Display

    %% Asset Links
    Input --> TestDir
    Input --> ImagesDir
    Login --> Req
    Login --> Readme
    Login --> License

    %% Click Events
    click Login "https://github.com/kishan-shr/computer-vision-based-facemask-detection-with-alert-system/blob/main/Computer-Vision-Based-Facemask-Detection-with-Alert-System/login.py"
    click FDProto "https://github.com/kishan-shr/computer-vision-based-facemask-detection-with-alert-system/blob/main/Computer-Vision-Based-Facemask-Detection-with-Alert-System/face_detector/deploy.prototxt"
    click FDWeights "https://github.com/kishan-shr/computer-vision-based-facemask-detection-with-alert-system/blob/main/Computer-Vision-Based-Facemask-Detection-with-Alert-System/face_detector/res10_300x300_ssd_iter_140000.caffemodel"
    click MCModel "https://github.com/kishan-shr/computer-vision-based-facemask-detection-with-alert-system/blob/main/Computer-Vision-Based-Facemask-Detection-with-Alert-System/fmd_model.h5"
    click TestDir "https://github.com/kishan-shr/computer-vision-based-facemask-detection-with-alert-system/tree/main/Computer-Vision-Based-Facemask-Detection-with-Alert-System/Test/"
    click ImagesDir "https://github.com/kishan-shr/computer-vision-based-facemask-detection-with-alert-system/tree/main/Computer-Vision-Based-Facemask-Detection-with-Alert-System/Images/"
    click Req "https://github.com/kishan-shr/computer-vision-based-facemask-detection-with-alert-system/blob/main/Computer-Vision-Based-Facemask-Detection-with-Alert-System/requirements.txt"
    click Readme "https://github.com/kishan-shr/computer-vision-based-facemask-detection-with-alert-system/blob/main/Computer-Vision-Based-Facemask-Detection-with-Alert-System/README.md"
    click License "https://github.com/kishan-shr/computer-vision-based-facemask-detection-with-alert-system/tree/main/Computer-Vision-Based-Facemask-Detection-with-Alert-System/LICENSE"
    click Input "https://github.com/kishan-shr/computer-vision-based-facemask-detection-with-alert-system/blob/main/Computer-Vision-Based-Facemask-Detection-with-Alert-System/detect_mask_live.ipynb"

    %% Styles
    classDef cv fill:#B3DDF2,stroke:#3182BD,color:#000
    classDef dl fill:#FDD49E,stroke:#D94801,color:#000
    classDef io fill:#C7E9C0,stroke:#31A354,color:#000
    classDef alert fill:#FCAE91,stroke:#CB181D,color:#000
    classDef logic fill:#DADAEB,stroke:#6A51A3,color:#000
    classDef control fill:#F4B7D2,stroke:#D53E4F,color:#000
    classDef asset fill:#EDEDED,stroke:#888,color:#000
```
