In this project, we utilize a webcam to create a virtual mouse using hand tracking. By leveraging the live feed from the webcam, we can control a virtual mouse with hand gestures, eliminating the need for a physical mouse. The hand detection is focused on the forefinger and middle finger, where the forefinger acts as the cursor. Moving the forefinger around moves the cursor, and bringing the forefinger and middle finger together performs a click action.
To ensure smooth cursor movement, a smoothness factor is applied to reduce shakiness.
To ensure the project functions correctly, the following modules must be installed:
-
OpenCV: An extensive open-source library for computer vision, machine learning, and image processing. OpenCV supports various programming languages, including Python, C++, and Java. It can be installed using
pip install opencv-python
. -
Mediapipe: A framework for building multimodal (e.g., video, audio, time series data), cross-platform (Android, iOS, web, edge devices) applied ML pipelines. Install it with
pip install mediapipe
. -
Autopy: A cross-platform GUI automation library for Python that includes functions for controlling the keyboard and mouse, finding colors and bitmaps on-screen, and displaying alerts. Install it using
pip install autopy
.
This project may encounter dependency issues. Here are some common issues and their solutions:
- Autopy Installation Issues: Autopy does not support Python versions above 3.8.
- Webcam Not Opening: This was a bug in Mediapipe, fixed in later Python versions.
To ensure smooth execution, you need to downgrade your Python version to 3.8.
Follow these steps to downgrade Python:
- Uninstall Python from the Add/Remove Programs.
- Navigate to AppData and delete any remaining Python folders.
- Download and install Python 3.8 from the official Python website.
- Confirm the installation by running
pip
in the command prompt.
By following these steps, your Python version should be downgraded successfully, allowing the project to run smoothly.