A real-time computer-vision project that uses a webcam to detect hand landmarks and turn fingertip movement into digital drawings.
This project began as a simple webcam hand-tracking experiment and is being developed step by step into a gesture-controlled drawing application.
- Real-time webcam input using OpenCV
- Hand landmark detection using MediaPipe
- Index-fingertip tracking
- Air drawing on a persistent canvas
- Smoothed fingertip movement for more stable lines
- Gesture-based color selection
- Neon air-graffiti trails
- Gesture-based erasing
- Movement-driven music-energy visualization
- Keyboard color-selection fallbacks
- Canvas clearing, saving, undo, and clean shutdown controls
air_drawing.py
Tracks the index fingertip and draws its movement on the screen.
air_drawing_v2.py
Adds gesture-based color selection and improved tracking stability.
Legacy V2 controls:
- Index finger raised, middle finger lowered — draw
- Two fingers — select blue
- Three fingers — select green
- Four fingers — select yellow
- Closed fist — select red
B— blueG— greenR— redY— yellowC— clear the canvasQ— quit
V3 controls:
- Point with the index finger, then pinch the index finger and thumb — draw
- Point at a color or eraser button in the left-side palette and hold for about half a second to select it
- Keyboard color selection remains available when tracking is weak
E— toggle manual eraserD— toggle free-draw mode when pinching is difficult- Hand height changes the musical note and movement energy changes volume
M— mute or unmute musicB/G/R/Y/P— select blue / green / red / yellow / purpleU— undo the last drawing, erasing, or clear actionS— save the drawing as a PNG in the project folderC— clear the canvasH— show or hide the help panelQ— quit
The V3 application is the recommended version for demonstrations and daily use.
V3 currently provides a visual music layer: faster hand movement increases the energy of the animated visualizer. Audio generation can be added as a later phase once the interaction is stable. The camera feed is used without software enhancement.
hand_tracking_test.py
Opens the webcam, detects hands, and displays MediaPipe landmarks without drawing.
- Windows, macOS, or Linux
- Python 3.10 recommended
- A working webcam
- OpenCV
- MediaPipe
Create and activate a virtual environment:
py -3.10 -m venv .venv
.\.venv\Scripts\Activate.ps1Install the dependencies:
python -m pip install --upgrade pip
python -m pip install -r requirements.txtRun the basic hand-tracking test:
python hand_tracking_test.pyRun the original air-drawing version:
python air_drawing.pyRun the legacy gesture-color version:
python air_drawing_v2.pyRun the latest version with gesture erasing, undo, and saving:
python air_drawing_v3.pyV3 opens fullscreen to maximize the drawing area. Press H to show or hide the help panel, and press Q while the camera view is focused to exit.
Close other applications that may be using the webcam, such as Camera, Zoom, Teams, or WhatsApp. If necessary, change the camera index in the script:
cv2.VideoCapture(0, cv2.CAP_DSHOW)Try 1 instead of 0 if the computer has multiple cameras.
Try the following:
- Face a light source instead of sitting with the light behind you
- Keep your hand 40–70 cm from the camera
- Use a clear, uncluttered background
- Keep your hand inside the visible camera frame
- Move the hand closer until it fills a reasonable part of the camera view
- Use the V3 status bar to confirm that the camera is running and the hand is detected
Use the project virtual environment and run commands with python -m pip. Keeping project dependencies inside .venv prevents conflicts with unrelated global packages.
- Webcam hand-tracking test
- Basic air drawing
- Gesture-based color selection
- Gesture-based erasing
- Improve gesture reliability and drawing usability
- Add an on-screen user interface
- Add saving and exporting drawings
- Add undo support
- Create a polished demo for sharing
This project is a practical introduction to computer vision and human-computer interaction. It explores how camera input, hand landmarks, gesture recognition, and real-time graphics can work together to create a natural interface.
This project is intended for learning and experimentation. A formal license can be added when the project is ready for public reuse.