# aabisunhinged/hand-gesture-control architecture

> Architecture diagram of the GitHub repository aabisunhinged/hand-gesture-control, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aabisunhinged/hand-gesture-control
- Repository: https://github.com/aabisunhinged/hand-gesture-control

## Overview

#### Purpose and Entry Points
A Windows-oriented desktop gesture-control application. It uses a webcam plus a packaged hand-landmark model to translate detected hand poses into mouse, volume, media, screenshot, and visual-overlay actions.

Primary launch paths:
- `hand gesture control/main.py`
- `hand gesture control/main.pyw` for windowed Python launch
- `hand gesture control/run.bat` for batch-based startup

#### Application Orchestration
`hand gesture control/main.py` is the likely runtime coordinator: it gathers detection-confidence input, opens the camera/UI loop, handles keyboard mode switching (`1`–`4`, `q`, `s`), and routes each frame through tracking and the active gesture mode.

`hand gesture control/main.pyw` provides an alternate launcher-oriented entry point, likely avoiding a visible console on Windows.

#### Hand Tracking and Model Boundary
`hand gesture control/hand_tracker.py` encapsulates webcam-frame hand detection and landmark extraction. It is the boundary between raw camera images and normalized hand/finger landmark data consumed by gesture logic.

The application depends on MediaPipe-style model inference through:
- `hand gesture control/hand_landmarker.task`

Detection confidence is user-configurable (default 0.5); this tunes the tracker’s sensitivity versus false detections.

#### Gesture Interpretation and OS Control
`hand gesture control/gesture_control.py` owns interpretation of landmarks into control commands and likely calls desktop automation APIs. It defines the behavioral boundary between vision-derived coordinates and operating-system effects.

Its mode-specific command flows are:
- Cursor: index-finger position maps to cursor movement; thumb/index pinch triggers click.
- Volume: thumb/index distance maps to system volume.
- Media: finger-state patterns scroll up/down; fist captures a screenshot.
- Global screenshot: keyboard `s` triggers capture independently of mode.

#### Mode State Machine
The runtime maintains one of four active modes. Input can transition mode directly via numeric keys or cyclically through a right-hand gesture with four or more raised fingers. A closed-hand reset prevents repeated transitions while the gesture remains visible.

Relevant coordination paths:
- `hand gesture control/main.py`
- `hand gesture control/gesture_control.py`
- `hand gesture control/hand_tracker.py`

#### Visual Rectangle/X-Ray Mode
Rectangle mode is a frame-rendering pipeline rather than an OS-control action. When both hands expose thumbs and index fingers, their landmarks define a rectangular region. The app composites an inverted, blue-tinted camera view inside that region while retaining the normal camera image outside, then draws scan-line and corner-bracket effects.

This stage depends on tracker output and is likely rendered in the main camera display loop:
- `hand gesture control/main.py`
- `hand gesture control/hand_tracker.py`

#### Runtime and Platform Assumptions
The project is a local Python desktop process requiring:
- Webcam access
- A GUI/video display runtime
- Mouse/keyboard/screenshot automation permissions
- Windows-compatible volume and window behavior, suggested by `.pyw` and `run.bat`

User-facing operating notes and launch guidance reside in:
- `hand gesture control/README BEFORE USING.txt`

