Skip to content

ShubrotoDas10/Air-Canvas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽจ Iron Canvas Pro - Air Drawing with Hand Gestures

Python OpenCV MediaPipe License

Iron Canvas Pro is a futuristic air drawing application that lets you paint in the air using just your hand gestures! Draw, sketch, and create with pinch gestures detected through your webcam - no physical tools required.

โœจ Features

๐Ÿ–๏ธ Hand Gesture Detection - Uses MediaPipe for accurate real-time hand tracking

โœ๏ธ Pinch to Draw - Bring your thumb and index finger together to draw

๐ŸŽจ Arc Color Palette - Beautiful semi-circle color picker at the top of the screen

๐ŸŒŸ Neon Glow Effects - Smooth neon glow on your drawings

๐ŸŽต Audio Feedback - Dynamic sound effects based on drawing speed (Windows only)

๐ŸŽฏ Sci-Fi HUD - Futuristic heads-up display showing hand skeleton and pinch indicator

๐Ÿงน Clear Canvas - Built-in eraser option to clear your artwork

โšก Smooth Movement - Configurable smoothing for stable drawing

๐ŸŽฎ How to Use

  1. Run the application
  2. Show your hand to the camera (palm facing the camera)
  3. Hover over the arc palette at the top to see colors
  4. Pinch (touch thumb to index finger) to select a color
  5. Move below the palette and pinch again to draw
  6. Release the pinch to stop drawing
  7. Select "CLEAR" from the palette to erase everything
  8. Press 'q' to quit

Gesture Controls

Gesture Action
๐Ÿ‘† Index finger up Control the cursor
๐Ÿค Pinch (thumb + index) Draw or select color
๐Ÿ–๏ธ Open hand Stop drawing
๐ŸŽจ Pinch over palette Change color or clear canvas

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • Webcam
  • Windows OS (for sound effects - optional)

Installation

  1. Clone or download the file
# Download canvas.py to your computer
  1. Install required packages
pip install opencv-python mediapipe numpy
  1. Run the application
python canvas.py

๐Ÿ“ฆ Dependencies

pip install opencv-python==4.8.0
pip install mediapipe==0.10.0
pip install numpy==1.24.0

Or install all at once:

pip install opencv-python mediapipe numpy

โš™๏ธ Configuration

You can customize the application by modifying the Config class:

class Config:
    WIDTH, HEIGHT = 1280, 720   # Window resolution
    
    PINCH_THRESHOLD = 40        # Sensitivity (lower = more sensitive)
    SMOOTHING = 0.6             # Movement smoothing (0.0 - 1.0)
    
    BRUSH_SIZE = 8              # Drawing brush thickness
    NEON_GLOW = True            # Enable/disable glow effect
    
    ARC_RADIUS = 150            # Color palette arc radius
    ARC_THICKNESS = 60          # Color palette thickness

Adjusting Sensitivity

If drawing is too sensitive:

PINCH_THRESHOLD = 50  # Increase this value

If drawing is not responsive enough:

PINCH_THRESHOLD = 30  # Decrease this value

For smoother but slightly laggy drawing:

SMOOTHING = 0.4  # Lower value

For faster but jittery drawing:

SMOOTHING = 0.8  # Higher value

๐ŸŽจ Available Colors

The arc palette includes:

  • ๐Ÿ”ด Red
  • ๐ŸŸ  Orange
  • ๐ŸŸก Yellow
  • ๐ŸŸข Green
  • ๐Ÿ”ต Cyan
  • ๐ŸŸฃ Purple
  • โšช White
  • ๐Ÿงน Clear (erases canvas)

๐Ÿ› ๏ธ Technical Details

How It Works

  1. Hand Detection

    • Uses MediaPipe Hands solution
    • Detects 21 hand landmarks in real-time
    • Tracks index finger (landmark 8) and thumb (landmark 4)
  2. Pinch Detection

    • Calculates distance between thumb tip and index finger tip
    • Pinch detected when distance < threshold (default: 40 pixels)
  3. Drawing System

    • Smooth cursor position using exponential smoothing
    • Lines drawn between consecutive positions
    • Neon glow effect using Gaussian blur
  4. Color Palette

    • Arc-shaped UI at top of screen
    • Hover detection using angle calculation
    • Selection by pinching over desired color
  5. Audio Feedback (Windows only)

    • Sound frequency changes based on drawing velocity
    • Runs in separate thread to avoid blocking
    • Automatically falls back if not available

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Camera    โ”‚
โ”‚   Input     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚
       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  MediaPipe  โ”‚
โ”‚Hand Trackingโ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚
       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Hand System โ”‚โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚   Canvas     โ”‚
โ”‚   (HUD)     โ”‚      โ”‚  (Drawing)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚                     โ”‚
       โ–ผ                     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚Arc Palette  โ”‚      โ”‚ Neon Glow    โ”‚
โ”‚  Selection  โ”‚      โ”‚   Effect     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŽฏ Features Breakdown

1. Hand System

  • Real-time hand tracking using MediaPipe
  • 21 landmark points detection
  • Sci-fi styled HUD overlay
  • Joint connections visualization
  • Pinch distance indicator bar

2. Arc Palette

  • 8 color options in semi-circle
  • Hover highlight effect
  • Color name display on hover
  • Selection feedback with white ring

3. Drawing Engine

  • Smooth line drawing with anti-aliasing
  • Configurable brush size
  • Movement-based line thickness
  • Neon glow post-processing

4. Sound Engine

  • Velocity-based frequency modulation
  • Non-blocking threaded audio
  • Graceful fallback on non-Windows systems

๐Ÿ“Š Performance

  • FPS: 30-60 (depends on camera and CPU)
  • Latency: ~30-50ms hand tracking
  • CPU Usage: ~15-25% on modern processors
  • Memory: ~200-300 MB

๐Ÿ› Troubleshooting

Camera not detected

# Try different camera index
cap = cv2.VideoCapture(1)  # or 2, 3, etc.

Hand not detected

  • Ensure good lighting
  • Keep hand within camera frame
  • Try adjusting min_detection_confidence:
self.hands = self.mp_hands.Hands(
    min_detection_confidence=0.5,  # Lower for easier detection
    min_tracking_confidence=0.3
)

Drawing is jittery

# Increase smoothing
SMOOTHING = 0.4  # Lower = smoother

Drawing is laggy

# Decrease smoothing
SMOOTHING = 0.8  # Higher = more responsive

Sound not working

  • Sound only works on Windows
  • Install winsound (usually pre-installed)
  • Application will work fine without sound

Low FPS

  • Reduce resolution:
WIDTH, HEIGHT = 640, 480
  • Disable glow effect:
NEON_GLOW = False

๐ŸŽจ Usage Tips

Best Practices

  1. Position your hand 1-2 feet from camera for best tracking
  2. Use good lighting - avoid backlit situations
  3. Keep hand still when selecting colors
  4. Draw in smooth motions for best results
  5. Practice pinch gesture - don't press too hard

Creating Better Art

  • Use smooth, flowing movements
  • Vary your drawing speed for different effects
  • Mix colors by drawing over previous lines
  • Use the glow effect for ethereal designs

๐Ÿ”ง Advanced Customization

Custom Colors

Add your own colors to the palette:

self.colors = [
    ((0, 0, 255), "RED"),
    ((128, 0, 128), "CUSTOM"),  # Add custom color
    # ... more colors
]

Brush Styles

Modify drawing style:

# Thicker brush
Config.BRUSH_SIZE = 12

# Dotted style (in drawing logic)
cv2.circle(canvas, (cx, cy), Config.BRUSH_SIZE, color, -1)

Different HUD Styles

Customize the heads-up display colors:

# In draw_sci_fi_hud method
cv2.circle(overlay, pt, 3, (255, 0, 0), -1)  # Red joints
cv2.line(overlay, pt1, pt2, (0, 255, 0), 1)   # Green lines

๐Ÿš€ Future Enhancements

  • Multiple brush styles (spray, pencil, marker)
  • Undo/Redo functionality
  • Save drawings as images
  • Adjustable brush size with gestures
  • Two-hand drawing support
  • Shape recognition (circles, squares)
  • Layer system
  • Background image selection
  • Recording drawing as video
  • Export to SVG format

๐Ÿ’ก Use Cases

  • ๐ŸŽ“ Education - Teaching, presentations, remote learning
  • ๐ŸŽจ Art - Digital sketching, concept art, doodling
  • ๐ŸŽฎ Gaming - Gesture-based game controls
  • ๐Ÿ“Š Presentations - Live annotations during talks
  • ๐Ÿงฉ Fun - Creative play, party entertainment
  • โ™ฟ Accessibility - Touch-free interaction

๐Ÿ“ Code Structure

canvas.py
โ”œโ”€โ”€ Config                  # Configuration settings
โ”œโ”€โ”€ SoundEngine             # Audio feedback system
โ”‚   โ”œโ”€โ”€ set_drawing()      # Update drawing state
โ”‚   โ””โ”€โ”€ _loop()            # Background audio thread
โ”œโ”€โ”€ HandSystem             # Hand tracking and HUD
โ”‚   โ”œโ”€โ”€ process()          # Extract hand landmarks
โ”‚   โ””โ”€โ”€ draw_sci_fi_hud()  # Render HUD overlay
โ”œโ”€โ”€ ArcPalette             # Color picker UI
โ”‚   โ””โ”€โ”€ draw()             # Render and detect selection
โ””โ”€โ”€ main()                 # Application loop
    โ”œโ”€โ”€ Video capture
    โ”œโ”€โ”€ Hand processing
    โ”œโ”€โ”€ Drawing logic
    โ””โ”€โ”€ Display rendering

๐Ÿ” Privacy & Security

  • No data collection - everything runs locally
  • No internet required - fully offline
  • Camera access - only during runtime
  • No file creation - unless you save screenshots

๐Ÿ“„ License

This project is open source and available under the MIT License.

๐Ÿ™ Acknowledgments

  • MediaPipe - Hand tracking solution
  • OpenCV - Computer vision library
  • Inspired by futuristic UI designs and gesture interfaces

๐Ÿ‘จโ€๐Ÿ’ป Author

Shubroto Das

๐Ÿ†˜ Support

Having issues? Try these resources:

  • Check the troubleshooting section above
  • Ensure all dependencies are installed correctly
  • Verify your webcam is working
  • Check Python version (3.8+ required)

๐ŸŽฏ Quick Command Reference

# Install dependencies
pip install opencv-python mediapipe numpy

# Run application
python canvas.py

# Quit application
Press 'q' key

๐Ÿ“ธ Screenshots

[Camera View]  โ†’  [Hand Detection]  โ†’  [Drawing Canvas]
                         โ†“
                  [Arc Color Palette]

Made with โค๏ธ by Shubroto Das

Draw in the air, create with gestures! โœจ

Report Bug ยท Request Feature

About

Futuristic air drawing application that lets you create art using hand gestures detected through your webcam. Features MediaPipe hand tracking, pinch-to-draw controls, an arc-shaped color palette, neon glow effects, and a sci-fi HUD overlay. Draw, sketch, and paint without touching anything - just gesture and create in mid-air.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages