# milind-mh19/bodypose_gamecontroller architecture

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

- Interactive diagram: https://gitdiagram.com/milind-mh19/bodypose_gamecontroller
- Repository: https://github.com/milind-mh19/bodypose_gamecontroller

## Overview

##### Project Type and Purpose
- This is a single‐host, full-application script that performs real-time pose detection on webcam input, classifies four gestures (left, right, jump, crouch), and injects keyboard events to control the Subway Surfer game.

##### Main Components
Break the code into these logical pieces (even if they live in app.py for now):
a. Input Source
- Webcam (OpenCV capture)
b. Pose Detection Engine
- MediaPipe Body Pose model
- Frame preprocessing (resizing, normalization)
c. Gesture Classifier & Mapping
- Simple rule-based logic to decide “left”, “right”, “jump”, “crouch”
d. Output/Actuator
e. Visualization & Logging (optional)
- Matplotlib for debugging plots, console logging

##### Relationships & Data Flow
User’s body → Webcam frame stream → Pose Detection → Gesture Classification → Keyboard Event → Subway Surfer Game

##### Architectural Patterns & Principles
- Pipeline pattern: data flows from capture → processing → action
- Single responsibility for each logical module (capture vs. detection vs. actuation)
- Separation of concerns sets you up to refactor into multiple files or even microservices later if needed.

##### Technologies & Frameworks
- OpenCV (camera capture, image preprocessing)
- MediaPipe (pose estimation graph)
- PyAutoGUI (keyboard automation)
- Matplotlib (optional debugging)

##### Final Checklist
- Clear, self-explanatory labels on components (e.g., “Pose Detector (MediaPipe)”)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Application (Python Runtime)"
        direction TB
        Input["Input Source<br/>(Webcam capture via OpenCV)"]:::python
        Pose["Pose Detector<br/>(MediaPipe & preprocessing)"]:::python
        Classifier["Gesture Classifier<br/>(rule‐based logic)"]:::python
        Actuator["Output/Actuator<br/>(PyAutoGUI key injection)"]:::python
        Visual["Visualization & Logging<br/>(Matplotlib & console logs)"]:::python
    end

    Webcam["Webcam Hardware"]:::external
    Game["Subway Surfer Game"]:::external
    Train["Gesture Training Service<br/>(placeholder)"]:::optional
    README["Project Overview & Instructions"]:::external
    Notebook["Experimental Prototyping & Notebooks"]:::external

    Webcam -->|"Video Frame"| Input
    Input -->|"Preprocessed Frame"| Pose
    Pose -->|"Pose Landmarks"| Classifier
    Classifier -->|"Action Command"| Actuator
    Actuator -->|"Key Press"| Game
    Actuator -->|"loop"| Input
    Pose -.->|"Debug Data"| Visual

    Train

    click Input "https://github.com/milind-mh19/bodypose_gamecontroller/blob/main/app.py"
    click Pose "https://github.com/milind-mh19/bodypose_gamecontroller/blob/main/app.py"
    click Classifier "https://github.com/milind-mh19/bodypose_gamecontroller/blob/main/app.py"
    click Actuator "https://github.com/milind-mh19/bodypose_gamecontroller/blob/main/app.py"
    click Visual "https://github.com/milind-mh19/bodypose_gamecontroller/blob/main/app.py"
    click README "https://github.com/milind-mh19/bodypose_gamecontroller/blob/main/README.md"
    click Notebook "https://github.com/milind-mh19/bodypose_gamecontroller/blob/main/main.ipynb"

    classDef python fill:#9f6,stroke:#333,stroke-width:1px
    classDef external fill:#ccc,stroke:#333,stroke-width:1px
    classDef optional fill:#bbf,stroke:#333,stroke-width:1px
```
