Skip to content
 
 

Repository files navigation

hand-detection-model

workflow phase1

Phase 1:

Environment & IO SetupBefore the "smart" features, you need a stable video pipe.Dependency Alignment: Install opencv-python, mediapipe, and numpy.Camera Mirroring: Use cv2.flip(frame, 1) so that when you move your hand left, the cursor moves left on screen.Canvas Initialization: Create a blank NumPy array (the "Canvas") with the same dimensions as your webcam feed.

Phase 2:

The Vision Backbone (MediaPipe)Instead of processing raw pixels, you convert the hand into a mathematical map.Landmark Extraction: Initialize the MediaPipe Hands solution.Coordinate Mapping: Extract the Index Tip (ID 8) and Middle Tip (ID 12).Normalization: Convert the 0.0–1.0 coordinates from MediaPipe into actual pixel values (Width × $x$, Height × $y$).

Phase 3:

Gesture Engine (Decision Tree)This is the "Brain" of your project. You categorize the state based on finger positions:Mode A (Drawing): If Index is up AND Middle is down.Mode B (Selection): If Index is up AND Middle is up.Mode C (Erasing/Clear): If 3+ fingers are up OR if the Index tip enters the "UI Zone" on the left.

Phase 4:

The Drawing LogicThe "Last Point" Variable: Store the $(x, y)$ of the previous frame.Line Continuity: Use cv2.line() to connect the Previous Point to the Current Point. This prevents the drawing from looking like a series of dots when you move your hand fast.UI Overlay: Draw the vertical tool panel (rectangles for colors/brush sizes) on the frame, but NOT on the canvas.

Phase 5:

Frame Blending (The Final Look)This is where the magic happens. You have two images: the Webcam Feed and the Paint Canvas.Bitwise Operations: Create a mask of your drawing.Merging: Use cv2.addWeighted or bitwise masking to overlay the colored lines onto the live video.FPS Optimization: Ensure the processing loop stays above 24 FPS for a "lag-free" drawing experience

AirCanvas/

├── app.py             # Main execution loop
├── hand_tracker.py    # Class for MediaPipe logic
├── ui_manager.py      # Functions to draw the sidebar and buttons
└── utils.py           # Mathematical smoothing functions

suggest starting with Phase 3. Most beginners struggle with "line flickering" (where the line breaks because the hand was briefly undetected).

About

Real-time hand tracking using OpenCV and MediaPipe for gesture-based interaction and computer vision applications.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages