# gvern/virtual-makeup-tryon architecture

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

- Interactive diagram: https://gitdiagram.com/gvern/virtual-makeup-tryon
- Repository: https://github.com/gvern/virtual-makeup-tryon

## Overview

##### Project Type and Purpose
- This is a full-stack, real-time computer vision application that processes webcam video to apply makeup transfer in real time.
- The README outlines that it uses face detection (via MediaPipe), face parsing (via BiSeNet – although not directly visible in the file tree, the README provides context), and makeup transfer algorithms along with a GUI interface (interface.py). Dependencies include OpenCV, PyTorch, and other supporting libraries.

##### File Structure
- Top-Level Files:
– interface.py: Main GUI application that the user interacts with.
– main.py: Contains the MakeupTryOn class which orchestrates loading images, processing the webcam feed, and orchestrating the makeup application.
– webcam_test.py: Script to test webcam functionality.
– requirements.txt: Lists all necessary dependencies.
- Assets:
– assets/reference_images: Contains reference makeup images.
- src Directory:
– Contains core modules such as face_detection.py (for detecting faces) and makeup_transfer.py (for applying makeup styles). (Note: README also mentions face_parsing but this file might be part of a different branch or integrated into the others.)
- Utils Directory:
– Contains utility functions grouped in utils.py and visualization.py to support image handling and visual overlays.

##### Key Components and Their Roles
a. User Interface (GUI):
b. Application Core:
– main.py (MakeupTryOn class): Acts as the central controller that ties together modules, manages the webcam feed, and triggers makeup processing.
c. Processing Modules:
– src/face_detection.py: Implements real-time face detection and landmark tracking, likely leveraging MediaPipe.
– (Possibly) a face_parsing component: According to the README, there is a segmentation step using BiSeNet for facial region segmentation.
d. Utility Modules:
– utils/utils.py: Provides helper functions for image manipulation.
– utils/visualization.py: Adds visualization overlays, for example, for segmentation if enabled.
e. Supporting Assets & Tests:
– assets/reference_images: Sources for makeup styles.
– webcam_test.py: Offers a quick test harness for webcam functionality.

##### Relationships and Data Flow
- The system begins at the User Interface (interface.py) where the user inputs their desired reference image and configuration.
- The GUI delegates control to the main process (the MakeupTryOn class in main.py) which captures and processes the webcam feed.
- Within the processing pipeline, raw frames pass through the face detection module (src/face_detection.py) and then into the makeup transfer algorithm (src/makeup_transfer.py).
- If segmentation is enabled, an additional step handles face parsing (as explained in the README).
- Utility functions (from the utils folder) support these operations by processing images and generating overlays for visualization.
- Finally, the output—augmented video feed—is rendered back to the GUI and optionally snapshot capture saves images.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI["User Interface (interface.py)"]:::ui
    end

    %% Application Core
    subgraph "Application Core"
        MC["Main Application Controller (main.py)"]:::core
    end

    %% Processing Modules
    subgraph "Processing Modules"
        FD["Face Detection (src/face_detection.py)"]:::processing
        MCFG["Makeup Configuration (src/makeup_config.py)"]:::processing
        MT["Makeup Transfer (src/makeup_transfer.py)"]:::processing
        FP["Face Parsing (BiSeNet - Optional)"]:::processing
    end

    %% Utilities
    subgraph "Utilities"
        U1["Utility Functions (Image Handling) (utils/utils.py)"]:::util
        U2["Utility Functions (Visualization Overlays) (utils/visualization.py)"]:::util
    end

    %% Assets
    subgraph "Assets"
        AR["Makeup Reference Images (assets/reference_images)"]:::asset
        SA["Supporting Icons (assets/icons)"]:::asset
        FL["Facemesh Landmarks (assets/facemesh_landmarks.py)"]:::asset
    end

    %% Testing
    subgraph "Testing"
        WT["Webcam Testing (webcam_test.py)"]:::test
    end

    %% Data Flow Connections
    UI -->|"initiates"| MC
    MC -->|"calls"| FD
    MC -->|"loads"| MCFG
    MCFG -->|"configures"| MT
    MC -->|"triggers"| FP
    FD -->|"outputs data"| MT
    AR -->|"supplies styles"| MT
    SA -->|"provides icons"| UI
    FL -->|"provides landmarks"| UI
    U1 -->|"supports"| FD
    U1 -->|"supports"| MT
    U2 -->|"overlays"| UI
    MT -->|"augmented feed"| UI
    WT -->|"tests webcam"| UI
    MC ---|"uses(OpenCV,PyTorch)"| FD

    %% Styles
    classDef ui fill:#FFEECC,stroke:#FF9900,stroke-width:2px;
    classDef core fill:#CCE5FF,stroke:#007BFF,stroke-width:2px;
    classDef processing fill:#CCFFCC,stroke:#339933,stroke-width:2px;
    classDef util fill:#EFEFEF,stroke:#AAAAAA,stroke-width:2px;
    classDef asset fill:#FFCCCC,stroke:#CC3333,stroke-width:2px;
    classDef test fill:#D3D3D3,stroke:#696969,stroke-width:2px;

    %% Click Events
    click UI "https://github.com/gvern/virtual-makeup-tryon/blob/main/interface.py"
    click MC "https://github.com/gvern/virtual-makeup-tryon/blob/main/main.py"
    click FD "https://github.com/gvern/virtual-makeup-tryon/blob/main/src/face_detection.py"
    click MCFG "https://github.com/gvern/virtual-makeup-tryon/blob/main/src/makeup_config.py"
    click MT "https://github.com/gvern/virtual-makeup-tryon/blob/main/src/makeup_transfer.py"
    click U1 "https://github.com/gvern/virtual-makeup-tryon/blob/main/utils/utils.py"
    click U2 "https://github.com/gvern/virtual-makeup-tryon/blob/main/utils/visualization.py"
    click AR "https://github.com/gvern/virtual-makeup-tryon/tree/main/assets/reference_images"
    click SA "https://github.com/gvern/virtual-makeup-tryon/tree/main/assets/icons"
    click FL "https://github.com/gvern/virtual-makeup-tryon/blob/main/assets/facemesh_landmarks.py"
    click WT "https://github.com/gvern/virtual-makeup-tryon/blob/main/webcam_test.py"
```
