Hand Gesture
Draw on screen with just your finger — a real-time hand gesture drawing app built with Python, MediaPipe, and OpenCV. Switch colors, clear canvas, all hands-free through your webcam.
HandGesture is a real-time hand gesture drawing app that lets you draw on screen using just your index finger — no mouse, no stylus, no touch required. Point your finger at the webcam and start painting.
Built entirely in Python, the project combines OpenCV for video capture and canvas rendering with MediaPipe Hands for accurate 21-point hand landmark detection. It can track up to 4 hands simultaneously, and all controls — color switching, start/stop, clear — are triggered purely through on-screen gesture interaction.
The project demonstrates practical human-computer interaction through computer vision, showing how a simple camera feed can replace traditional input devices entirely.
1. Video Capture — OpenCV opens the default webcam and reads frames in a continuous loop, mirroring the feed so movement feels natural.
2. Preprocessing — Each frame is flipped horizontally and converted from BGR to RGB colour space as required by MediaPipe before processing.
3. Landmark Detection — MediaPipe Hands processes the RGB frame and returns normalised (x, y, z) coordinates for 21 hand keypoints per detected hand — covering every joint from wrist to fingertip.
4. Writing Gesture Check — A rule-based function checks whether only the index finger is raised (tip above MCP knuckle) while other fingers are folded. If true → drawing mode is active for that hand.
5. Canvas Drawing — When in drawing mode, the app draws a line between the current and previous index fingertip position on a persistent canvas layer using OpenCV's drawing functions.
6. Button Interaction — On-screen buttons (Start, Stop, Clear, colour pickers) are fixed regions on the frame. When a fingertip enters a button's bounding box, the corresponding action triggers automatically — no click needed.
7. Overlay & Display — The canvas layer is composited onto the live video frame and displayed in real time. Press Q to quit.
python handgesture.py in your terminal. Make sure your webcam is plugged in and the room is well-lit before running.Q to quit the app.| Button | Action |
|---|---|
| Start | Enable drawing mode — fingertip starts tracing lines |
| Stop | Disable drawing mode — hand tracked but nothing drawn |
| Clear | Wipe the entire canvas clean |
| Blue Green Red Pink | Switch brush color instantly |
Q |
Quit the application |
See it live — HandGesture in action.
The clip below shows the full experience: MediaPipe detecting hand landmarks in real time, the index-finger drawing engine tracing strokes on the canvas overlay, and gesture-based button interactions switching colors and clearing the board — all running at 30+ FPS directly from a webcam feed, with zero external hardware.
python handgesture.py. A webcam and a well-lit room is all you need.