A Python-based virtual mouse that lets you control your computer cursor with hand gestures using your webcam. This project utilizes OpenCV for image processing, MediaPipe for real-time hand tracking, and PyAutoGUI to simulate mouse actions.
- ποΈ Hand tracking with high accuracy using MediaPipe
- π±οΈ Cursor movement using index finger
- π Left click with index + middle finger pinch
- π€ Right click with index + ring finger pinch
- π Extendable for scroll and drag gestures
- Python 3.8+
- OpenCV β for video capture and processing
- MediaPipe β for hand landmark detection
- PyAutoGUI β for mouse control
You can install all dependencies with:
pip install -r requirements.txt
pip install opencv-python mediapipe pyautogui
- Clone the Repository
git clone https://github.com/yourusername/virtual-mouse-opencv.git
cd virtual-mouse-opencv
- Run the Script
python virtual_mouse.py
Make sure your webcam is connected and accessible.
-
The webcam feed is processed frame by frame using OpenCV.
-
MediaPipe detects and tracks 21 hand landmarks.
-
Coordinates of the index finger tip are used to move the cursor.
-
Distance between specific fingers determines click actions:
- Left Click: Pinch index and middle fingers
- Right Click: Pinch index and ring fingers
virtual-mouse/
β
βββ virtual_mouse.py # Main Python script
βββ README.md # Project readme
βββ requirements.txt # Python package dependencies
βββ screenshots/
Watch the original tutorial by Murtazaβs Workshop:
π YouTube Video
Built based on the tutorial by Murtazaβs Workshop - Robotics and AI.
This project is licensed under the MIT License. Feel free to use and modify for learning purposes.
If you have questions or improvements, feel free to raise an issue or contribute via pull request.