This Python script utilizes OpenCV, MediaPipe, and PyAutoGUI to implement a virtual mouse that tracks hand movements via a webcam. It enables cursor movement and clicking using hand gestures.
π₯ Preview Video
- Tracks hand movements in real-time using a webcam.
- Moves the cursor based on the index finger's position.
- Clicks when the thumb and index finger come close together.
- Uses OpenCV for video processing and MediaPipe for hand tracking.
- Python 3.x installed on your system.
- Required Python libraries:
opencv-pythonmediapipepyautogui
- Ensure Python is installed by running:
python --version
- Install dependencies using:
pip install opencv-python mediapipe pyautogui
- Run the script:
python script.py
- Ensure your webcam is on and positioned properly.
- Move your index finger to control the cursor.
- Bring your thumb close to your index finger to simulate a mouse click.
- Adjust the sensitivity if needed by modifying the script.
- Download or copy the script to your local system.
- Ensure all dependencies are installed.
- Open a command prompt or terminal.
- Navigate to the scriptβs directory using:
cd path/to/your/script - Run the script:
python script.py
- Move your hand in front of the webcam to control the cursor.
- To click, bring your thumb and index finger close together.
- Captures video feed using OpenCV.
- Processes frames using MediaPipe to detect hand landmarks.
- Moves the mouse based on the index fingerβs position.
- Performs a click when the thumb and index finger are close together.
Virtual Mouse Activated
Cursor Moving...
Click Detected!
- Ensure your hand is visible to the webcam for optimal tracking.
- Adjust sensitivity by modifying the threshold values in the script.
- Works best in well-lit environments.
Pull requests are welcome! Feel free to fork and help improve this project!
Made by Muhammad Yusuf Aditiya (Myfza)
π GitHub | LinkedIn