A sophisticated computer vision application that allows you to control your mouse cursor using hand gestures captured through your webcam. Built with Python, OpenCV, and MediaPipe, this project enables natural and intuitive interaction with your computer.
- Hand Tracking: Real-time detection and tracking of hand landmarks
- Gesture-based Control: Control mouse movement and clicks using natural hand gestures
- Smooth Movement: Implemented smoothening algorithm for precise cursor control
- Performance Optimization: Real-time FPS counter to monitor performance
- Customizable Settings: Adjustable parameters for sensitivity and control area
pip install opencv-python
pip install mediapipe
pip install numpy
pip install autopy- Clone this repository
- Navigate to the project directory
- Run the main script:
python main.py-
Moving the Cursor:
- Raise your index finger
- Move your hand within the frame to control the cursor
- The cursor position is smoothed for better precision
-
Clicking:
- Raise both index and middle fingers
- Bring them close together to perform a click
- A green circle will appear when click is registered
wCam, hCam = 640, 480 # Camera resolution
frameR = 100 # Frame reduction for movement area
smoothening = 7 # Mouse movement smoothening factor-
HandTrackingModule.py:
- Custom module for hand detection and tracking
- Implements MediaPipe solutions for hand landmark detection
- Provides utilities for gesture recognition
-
main.py:
- Main application logic
- Implements mouse control functionality
- Handles gesture interpretation and cursor movement
- Uses MediaPipe's hand tracking solution
- Detects up to 21 hand landmarks
- Supports multiple hand tracking (configured for single hand in this application)
- Identifies finger positions and states (up/down)
- Calculates distances between landmarks
- Implements custom gesture patterns for mouse control
- Maps hand coordinates to screen coordinates
- Implements smoothening for precise movement
- Supports left-click functionality
You can modify the following parameters in main.py to adjust the application behavior:
wCam, hCam: Camera resolutionframeR: Movement area boundarysmoothening: Cursor movement smoothness
-
Camera not working:
- Check if camera index is correct in
cv2.VideoCapture(0) - Ensure camera permissions are granted
- Check if camera index is correct in
-
Jerky cursor movement:
- Increase the
smootheningvalue - Ensure adequate lighting conditions
- Increase the
-
Performance issues:
- Check the FPS counter in the top-left corner
- Reduce camera resolution if needed
- Ensure no resource-heavy applications are running
This project is open-source and available under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
- MediaPipe team for their excellent hand tracking solution
- OpenCV community for computer vision tools
- Autopy developers for mouse control functionality