# mjrovai/opencv-face-recognition architecture

> Architecture diagram of the GitHub repository mjrovai/opencv-face-recognition, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mjrovai/opencv-face-recognition
- Repository: https://github.com/mjrovai/opencv-face-recognition

## Overview

##### Project type and purpose
- This is a Python-based, real-time computer-vision application built around OpenCV.
- It performs two main tasks: face/feature detection (using Haar cascades) and face recognition (dataset creation, model training, and live recognition).

##### File structure
- Top-level folders:
- FaceDetection/ – contains scripts for detecting faces, eyes, smiles, or any combination
- FacialRecognition/ – contains scripts to collect a face dataset, train a recognizer, and run recognition
- Cascades/ subfolder in FaceDetection holds XML models (haarcascade_*.xml).

##### README
- Confirms the use of OpenCV, Python, Haar cascades, and a standard recognition algorithm (e.g., LBPH).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Online Phase" 
        direction TB
        VideoInput["Video Input\n(Camera/Stream)"]:::io
        Preprocessing["Preprocessing\n(Frame Grabber + Grayscale)"]:::process
        subgraph "Detection Variants"
            direction TB
            FD1["faceDetection.py"]:::process
            FD2["faceEyeDetection.py"]:::process
            FD3["faceSmileDetection.py"]:::process
            FD4["faceSmileEyeDetection.py"]:::process
        end
        FeatureDetection["Feature Detection Module"]:::process
        RecognitionEngine["Recognition Engine\n(predicted ID)"]:::process
        OutputDisplay["Output Display\n(Annotated Video / CLI)"]:::io
    end

    subgraph "Offline Phase"
        direction TB
        DatasetManager["Dataset Manager\n(captures faces)"]:::storage
        TrainingEngine["Training Engine\n(trains LBPH model)"]:::storage
        ModelFile["Model File"]:::storage
    end

    subgraph "Resources"
        direction TB
        Cascades["Haar Cascades"]:::external
        FDFCascade["haarcascade_frontalface_default.xml"]:::external
        EyeCascade["haarcascade_eye.xml"]:::external
        SmileCascade["haarcascade_smile.xml"]:::external
    end

    %% Data Flow Online
    VideoInput -->|"Frame"| Preprocessing
    Preprocessing -->|"Grayscale Frame"| FeatureDetection
    FeatureDetection -->|"Detected Face ROI"| RecognitionEngine
    RecognitionEngine -->|"Prediction"| OutputDisplay

    %% Data Flow Offline (dashed)
    Preprocessing -->|"Detected Face ROI"| DatasetManager -.-> TrainingEngine
    TrainingEngine -.->|"Trained Model"| ModelFile
    ModelFile -.->|"Load Model"| RecognitionEngine

    %% Shared resources
    FeatureDetection --> FDFCascade
    FeatureDetection --> EyeCascade
    FeatureDetection --> SmileCascade

    %% Script variants feeding into FeatureDetection
    FD1 --> FeatureDetection
    FD2 --> FeatureDetection
    FD3 --> FeatureDetection
    FD4 --> FeatureDetection

    %% Click events
    click FD1 "https://github.com/mjrovai/opencv-face-recognition/blob/master/FaceDetection/faceDetection.py"
    click FD2 "https://github.com/mjrovai/opencv-face-recognition/blob/master/FaceDetection/faceEyeDetection.py"
    click FD3 "https://github.com/mjrovai/opencv-face-recognition/blob/master/FaceDetection/faceSmileDetection.py"
    click FD4 "https://github.com/mjrovai/opencv-face-recognition/blob/master/FaceDetection/faceSmileEyeDetection.py"
    click RecognitionEngine "https://github.com/mjrovai/opencv-face-recognition/blob/master/FacialRecognition/03_face_recognition.py"
    click DatasetManager "https://github.com/mjrovai/opencv-face-recognition/blob/master/FacialRecognition/01_face_dataset.py"
    click TrainingEngine "https://github.com/mjrovai/opencv-face-recognition/blob/master/FacialRecognition/02_face_training.py"
    click FDFCascade "https://github.com/mjrovai/opencv-face-recognition/blob/master/FaceDetection/Cascades/haarcascade_frontalface_default.xml"
    click EyeCascade "https://github.com/mjrovai/opencv-face-recognition/blob/master/FaceDetection/Cascades/haarcascade_eye.xml"
    click SmileCascade "https://github.com/mjrovai/opencv-face-recognition/blob/master/FaceDetection/Cascades/haarcascade_smile.xml"

    %% Legend
    subgraph Legend
        direction TB
        IO["Input/Output"]:::io
        Proc["Processing"]:::process
        Stor["Storage"]:::storage
        Ext["External Resource"]:::external
    end

    classDef io fill:#9cd3db,stroke:#333,stroke-width:1px
    classDef process fill:#b3e6b5,stroke:#333,stroke-width:1px
    classDef storage fill:#ffcc80,stroke:#333,stroke-width:1px
    classDef external fill:#cccccc,stroke:#333,stroke-width:1px
```
