Air-Piano is a hands-free virtual MIDI instrument powered by your webcam and computer vision. By detecting finger gestures from both hands, it plays chords from the D Major scale in real-time โ no physical keyboard required!
A creative blend of music, machine vision, and MIDI technology โ all in Python.
This project uses OpenCV, cvzone (MediaPipe), and pygame.midi to:
- Detect hand gestures via webcam
- Map each raised finger to a chord
- Play the chord for 2 seconds before releasing it
PianoProject_CV/
โ
โโโ handgesturecvpiano.py # Original basic version: finger-chord mapping and auto-stop
โโโ handgesture.py # Enhanced version with instrument switching + chord display
โโโ chordmaping.txt # Lists chord mappings for reference
โโโ requirements.txt # All required dependencies
โโโ README.md # ๐ Youโre reading it!
Each hand controls different chords. Raising a finger = triggering a chord.
Hand | Finger | Chord | Notes Played |
---|---|---|---|
Left | Thumb | D Major | D, F#, A |
Left | Index | E Minor | E, G, B |
Left | Middle | G Major | G, B, D |
Right | Thumb | G Major | G, B, D |
Right | Index | A Major | A, C#, E |
Right | Middle | B Minor | B, D, F# |
Right | Pinky | F# Minor | F#, A, C# |
Check full mapping in:
chordmaping.txt
git clone https://github.com/anjalirj27/PianoProject_CV.git
cd PianoProject_CV
Ensure you are in a Python environment (e.g., tensorflowenv
). Then install all required packages:
pip install -r requirements.txt
Dependencies List (from requirements.txt
):
opencv-python
cvzone
pygame
mediapipe
numpy
To run the original hand-to-chord logic:
python handgesturecvpiano.py
To use advanced features like instrument switching and chord visual feedback:
python handgesture.py
- ๐ฅ Real-Time Hand Tracking using OpenCV + cvzone
- ๐น MIDI Chord Output using pygame.midi
- ๐ถ D Scale Chords mapped to specific fingers (both hands)
- โฑ๏ธ Auto Sustain: Chords sustain for 2 seconds and stop
- ๐๏ธ Control the piano just by lifting fingers in front of a webcam!