# saiyam26/face-recognition-with-opencv architecture

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

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

## Overview

##### Project Type and Purpose
- It’s a Python-based, command-line face recognition *pipeline* using OpenCV’s Haar Cascade for detection and LBPH for recognition.
- Purpose: capture face images, train an LBPH model, and perform real-time recognition.

##### File Structure
- Top-level scripts:
- TakePhotos.py — image capture & dataset creation
- Train.py — model training (LBPH)
- Recognize.py — model inference/real-time recognition
- Classifiers folder:
- haarface.xml — pre-trained cascade for face detection
- TrainedLBPH.yml (generated) — trained LBPH model
- No web/frontend components—this is a CLI/data-processing pipeline.

##### Extract Insights from README
- Workflow:
a. Run TakePhotos.py → collect ~25 face images per user
b. Run Train.py → produces TrainedLBPH.yml in Classifiers/
c. Run Recognize.py → live camera feed, detect & label faces
- Dependencies: Python 3.6+, OpenCV, NumPy, Pandas.

##### Main Components & Their Interactions
A. Data Capture Module
- Script: TakePhotos.py
- Uses webcam → detects faces via Haar Cascade (haarface.xml) → stores cropped face images in a local “datasets” folder (implied).
B. Dataset Storage
- Directory for raw images, typically named by user ID/​name.
C. Training Module
- Script: Train.py
- Inputs: face images + Haar Cascade
- Process: extracts LBPH features, trains model → outputs TrainedLBPH.yml
D. Model Storage
- Classifiers/TrainedLBPH.yml
E. Recognition Module
- Script: Recognize.py
F. External Libraries
- OpenCV (cv2) – face detection, image capture, display
- NumPy – numerical operations
- Pandas – (optional, for data handling)

##### Architectural Patterns & Design Principles
- Pipeline pattern: clear separation of capture → train → infer stages.
- Modularity: each Python script is a distinct component.
- Single responsibility: one script per major task.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Runtime Processes
    subgraph "Pipeline Stages"
        direction TB
        DC["TakePhotos.py"]:::process
        TR["Train.py"]:::process
        RC["Recognize.py"]:::process
    end

    %% Local Storage
    subgraph "Local Storage"
        direction TB
        DS["Dataset Storage (JPEG images)"]:::data
        Cascade["haarface.xml"]:::data
        MS["TrainedLBPH.yml"]:::data
    end

    %% External Dependencies
    subgraph "Dependencies"
        direction TB
        OPENCV["OpenCV (cv2)"]:::external
        NUMPY["NumPy"]:::external
        PANDAS["Pandas"]:::external
    end

    %% Workflow Arrows
    Webcam["Webcam"]:::external
    Webcam -->|"Frame stream"| DC
    DC -->|"Cropped face images (.jpg)"| DS

    DS -->|"Image set + haarface.xml"| TR
    Cascade --> TR
    TR -->|"LBPH model (.yml)"| MS

    Webcam -->|"Live frames"| RC
    Cascade --> RC
    MS --> RC
    RC -->|"Detection+Label"| UI["Console/UI"]:::external

    %% Dependencies connections
    OPENCV -.-> DC
    OPENCV -.-> TR
    OPENCV -.-> RC
    NUMPY -.-> DC
    NUMPY -.-> TR
    NUMPY -.-> RC
    PANDAS -.-> TR

    %% Legend
    subgraph "Legend"
        direction TB
        A["Processing Modules"]:::process
        B["Data & Models"]:::data
        C["External Dependencies"]:::external
    end

    %% Click Events
    click DC "https://github.com/saiyam26/face-recognition-with-opencv/blob/main/TakePhotos.py"
    click TR "https://github.com/saiyam26/face-recognition-with-opencv/blob/main/Train.py"
    click RC "https://github.com/saiyam26/face-recognition-with-opencv/blob/main/Recognize.py"
    click Cascade "https://github.com/saiyam26/face-recognition-with-opencv/blob/main/Classifiers/haarface.xml"
    click MS "https://github.com/saiyam26/face-recognition-with-opencv/blob/main/Classifiers/TrainedLBPH.yml"
    click README["README.md"] "README.md"

    %% Styles
    classDef process fill:#88cc88,stroke:#339933,stroke-width:2px;
    classDef data fill:#88bbff,stroke:#3366cc,stroke-width:2px;
    classDef external fill:#ffbb66,stroke:#cc6600,stroke-width:2px;
```
