Click below to watch the demo video:
A webcam-powered, real-time virtual musical instrument that transforms your hand gestures into MIDI chords and notes.
No physical instrument needed โ your fingers are the keys.
- Detects hand gestures via webcam
- Maps gestures to MIDI chords from the C Major / A Minor scale
- Works with any MIDI-compatible instrument โ piano, guitar, synth, drums, etc.
- Sends real-time MIDI signals with automatic note sustain (2 seconds)
| Tool | Purpose |
|---|---|
OpenCV |
Live webcam feed & image processing |
MediaPipe |
High-accuracy hand tracking engine |
cvzone |
Simplified wrapper for hand detection |
pygame.midi |
MIDI signal generation |
threading |
Smooth non-blocking note sustain |
git clone https://github.com/kaleprabhat24/MidiHands.git
cd MidiHandsEnsure Python 3.7 or higher is installed.
pip install -r requirements.txtIf cvzone doesn't install correctly:
pip install git+https://github.com/cvzone/cvzone.git- Webcam captures live video.
- MediaPipe locates hands and fingers.
- Raised fingers are mapped to specific chords.
pygame.midiplays MIDI notes in real-time.- Notes automatically stop after a 2-second sustain.
| Finger | Chord | Notes (MIDI) |
|---|---|---|
| Thumb | C Major | 60, 64, 67 |
| Index | D Minor | 62, 65, 69 |
| Middle | E Minor | 64, 67, 71 |
| Ring | F Major | 65, 69, 72 |
| Pinky | G Major | 67, 71, 74 |
| Finger | Chord | Notes (MIDI) |
|---|---|---|
| Thumb | A Minor | 69, 72, 76 |
| Index | C Major | 60, 64, 67 |
| Middle | D Minor | 62, 65, 69 |
| Ring | E Minor | 64, 67, 71 |
| Pinky | F Major | 65, 69, 72 |
cvzone.HandDetector()tracks hands and fingers.fingersUp()checks which fingers are raised.- Each finger triggers
note_on; sustain managed by Python threads. note_offis delayed by 2 seconds usingthreading.Timer.
- ๐ Real-time hand gesture control โ touchless & intuitive
- ๐น Use any virtual instrument (FL Studio, Synths, etc.)
- ๐งฉ Beginner-friendly code โ easily customizable
- ๐ Scalable โ add more gestures, notes, or instruments
- ๐ ๏ธ Works with both hands simultaneously
-
๐ป Change Instrument:
player.set_instrument(<instrument_id>)
Refer to General MIDI Instrument List
-
๐ Change Scale or Chords: Edit the
chord_mapdictionary to assign new chords or keys. -
โฑ๏ธ Modify Sustain Duration: Change the value of
SUSTAIN_TIME(default: 2.0 seconds).
absl-py==2.2.2
attrs==25.3.0
cffi==1.17.1
contourpy==1.3.2
cvzone==1.6.1
cycler==0.12.1
flatbuffers==25.2.10
fonttools==4.57.0
jax==0.6.0
jaxlib==0.6.0
kiwisolver==1.4.8
matplotlib==3.10.1
mediapipe==0.10.21
ml_dtypes==0.5.1
numpy==1.26.4
opencv-contrib-python==4.11.0.86
opencv-python==4.11.0.86
opt_einsum==3.4.0
packaging==24.2
pillow==11.2.1
protobuf==4.25.6
pycparser==2.22
pygame==2.6.1
pyparsing==3.2.3
python-dateutil==2.9.0.post0
scipy==1.15.2
sentencepiece==0.2.0
six==1.17.0
sounddevice==0.5.1Install them using:
pip install -r requirements.txt- ๐ต Beginners exploring music with no hardware
- โฟ Touchless option for disabled musicians
- ๐ Ideal for student projects, educators, or hobbyists
- ๐ง Connect directly to FL Studio or any DAW via virtual MIDI ports
A creative fusion of AI + Computer Vision + Music โ
This project shows how simple gestures can become powerful, expressive tools for creating sound.
Low-cost, fun, and full of potential.
- cvzone by Murtaza Hassan
pygame.midifor MIDI integration- OpenCV and MediaPipe for computer vision tracking
