# antoinelame/gazetracking architecture

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

- Interactive diagram: https://gitdiagram.com/antoinelame/gazetracking
- Repository: https://github.com/antoinelame/gazetracking

## Overview

##### Main Components
- Demo/Client Layer: Represented by the example.py script which initiates the webcam capture using OpenCV and uses the GazeTracking class for processing.
- GazeTracking Library (gaze_tracking package): The core package contains modules like calibration.py, eye.py, gaze_tracking.py, and pupil.py. This layer encapsulates the processing logic (calibration routines, eye detection, pupil localization, gaze calculations).
- Trained Models: Under gaze_tracking/trained_models, include the dlib landmark predictor (shape_predictor_68_face_landmarks.dat) that is essential for facial feature extraction.
- External Dependencies: Highlight external libraries such as OpenCV for video capture and image processing, dlib for facial landmark detection, and NumPy as a supporting math library.

##### Relationships and Data Flow
- From example.py, the video frame is passed to the GazeTracking instance (invoking gaze_tracking.refresh(frame)).
- Inside the GazeTracking module, detail the pipeline:
- The calibration module processes the frame.
- The eye and pupil modules further extract the relevant regions (or coordinates).
- The gaze_tracking module uses these outputs along with the pre-trained model to compute gaze directions and other metrics.
- Finally, the annotated_frame() is produced and passed back to the output/display (using OpenCV’s imshow).

##### Architectural Patterns
- Pipeline Processing: Show a sequential flow from frame capture → calibration → landmark/eye detection → gaze computation → annotation.
- Modularity: Separate blocks for each processing module (calibration, eye tracking, pupil detection) reinforce clear responsibilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input/Output
    subgraph "Input/Output"
        A("Webcam Capture (OpenCV)"):::external
        B("Display (OpenCV imshow)"):::external
    end

    %% Demo/Client Layer
    subgraph "Demo/Client Layer"
        C("example.py"):::client
    end

    %% GazeTracking Library
    subgraph "GazeTracking Library"
        D("GazeTracking Instance (.refresh(frame))"):::library
        E("Calibration Module"):::module
        F("Eye Detection Module"):::module
        G("Pupil Detection Module"):::module
        H("Gaze Computation Module (gaze_tracking.py)"):::module
        I("Trained Model (shape_predictor_68_face_landmarks.dat)"):::model
    end

    %% External Dependencies
    subgraph "External Dependencies"
        J("OpenCV"):::externalDep
        K("dlib"):::externalDep
        L("NumPy"):::externalDep
    end

    %% Environment & Deployment
    subgraph "Environment & Deployment"
        M("Dockerfile"):::deploy
        N("environment.yml"):::deploy
        O("build_and_run.sh"):::deploy
    end

    %% Data & Control Flows
    A -->|"captures_frame"| C
    C -->|"sends_frame_to"| D
    D -->|"calls_calibration"| E
    E -->|"feeds_eye_detection"| F
    E -->|"feeds_pupil_detection"| G
    F -->|"combined_results"| H
    G -->|"combined_results"| H
    I -->|"used_by"| H
    H -->|"annotates_frame"| B

    %% External Dependencies influence processing
    J ---|"used_in_frame_capture/processing"| A
    J ---|"used_in_processing"| D
    K ---|"provides_landmark_detection"| I
    K ---|"used_in_processing"| H
    L ---|"computes_metrics"| H

    %% Click Events
    click C "https://github.com/antoinelame/gazetracking/blob/master/example.py"
    click D "https://github.com/antoinelame/gazetracking/tree/master/gaze_tracking/"
    click I "https://github.com/antoinelame/gazetracking/blob/master/gaze_tracking/trained_models/shape_predictor_68_face_landmarks.dat"
    click M "https://github.com/antoinelame/gazetracking/tree/master/Dockerfile"
    click N "https://github.com/antoinelame/gazetracking/blob/master/environment.yml"
    click O "https://github.com/antoinelame/gazetracking/blob/master/build_and_run.sh"

    %% Styles
    classDef external fill:#AED6F1,stroke:#2E86C1,stroke-width:2px;
    classDef client fill:#ABEBC6,stroke:#28B463,stroke-width:2px;
    classDef library fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
    classDef module fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef model fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef externalDep fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef deploy fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
```
