Control the game "Traffic Rider" using real-time hand gestures detected via your webcam. No keyboard input required!
- Gesture Control: Control throttle, brake, and lean left/right using hand gestures
- Real-time Detection: Uses MediaPipe Tasks API for fast and accurate hand tracking
- Overlay Display: Shows gesture information and countdowns on top of the game
- Safe Exit: Requires holding both palms open for 2 seconds to quit
- Python 3.8+
- Webcam
opencv-pythonmediapipepynput
-
Clone the repository
git clone <repository-url> cd Traffic-Rider-Gesture-Control
-
Install dependencies
pip install opencv-python mediapipe pynput
-
Download model file Download
hand_landmarker.taskand place it in the same directory as the script: https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task
-
Start the application
python traffic_rider_gesture_control.py
-
Gesture controls The script will display the available gestures on startup:
Right Fist → Up Arrow (Accelerate) Right Open Palm → Down Arrow (Brake) Left Hand Tilt L → Left Arrow (Lean Left) Left Hand Tilt R → Right Arrow (Lean Right) Both Open Palms → QUIT (Hold 2s) -
Play the game Switch to Traffic Rider and play! The gesture controls work in the background via
pynput, so the game window can stay focused.
| Gesture | Key | Description |
|---|---|---|
| Right Fist | Up Arrow | Accelerate |
| Right Open Palm | Down Arrow | Brake |
| Left Hand Tilt Left | Left Arrow | Lean Left |
| Left Hand Tilt Right | Right Arrow | Lean Right |
| Both Open Palms | Quit | Hold for 2 seconds to exit |
If the gestures aren't working as expected, adjust these constants in the script:
-
TILT_LEFT_THRESHOLD: Lower = left tilt triggers more easily -
TILT_RIGHT_THRESHOLD: Increase if right tilt triggers too easily -
FIST_CURL_THRESHOLD: Increase if fist/brake detection is too sensitive
- Camera not detected: Make sure your webcam is connected and not being used by another application
- Gestures not working: Ensure your hands are clearly visible to the webcam and well-lit
- Performance issues: Try reducing
CAMERA_WIDTHandCAMERA_HEIGHT, or increasingPROCESS_EVERY_N_FRAMEto skip more frames - Model file missing: Download
hand_landmarker.taskmanually from the URL above and place it in the same directory as the script.