This project implements a Virtual Mouse that allows users to control their computer cursor using hand gestures. It leverages Mediapipe for real-time hand tracking and OpenCV for computer vision processing, providing an innovative and touch-free interface.
The Virtual Mouse enables cursor control through hand gestures, bypassing the need for traditional input devices. By detecting hand landmarks and interpreting gestures, it maps hand movements to cursor movements, making it a versatile tool for accessibility and innovation.
- Real-time hand tracking using Mediapipe.
- Click, drag, and scroll gestures.
- Easy-to-use and lightweight solution.
- Compatible with any webcam-enabled device.
- Python 3.7+
- OpenCV
- Mediapipe
- PyAutoGUI (for controlling mouse functions)
- HandTrackingModule
-
Clone this repository:
git clone https://github.com/username/virtual-mouse.git cd virtual-mouse
-
Install the required dependencies:
pip install -r requirements.txt
🚀 Usage
-
Connect a webcam to your computer.
-
Run the script
python virtual_mouse.py
- Mediapipe detects 21 key landmarks on each hand.
- These landmarks are analyzed to determine gestures and control logic.
- Specific hand gestures are mapped to mouse functions:
- Single Finger Up: Cursor control.
- Two Fingers Up: Click.
- Pinch Gesture: Drag.
- Closed Fist: Scroll.
- The screen resolution and hand detection region are mapped using OpenCV to accurately translate hand movements into cursor movements.
- PyAutoGUI handles the actual mouse events, such as:
- Moving the cursor.
- Simulating left and right clicks.
- Performing drag and drop.
- Implementing scrolling functionality.
- Add support for multi-hand gesture control.
- Implement additional gestures for keyboard emulation.
- Optimize performance for low-spec devices.
- Explore 3D gesture-based interactions to enhance functionality.
- Open a terminal and navigate to the project directory.
- Create a virtual environment using
venv
:python -m venv venv
- Windows:
.\venv\Scripts\activate
- Linux/macOS:
source venv/bin/activate
- Install all the necessary packages from the
requirements.txt
file:pip install -r requirements.txt
- Execute the Python script to start the Virtual Mouse:
python virtual_mouse.py
- Ensure your webcam is connected and follow these gestures:
- Index Finger Up: Move the cursor.
- Index and Middle Finger Up: Left-click.
- Pinch Gesture: Drag.
- Closed Fist: Scroll.
- To deactivate the virtual environment after you're done:
deactivate
- Make sure your Python version is 3.7 or above.
- Ensure the webcam is enabled and accessible by the script.
- For better performance, use a well-lit environment for hand tracking.
Enjoy controlling your mouse with gestures! 🖐️ Feel free to contribute, suggest improvements, or report issues to make this project even better! 🚀