This project implements a virtual mouse control system using hand gestures captured through a webcam. It utilizes computer vision techniques to detect hand movements and translates them into mouse actions on your computer.
- Mouse Cursor Movement
- Left Click
- Right Click
- Double Click
- Click and Drag
- Scrolling
- Zooming
- Clone this repository or download the source code.
- Install the required packages:
pip install -r requirments.txt
- Ensure you have the
hand.py
file in the same directory as the main script. - Place a
cursor.png
file in aCursor
folder in the same directory (optional, for custom cursor overlay).
Run the script using Python:
python virtual_mouse.py
Hold your hand up to the webcam and use the following gestures to control the mouse:
- Hold up your index finger (fingers: 0,1,0,0,0)
- Move your hand to control the cursor position
- Hold up your index and middle fingers, forming an L-shape (fingers: 0,1,1,0,0)
- Bend your index finger slightly to perform a left click
- Hold up your index, middle, and ring fingers (fingers: 0,1,1,1,0)
- Hold up all fingers except the thumb (fingers: 0,1,1,1,1)
- Pinch your index finger and thumb together
- Move your hand to drag items on the screen
- Hold up your thumb and index finger in an L-shape (fingers: 1,1,0,0,0)
- Move your hand up or down to scroll
- Zoom In: Hold up your thumb, index finger, and pinky (fingers: 1,1,0,0,1)
- Zoom Out: Hold up all fingers (fingers: 1,1,1,1,1)
- Close all fingers (make a fist) to exit the program
- Alternatively, press 'q' on your keyboard while the webcam window is active
You can adjust various parameters in the script to fine-tune the behavior:
CURSOR_WIDTH
andCURSOR_HEIGHT
: Size of the cursor overlaySCROLL_THRESHOLD
: Sensitivity of scrollingPINCH_THRESHOLD
: Distance threshold for pinch detectionANGLE_THRESHOLD_MIN
andANGLE_THRESHOLD_MAX
: Angle range for left click detectionL_ANGLE_MIN
andL_ANGLE_MAX
: Angle range for scroll mode detection
-
If the cursor movement is too sensitive or not sensitive enough, adjust the
smoothing
andspeed_multiplier
variables in themove_cursor
function. -
If gesture detection is unreliable, try adjusting the lighting conditions or the
detectionCon
andtrackCon
parameters when initializing thehandDetector
.
- The system is designed for single-hand use only.
- Performance may vary depending on lighting conditions and webcam quality.
- Some gestures might require practice to perform consistently.
Feel free to fork this project and submit pull requests with improvements or additional features.
This project is open-source and available under the MIT License.# virtual-mouse