Main entry points: [`hand gesture control/main.py`](https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/main.py) (Runtime coordinator), [`hand gesture control/gesture_control.py`](https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/gesture_control.py) (Gesture interpreter), [`hand gesture control/hand_tracker.py`](https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/hand_tracker.py) (Hand tracker), [`hand gesture control/main.pyw`](https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/main.pyw) (Windowed launcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_launch["Launch"]
  node_main["Runtime coordinator<br/>Python application<br/>[main.py]"]
  node_main_pyw["Windowed launcher<br/>Python entry point<br/>[main.pyw]"]
  node_run_bat["Batch launcher<br/>Windows batch entry point<br/>[run.bat]"]
  node_usage_notes["Operating notes<br/>user documentation"]
end

subgraph group_vision["Vision Pipeline"]
  node_webcam(("Webcam frames<br/>camera input"))
  node_tracker["Hand tracker<br/>landmark extraction<br/>[hand_tracker.py]"]
  node_landmarker_model{{"Hand landmark model<br/>packaged inference model"}}
  node_landmarks["Hand landmarks<br/>normalized tracking data"]
end

subgraph group_control["Gesture Control"]
  node_gesture_control["Gesture interpreter<br/>command mapping<br/>[gesture_control.py]"]
  node_mode_state(("Four-mode state<br/>interaction state machine"))
end

subgraph group_output["Desktop &amp; Display"]
  node_cursor_actions["Cursor and click<br/>desktop action"]
  node_media_actions["Volume, media, screenshot<br/>desktop action"]
  node_rectangle_renderer["X-ray rectangle renderer<br/>frame compositing<br/>[main.py]"]
  node_camera_display["Camera display<br/>GUI video output"]
  node_windows_os{{"Windows desktop APIs<br/>OS automation"}}
end

node_main_pyw -->|"windowed launch"| node_main
node_run_bat -->|"starts"| node_main
node_usage_notes -.->|"documents launch"| node_main
node_webcam -->|"frames"| node_tracker
node_landmarker_model -->|"inference model"| node_tracker
node_main -->|"configures confidence and reads frames"| node_tracker
node_tracker -->|"extracts"| node_landmarks
node_landmarks -->|"hand coordinates"| node_gesture_control
node_main -->|"keyboard input 1–4"| node_mode_state
node_gesture_control -->|"raised-finger transition and reset"| node_mode_state
node_mode_state -->|"selects active behavior"| node_gesture_control
node_gesture_control -->|"cursor mode"| node_cursor_actions
node_gesture_control -->|"volume and media modes"| node_media_actions
node_main -->|"global s screenshot"| node_media_actions
node_cursor_actions -->|"mouse automation"| node_windows_os
node_media_actions -->|"system control"| node_windows_os
node_landmarks -->|"two-hand rectangle"| node_rectangle_renderer
node_main -->|"routes rectangle mode frames"| node_rectangle_renderer
node_rectangle_renderer -->|"composited frame"| node_camera_display
node_main -->|"normal display loop"| node_camera_display

click node_main "https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/main.py"
click node_main_pyw "https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/main.pyw"
click node_run_bat "https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/run.bat"
click node_tracker "https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/hand_tracker.py"
click node_landmarker_model "https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/hand_landmarker.task"
click node_gesture_control "https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/gesture_control.py"
click node_rectangle_renderer "https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_main_pyw,node_run_bat,node_usage_notes toneBlue
class node_webcam,node_tracker,node_landmarker_model,node_landmarks toneAmber
class node_gesture_control,node_mode_state toneMint
class node_cursor_actions,node_media_actions,node_rectangle_renderer,node_camera_display,node_windows_os toneRose
```

## Components

### Launch

- [Runtime coordinator](https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/main.py): Python application · Runs the camera loop, mode input, and frame routing. · `hand gesture control/main.py`
- [Windowed launcher](https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/main.pyw): Python entry point · Launches the application without a Windows console. · `hand gesture control/main.pyw`
- [Batch launcher](https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/run.bat): Windows batch entry point · `hand gesture control/run.bat`
- **Operating notes**: user documentation · Provides setup and launch guidance.

### Vision Pipeline

- **Webcam frames**: camera input
- [Hand tracker](https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/hand_tracker.py): landmark extraction · Converts camera frames into hand and finger landmarks. · `hand gesture control/hand_tracker.py`
- [Hand landmark model](https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/hand_landmarker.task): packaged inference model · MediaPipe-style hand landmark inference asset. · `hand gesture control/hand_landmarker.task`
- **Hand landmarks**: normalized tracking data

### Gesture Control

- [Gesture interpreter](https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/gesture_control.py): command mapping · Maps landmark patterns and distances to desktop commands. · `hand gesture control/gesture_control.py`
- **Four-mode state**: interaction state machine · Keyboard and raised-finger gestures select the active mode.

### Desktop & Display

- **Cursor and click**: desktop action · Maps index position to cursor movement and pinch to click.
- **Volume, media, screenshot**: desktop action · Applies distance and finger-state commands to OS controls.
- [X-ray rectangle renderer](https://github.com/aabisunhinged/hand-gesture-control/blob/main/hand%20gesture%20control/main.py): frame compositing · Renders an inverted blue region with scan-line and corner effects. · `hand gesture control/main.py`
- **Camera display**: GUI video output
- **Windows desktop APIs**: OS automation · Requires mouse, keyboard, screenshot, and volume permissions.

## Connections

- Windowed launcher → Runtime coordinator: windowed launch
- Batch launcher → Runtime coordinator: starts
- Operating notes → Runtime coordinator: documents launch
- Webcam frames → Hand tracker: frames
- Hand landmark model → Hand tracker: inference model
- Runtime coordinator → Hand tracker: configures confidence and reads frames
- Hand tracker → Hand landmarks: extracts
- Hand landmarks → Gesture interpreter: hand coordinates
- Runtime coordinator → Four-mode state: keyboard input 1–4
- Gesture interpreter → Four-mode state: raised-finger transition and reset
- Four-mode state → Gesture interpreter: selects active behavior
- Gesture interpreter → Cursor and click: cursor mode
- Gesture interpreter → Volume, media, screenshot: volume and media modes
- Runtime coordinator → Volume, media, screenshot: global s screenshot
- Cursor and click → Windows desktop APIs: mouse automation
- Volume, media, screenshot → Windows desktop APIs: system control
- Hand landmarks → X-ray rectangle renderer: two-hand rectangle
- Runtime coordinator → X-ray rectangle renderer: routes rectangle mode frames
- X-ray rectangle renderer → Camera display: composited frame
- Runtime coordinator → Camera display: normal display loop
