# abdullahsajid007/eye-controlled-mouse-using-mediapipe-and-opencv architecture

> Architecture diagram of the GitHub repository abdullahsajid007/eye-controlled-mouse-using-mediapipe-and-opencv, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abdullahsajid007/eye-controlled-mouse-using-mediapipe-and-opencv
- Repository: https://github.com/abdullahsajid007/eye-controlled-mouse-using-mediapipe-and-opencv

## Overview

##### Project Type and Purpose
- It’s a single‐script, real‐time computer‐vision application in Python.
- Purpose: capture webcam video, detect eye position and blinks, map movements to mouse control.

##### Main Architectural Components
a. Input Layer
- Physical Webcam (video stream)
b. Processing Layer (data‐flow pipeline)
1. Video Capture Module
– OpenCV captures frames from webcam.
2. FaceMesh Detector
– Mediapipe FaceMesh processes each frame → outputs facial landmarks (eye coordinates).
3. Landmark Processor
– Extracts relevant eye landmarks, computes normalized positions & blink metric.
4. Coordinate Mapper
– Maps normalized eye‐position to screen coordinates based on display resolution.
5. Blink Detector
– Computes vertical distance between eye landmarks → detects blink event.
c. Output Layer
- Mouse Control Module (PyAutoGUI)
– Receives mapped coordinates and blink events → moves cursor & issues click events.
d. Optional Visualization
- OpenCV window showing live feed + overlayed landmarks.

##### Relationships & Data Flow
[Webcam] → [Video Capture] → [FaceMesh Detector] → [Landmark Processor] →
branching to → [Coordinate Mapper] → [Mouse Control] ⇒ OS cursor
and → [Blink Detector] → [Mouse Control] ⇒ OS click

##### Architectural Patterns & Design Principles
- Pipeline pattern: discrete, sequential processing stages.
- Single‐process, event‐driven loop.
- Modular separation (even in one script): input, detection, mapping, output.

##### Technologies & Frameworks
- OpenCV: video I/O & visualization.
- Mediapipe: face landmarks detection.
- PyAutoGUI: OS‐level mouse control.
- Python: orchestration.

##### Required Elements Checklist
- If desired, note future-enhancement extension points (e.g., “Drag‐and‐Drop Gesture Detector”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global direction
    direction TB

    %% External Devices
    WC["Webcam"]:::external
    OS["OS Cursor/Click"]:::external
    RD["Project Documentation"]:::doc

    %% Real-time Processing Loop
    subgraph "Real-time Processing Loop"
        direction TB
        VC["Video Capture Module"]:::process
        FD["FaceMesh Detector"]:::process
        LP["Landmark Processor"]:::process
        CM["Coordinate Mapper"]:::process
        BD["Blink Detector"]:::decision
    end

    %% Optional Visualization
    OV["Visualization (OpenCV imshow)"]:::process

    %% Mouse Control
    MC["Mouse Control Module"]:::process

    %% Data Flow
    WC -->|frame| VC
    VC -->|frame| FD
    FD -->|landmarks| LP
    LP -->|normalized landmarks| CM
    LP -->|landmarks| BD
    CM -->|"(x,y) coords"| MC
    BD -->|click_event| MC
    MC -->|move & click| OS
    LP -.->|frame with overlays| OV

    %% Documentation Link
    RD

    %% Click Events
    click VC "https://github.com/abdullahsajid007/eye-controlled-mouse-using-mediapipe-and-opencv/blob/main/main.py"
    click FD "https://github.com/abdullahsajid007/eye-controlled-mouse-using-mediapipe-and-opencv/blob/main/main.py"
    click LP "https://github.com/abdullahsajid007/eye-controlled-mouse-using-mediapipe-and-opencv/blob/main/main.py"
    click CM "https://github.com/abdullahsajid007/eye-controlled-mouse-using-mediapipe-and-opencv/blob/main/main.py"
    click BD "https://github.com/abdullahsajid007/eye-controlled-mouse-using-mediapipe-and-opencv/blob/main/main.py"
    click MC "https://github.com/abdullahsajid007/eye-controlled-mouse-using-mediapipe-and-opencv/blob/main/main.py"
    click OV "https://github.com/abdullahsajid007/eye-controlled-mouse-using-mediapipe-and-opencv/blob/main/main.py"
    click RD "https://github.com/abdullahsajid007/eye-controlled-mouse-using-mediapipe-and-opencv/blob/main/README.md"

    %% Styles
    classDef external fill:#d5f5e3,stroke:#2e7d32,color:#1b5e20,stroke-width:1px;
    classDef process fill:#d0e6f7,stroke:#1a5276,color:#154360,stroke-width:1px;
    classDef decision fill:#f7dc6f,stroke:#b9770e,color:#7d6608,stroke-width:1px,shape:diamond;
    classDef doc fill:#eeeeee,stroke:#999999,color:#333333,stroke-width:1px;
```
