Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

🏃 Subway Surfers — One-Hand Finger Gesture Controller

Control Subway Surfers in Google Chrome using stationary, intuitive one-hand finger gestures captured from your MacBook webcam. Powered by OpenCV + MediaPipe Hands for real-time finger joint geometry tracking and PyAutoGUI for instant keyboard automation.


🎮 Final Gesture Controls

Keep your hand approximately stationary in front of the camera and show these simple finger combinations:

Gesture Finger Combination Game Action Key Sent
👍 THUMB ONLY Move Left ← Left Arrow
🤏 THUMB + INDEX Move Right → Right Arrow
☝️ INDEX ONLY Jump ↑ Up Arrow
✌️ INDEX + MIDDLE Roll / Duck ↓ Down Arrow
✊ FIST / ALL CLOSED Neutral / Reset (No action)
Q Press Q on keyboard Exit program —

Note: Any hand pose with 3 or more extended fingers (e.g. open hand) is automatically treated as NEUTRAL.


⚡ How the Finger Gesture Recognition Works

  1. No Arm or Tilt Movements:

    • The player keeps their hand comfortably in one place in front of the webcam.
    • The detector measures joint extension geometry (distances and angles relative to the wrist and knuckle bases), completely independent of hand tilt, velocity, or screen position.
  2. Accurate Thumb vs Finger Detection:

    • Thumb: Evaluated via straightness and abduction distance from the palm knuckles (MIDDLE_MCP and INDEX_MCP).
    • Index / Middle / Ring / Pinky: Evaluated via joint extension ratios relative to WRIST, MCP, and PIP.
    • Function identify_gesture(hand_landmarks) maps the exact combination to "LEFT", "RIGHT", "JUMP", "ROLL", or "NEUTRAL".
  3. One Gesture = Exactly One Keypress:

    • Showing ☝️ triggers one jump.
    • Holding ☝️ for 5 seconds does not spam repeated keys.
  4. Direct Gesture Switching:

    • You can switch directly between gestures (e.g. ☝️ JUMP → ✌️ ROLL, or 👍 LEFT → 🤏 RIGHT) without needing to close your hand into a fist first.
    • When a new gesture stabilizes, it triggers once immediately.
    • A fist ✊ acts as an explicit neutral reset.
  5. 2-of-3 Frame Debouncing (~66ms Latency):

    • Maintains a 3-frame history window requiring 2 frames to agree before confirming an action.
    • Eliminates single-frame transition glitches and flickering.
  6. Visual HUD & Fingertip Indicators:

    • The top banner on the webcam window displays:
      Detected Fingers: THUMB + INDEX
      Gesture: RIGHT   |   Action: RIGHT ARROW   |   State: ACTIVE   |   FPS: 30
      
    • Extended fingertips are highlighted with bright glowing circles and labels directly on the camera view.
    • A visual quick reference guide is displayed in the bottom-left corner.

🚀 Quick Start

1. Grant macOS Permissions

Ensure Terminal (or your IDE) has Accessibility and Camera permissions:

  • System Settings → Privacy & Security → Accessibility → Enable Terminal
  • System Settings → Privacy & Security → Camera → Enable Terminal

2. Activate Virtual Environment & Run

cd ~/Desktop/subway\ surfers
source .venv/bin/activate
python main.py

3. Play Subway Surfers

  1. Open Google Chrome and open Subway Surfers on Poki.
  2. Click inside the game window to give it keyboard focus.
  3. Show your hand gestures:
    • 👍 Thumb Only: Dodge left
    • 🤏 Thumb + Index: Dodge right
    • ☝️ Index Only: Jump
    • ✌️ Index + Middle: Roll
    • ✊ Fist: Reset

⚙️ Configuration Tuning (config.py)

Parameter Default Effect / How to Tune
GESTURE_CONFIRMATION_FRAMES 2 Number of frames that must agree (2 frames = ~66ms response).
GESTURE_HISTORY_LENGTH 3 History buffer size for majority voting.
GESTURE_COOLDOWN 0.15s Cooldown in seconds (150ms) between actions.
MIN_DETECTION_CONFIDENCE 0.60 MediaPipe hand detection confidence.
MIN_TRACKING_CONFIDENCE 0.60 MediaPipe hand tracking confidence.
FINGER_WRIST_TIP_RATIO 1.10 Tip-to-wrist extension ratio for index/middle/ring/pinky.
FINGER_MCP_TIP_RATIO 1.25 Tip-to-knuckle extension ratio for index/middle/ring/pinky.
THUMB_STRAIGHT_RATIO 1.15 Straightness ratio for thumb extension.
THUMB_PALM_DISTANCE_RATIO 0.55 Abduction distance ratio for thumb away from palm.

📁 Project Structure

subway surfers/
├── main.py              # Camera loop, MediaPipe Hands pipeline, fingertip highlights & HUD
├── gesture_detector.py  # Joint geometry classifier, identify_gesture(), debouncing & state machine
├── game_controller.py   # PyAutoGUI keyboard automation & safety failsafes
├── config.py            # Centralized settings & tunable parameters
├── requirements.txt     # Pinned Python dependencies
└── README.md            # Documentation & player guide

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages