A real-time hand gesture recognition system that plays musical notes based on hand signs, using MediaPipe, OpenCV, and a trained classification model.
- Real-time Hand Tracking: Utilizes MediaPipe to accurately detect and track your hand's landmarks from a webcam feed.
- Gesture Recognition: Employs a pre-trained Random Forest Classifier to identify specific hand gestures in real time.
- Musical Note Playback: Maps detected gestures to musical notes (A-G), played via Pygame. Just press
P! - Melody Recording & Playback: Record sequences of notes you play and save them. You can then play back your recorded melodies.
- Interactive GUI: A user-friendly Tkinter interface displays the live camera feed, recognized gestures, and provides controls for camera, recording, and data collection.
- Gesture Data Collection: A built-in feature to collect new hand gesture data, allowing you to train your model with custom gestures.
- Uses your webcam to track your hand.
- Detects specific hand gestures using a trained machine learning model.
- Maps each gesture to a corresponding musical note (A–G).
- Press
Pto play the note associated with the currently detected gesture. - The GUI manages all these processes, showing the live feed, recognized gestures, and offering controls for various functionalities including recording your musical creations.
| Gesture | Musical Note |
|---|---|
| peace_sign | C |
| fist | D |
| thumbs_up | E |
| open_palm | F |
| call_me | G |
| index_finger | A |
| rock_on | B |
Install dependencies using pip:
pip install -r requirements.txtyour_project/
├── models/
│ ├── gesture_classifier.pkl
│ └── gesture_labels.pkl
├── notes/
│ ├── A.wav
│ ├── B.wav
│ └── ... (C to G)
├── data_creator_main.py
├── gesture_music_player.py
├── model_demo.py
├── model.py
├── README.md
└── requirements.txt
- Make sure you have a webcam connected.
- Place your trained model files (
gesture_classifier.pklandgesture_labels.pkl) in themodels/folder. - Ensure your note sound files (
A.wavtoG.wav) are in thenotes/folder. - Run the app:
python gesture_music_player.py- Interact with the App:
- The GUI will open, displaying your live camera feed. Hold your hand in front of the camera. The "Gesture" label will show the recognized gesture. Press the P key on your keyboard to play the musical note corresponding to the currently detected gesture. Use the "Start/Stop Recording" button to record a sequence of played notes. Click "Save Melody" to save your recorded sequence. Use the "List Melodies" and "Play Selected" buttons to manage and listen to your saved musical compositions. To close the application, simply close the GUI window.
- Press
ESCto exit the app.
- The app expects 21 hand landmarks, with x and y coordinates, for a total of 42 features.
- Trained using MediaPipe hand tracking data collected through a custom script.
Enjoy making music with your hands! ✋🎶
