Air Draw
Wanted to try making an air drawing thing from scratch. Most tutorials use the old mediapipe Hands API which is getting deprecated so I used the newer Tasks API instead.
Canvas layer
Keeping a separate image layer for the drawing and merging it with the camera feed each frame was the annoying part. Empty parts of the canvas had to be made transparent using a threshold mask and bitwise operations. cv2.threshold + cv2.bitwise_and + cv2.bitwise_or is the combo that works.
Gesture detection
First tried checking if fingertip y coordinate was above the knuckle y coordinate. Broke whenever the hand tilted sideways. Switched to distance based: if fingertip is farther from the wrist than the middle knuckle, finger is extended. Works regardless of hand angle.
Smoothing
Two layers of smoothing. One on the landmark positions themselves and one on the actual drawing point
Pinch to lift
Fixed pixel distance threshold for pinch detection broke whenever the hand moved closer or farther from the camera. Made the threshold relative to palm size instead (35% of wrist to middle knuckle distance). Much more consistent.
Controls (nutshell):
- Index finger up: Move Brush
- Pinch (Index + Thumb): Lift Brush (Pause Drawing)
- Index + Middle fingers up: Select Color / Clear
- Press ‘q’ to quit
Comments 1
The FPS is so low as i was in OBS when doing this and the main python window was inactive, or also maybe cause OBS was taking too much resource
Sign in to join the conversation.