This project is a Hand Drawing Application that uses OpenCV and MediaPipe to enable drawing on the screen by tracking hand landmarks. Users can draw lines using their index finger, clear the canvas, and save their drawing as a JSON file.
- Real-time hand tracking using MediaPipe.
- Draw lines on the screen by pinching (bringing the thumb and index finger close).
- Clear the drawing canvas by pressing a key.
- Save drawn points as a JSON file for later use.
- Python 3.7+
- OpenCV
- MediaPipe
- NumPy
- Clone the repository:
git clone https://github.com/your-username/hand-drawing-app.git cd hand-drawing-app - Install the required packages:
pip install -r requirements.txt
-
Run the application:
python hand_drawing.py
-
Use your webcam to interact with the application:
- Bring your thumb and index finger close to draw on the screen.
- Press
cto clear the canvas. - Press
qto quit the application.
-
After exiting, the drawing data will be saved to a file named
drawing_data.json.
q: Quit the application.c: Clear the canvas.
- The application generates a JSON file named
drawing_data.json, which contains the coordinates of the drawn points.
-
Hand Detection:
- The application uses MediaPipe to detect hand landmarks in real time from the webcam feed.
-
Drawing Logic:
- The distance between the thumb tip and index finger tip is calculated.
- If the distance is below a threshold, drawing mode is activated, and the index finger's coordinates are recorded.
-
Canvas Operations:
- The recorded coordinates are used to draw lines on the video frame.
- Pressing
cclears the list of recorded points, effectively clearing the canvas.
-
Data Saving:
- The coordinates of the drawn points are saved in a JSON file when the application exits.
- OpenCV: For capturing webcam feed and drawing.
- MediaPipe: For hand landmark detection.
- NumPy: For mathematical operations.
- MediaPipe for the excellent hand tracking module.
- OpenCV for real-time computer vision capabilities.
This project is licensed under the MIT License. Feel free to use and modify it as needed.
Contributions are welcome! If you have suggestions or improvements, feel free to submit a pull request.