Skip to content

VirtualPainter is an interactive computer vision application that transforms your webcam into a virtual drawing canvas

Notifications You must be signed in to change notification settings

0xZayyad/VirtualPainter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VirtualPainter 🎨

A fun and interactive Python/OpenCV project that transforms your webcam into a virtual drawing canvas using advanced hand gesture recognition.

Overview

VirtualPainter uses computer vision and machine learning to detect hand gestures in real-time, allowing users to draw, paint, and create digital art using nothing but hand movements. Built with MediaPipe and OpenCV, it offers an intuitive and engaging way to create digital artwork.

Features

  • 🖐️ Real-time Hand Tracking: Advanced gesture recognition using MediaPipe
  • 🎨 Multiple Colors: Red, Green, Blue, Magenta, and Eraser modes
  • ✏️ Drawing Modes: Selection mode (two fingers) and Drawing mode (index finger)
  • 🖼️ Persistent Canvas: Your drawings stay on screen until cleared
  • 🎯 Gesture Controls: Intuitive finger-based interface
  • 📱 Cross-platform: Works on Windows, macOS, and Linux

Quick Start

Installation

  1. Clone the repository

    git clone <repository-url>
    cd VirtualPainter
  2. Install dependencies

    pip install -r requirements.txt
  3. Run the application

    python app.py

Basic Usage

  1. Position yourself 2-3 feet from your webcam
  2. Select colors by raising index and middle fingers together, then hover over the color palette
  3. Draw by raising only your index finger and moving it around
  4. Erase by selecting the black color (rightmost in palette)
  5. Press 'q' to quit the application

Documentation

📚 Complete Documentation Suite

🚀 Quick Reference

Gesture Controls

  • Selection Mode: Index + Middle fingers up → Navigate color palette
  • Drawing Mode: Index finger only → Draw on canvas
  • Rest Position: All fingers down → No action

Color Palette

Color Position Use Case
Red Slot 1 Default drawing
Green Slot 2 Nature elements
Blue Slot 3 Sky and water
Magenta Slot 4 Highlights
Black Slot 5 Eraser mode

Project Structure

VirtualPainter/
├── app.py                    # Main application
├── detectlib.py             # Detection library with HandDetector, FaceDetector, PoseDetector
├── requirements.txt         # Python dependencies
├── graphics/               # UI assets and color palette images
├── docs/                   # Comprehensive documentation
│   ├── API_DOCUMENTATION.md     # Complete API reference
│   ├── USER_GUIDE.md           # User instructions and tips
│   └── TECHNICAL_REFERENCE.md  # Technical implementation details
└── README.md               # This file

API Overview

HandDetector Class

import detectlib as dlib

# Initialize detector
detector = dlib.HandDetector(min_detection_confidence=0.7)

# Detect hands in frame
frame = detector.detect_hands(frame, draw_rect=True)

# Get hand landmarks
landmarks = detector.find_position(frame, draw=False)

# Check finger states
fingers = detector.fingers_up()  # [thumb, index, middle, ring, pinky]

Key Methods

  • detect_hands() - Detect and draw hand bounding boxes
  • find_position() - Get landmark coordinates
  • fingers_up() - Determine which fingers are extended
  • draw_circle() - Draw markers at specific landmarks
  • hands_count() - Count detected hands

Examples

Basic Hand Tracking

import cv2
import detectlib as dlib

detector = dlib.HandDetector()
cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()
    if ret:
        frame = detector.detect_hands(frame)
        cv2.imshow('Hand Tracking', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

cap.release()
cv2.destroyAllWindows()

Gesture Recognition

fingers = detector.fingers_up()
if fingers[1] and fingers[2]:
    print("Selection mode - Two fingers up")
elif fingers[1] and not fingers[2]:
    print("Drawing mode - Index finger only")

Requirements

  • Python 3.7+
  • OpenCV 4.5+
  • MediaPipe 0.8.9+
  • NumPy 1.19+
  • Webcam (built-in or external)

Troubleshooting

Common Issues

  • Hand not detected: Improve lighting, move closer to camera
  • Choppy drawing: Move finger more slowly, ensure good lighting
  • Colors not changing: Make sure both fingers are clearly raised in selection mode

See the User Guide for detailed troubleshooting steps.

Customization

The application can be easily customized:

  • Brush settings: Modify brush_thickness and eraser_thickness
  • Colors: Add new colors to the palette
  • Camera settings: Adjust resolution and FPS
  • Detection sensitivity: Tune confidence thresholds

See the Technical Reference for implementation details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests and documentation
  5. Submit a pull request

License

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

Acknowledgments

  • MediaPipe - Google's framework for building multimodal applied ML pipelines
  • OpenCV - Open source computer vision library
  • Community - Thanks to all contributors and users

Happy Drawing! 🎨✨

About

VirtualPainter is an interactive computer vision application that transforms your webcam into a virtual drawing canvas

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages