Rhythmic Gestures is a webcam-controlled rhythm game that challenges players to perform hand gestures while music plays. The application combines real-time computer vision, gesture recognition, audio analysis, and an interactive scoring loop.
Built with Python, MediaPipe, OpenCV, librosa, and Pygame.
- OpenCV captures frames from the player’s webcam.
- MediaPipe classifies the player’s current hand gesture.
- The game displays a randomly selected target gesture.
- Matching the target gesture awards 100 points.
- Pygame plays the selected audio track while the game runs.
- librosa estimates the track’s tempo for future rhythm synchronization.
The current gesture vocabulary includes:
- Closed Fist
- Open Palm
- Pointing Up
- Thumb Down
- Thumb Up
- Victory
- I Love You
Webcam
|
v
OpenCV frame capture
|
v
MediaPipe gesture recognition
|
v
Compare detected gesture with target
|
+---- match ----> update score
|
+---- no match -> continue game loop
Audio file
|
+---- Pygame playback
|
+---- librosa tempo analysis
The application separates gesture prompts from the main game controller:
Gestureselects and displays target gestures.Gamemanages webcam capture, model inference, scoring, audio playback, and the main event loop.gesture_recognizer.taskprovides the MediaPipe gesture-recognition model.
- Python 3
- A working webcam
- A graphical desktop environment
- A legally obtained WAV audio file
Python packages:
mediapipeopencv-pythonlibrosapygame
Clone the repository:
git clone https://github.com/Colin243/Rhythmic-Gestures.git
cd Rhythmic-GesturesCreate and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activateOn Windows:
python -m venv .venv
.venv\Scripts\activateInstall the dependencies:
pip install mediapipe opencv-python librosa pygameThe current prototype expects a WAV file whose path is configured near the top of game.py.
Use an audio file that you have permission to use, place it in the project directory, and update both audio references:
y, sr = librosa.load("your-audio-file.wav")
my_sound = pygame.mixer.Sound("your-audio-file.wav")If the new track has a different duration, update the corresponding track-length value as well.
Start the application:
python game.pyA window named Gesture Tracking will display the mirrored webcam feed, target gesture, and score.
Press q to exit.
For the best recognition results:
- Keep your hand clearly visible.
- Use an evenly lit environment.
- Avoid placing your hand too far from the camera.
- Hold each gesture briefly so it can be classified.
Rhythmic-Gestures/
├── data/
│ ├── gesture_recognizer.task
│ └── hand_landmarker.task
├── game.py
├── test.py
└── README.md
game.pycontains the playable gesture game.data/gesture_recognizer.taskcontains the MediaPipe model used by the game.test.pycontains experimental Spotify integration and is not required to run the main application.
This repository is an early prototype.
- Gesture prompts currently change on a timer rather than using the exact beat timestamps returned by librosa.
- Audio configuration and duration are hard-coded.
- The game supports one level and a fixed scoring rule.
- Recognition confidence is not currently displayed or used to adjust scoring.
- There is no start screen, results screen, pause control, or difficulty selection.
- The experimental Spotify code is separate from the playable game.
- Automated tests and a dependency lock file have not yet been added.
- Schedule gesture prompts using librosa’s detected beat frames.
- Add configurable songs and automatic duration detection.
- Support difficulty levels and increasingly rapid gesture sequences.
- Introduce streaks, timing accuracy, and confidence-weighted scoring.
- Add start, pause, results, and song-selection screens.
- Separate camera, audio, recognition, and gameplay logic into testable modules.
- Add automated tests for scoring and gesture-transition behavior.
- Package the application with reproducible dependency versions.
I built Rhythmic Gestures to explore how real-time computer vision can become an interactive input mechanism. The project gave me experience integrating continuous webcam processing, ML-based gesture classification, audio playback, and stateful game logic in a latency-sensitive loop.
Colin Ho
Computer Science and Mathematics, Tufts University
GitHub