AirCursor is a Python application that enables touchless cursor control using hand gestures captured via a webcam. It uses computer vision and hand tracking to move the mouse cursor, perform left and right clicks, and scroll based on specific hand gestures.
- Cursor Movement: Track the index finger tip to move the cursor across the screen.
- Left Click: Pinch gesture (thumb and index finger close together).
- Right Click: Fingers folded with thumb held horizontally.
- Scroll: Fist gesture with vertical hand movement.
- Real-time hand tracking with visual feedback via webcam feed.
- Python 3.11
- A webcam
- Required Python packages (see
requirements.txtbelow)
opencv-python==4.9.0.80
PyAutoGUI==0.9.54
mediapipe==0.10.21-
Clone the Repository:
git clone https://github.com/Pythonpreran/Aircursor.git cd Aircursor -
Set Up a Virtual Environment (recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Ensure Webcam Access:
- Connect a webcam and ensure it’s accessible.
- Grant camera permissions as needed.
-
Run the Script:
python aircursor.py
-
Gestures:
- Move Cursor: Point your index finger to move the cursor.
- Left Click: Pinch thumb and index finger together (distance < 40 pixels).
- Right Click: Fold index finger (tip below DIP joint) and keep thumb horizontal.
- Scroll: Make a fist and move hand vertically to scroll (threshold > 15 pixels).
- Exit: Press
ESCto close the application.
-
Visual Feedback:
- A window (
AirCursor) shows the webcam feed with hand landmarks and gesture status (e.g., "Moving", "Left Click Down", "Scrolling"). - Ensure your hand is well-lit and visible to the webcam.
- A window (
- Hand Tracking: Utilizes MediaPipe Hands for real-time hand landmark detection.
- Gesture Detection:
- Cursor movement maps the index finger tip’s position to screen coordinates.
- Left click is triggered when thumb and index finger are close (distance < 40 pixels).
- Right click requires a folded index finger and horizontal thumb.
- Scrolling activates with a fist gesture, using vertical hand movement.
- Dependencies:
opencv-python: Handles webcam input and visual output.PyAutoGUI: Controls mouse movements, clicks, and scrolling.mediapipe: Provides hand tracking functionality.math.hypot: Calculates distances between landmarks for gesture detection.
Adjust the following thresholds in aircursor.py for better performance:
CLICK_THRESHOLD(default: 40): Distance for pinch-based left click.SCROLL_DIST_THRESHOLD(default: 15): Minimum vertical movement for scrolling.FIST_DISTANCE_THRESHOLD(default: 80): Distance to detect a fist for scrolling.
- Webcam Not Detected: Verify webcam connection and permissions. Try a different USB port or webcam.
- Poor Gesture Detection: Improve lighting, keep hand in frame, or adjust
min_detection_confidence(default: 0.8) in the code. - Lag or Performance Issues: Reduce webcam resolution or tweak thresholds for responsiveness.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature). - Commit changes (
git commit -m "Add your feature"). - Push to the branch (
git push origin feature/your-feature). - Open a pull request.
This project is licensed under the Apache 2.0 License.
- MediaPipe for robust hand tracking.
- PyAutoGUI for mouse and keyboard control.
- Inspired by innovative touchless interface solutions.
For issues or suggestions, open an issue on GitHub or contact Pythonpreran.
