This project enables controlling the computer mouse using hand gestures captured by a webcam. It utilizes the OpenCV and Mediapipe libraries to detect and track hand landmarks, and performs actions based on specific gestures.
- Python 3.x
- OpenCV library
- Mediapipe library
- Numpy library
- PyAutoGUI library
The project consists of two main files:
-
handtracking2d.py
: This file contains thehandDetector
class, which encapsulates the hand detection and tracking functionality. It utilizes thempHands
module from Mediapipe to detect hand landmarks and provides methods for finding hands, positions, finger states, distances, etc. Themain
function sets up the webcam, initializes thehandDetector
, and continuously processes video frames to detect and track hand gestures. -
mouse.py
: This file enables mouse control using hand gestures. It imports thehandDetector
class fromhandtracking2d.py
and utilizes it to detect hand landmarks and recognize specific gestures. It captures video frames from the webcam, tracks the movement of the index finger, and moves the mouse cursor accordingly. It also detects when the index and middle fingers are close together to simulate a mouse click.
-
Install the necessary libraries by running the following command:
pip install opencv-python mediapipe numpy pyautogui
The project assumes that a single hand is being tracked at a time. If multiple hands are present, only the first detected hand will be considered for mouse control.
The project incorporates smoothening techniques to reduce cursor jitter and improve usability. The project provides visual feedback by overlaying circles on the video frames to indicate the active modes (moving or clicking) and the cursor position.