Skip to content

AirCursor: Control your mouse with hand gestures! Uses webcam, MediaPipe, and OpenCV for touchless cursor movement, clicks, and scrolling. 🖐️🖱️

License

Notifications You must be signed in to change notification settings

Pythonpreran/Aircursor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AirCursor: Gesture-Based Cursor Control

Python

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.

Features

  • 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.

Demo

ezgif-72ff60e342241d (1)

Requirements

  • Python 3.11
  • A webcam
  • Required Python packages (see requirements.txt below)

requirements.txt

opencv-python==4.9.0.80
PyAutoGUI==0.9.54
mediapipe==0.10.21

Installation

  1. Clone the Repository:

    git clone https://github.com/Pythonpreran/Aircursor.git
    cd Aircursor
  2. Set Up a Virtual Environment (recommended):

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install Dependencies:

    pip install -r requirements.txt
  4. Ensure Webcam Access:

    • Connect a webcam and ensure it’s accessible.
    • Grant camera permissions as needed.

Usage

  1. Run the Script:

    python aircursor.py
  2. 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 ESC to close the application.
  3. 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.

How It Works

  • 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.

Configuration

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.

Troubleshooting

  • 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.

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/your-feature).
  3. Commit changes (git commit -m "Add your feature").
  4. Push to the branch (git push origin feature/your-feature).
  5. Open a pull request.

License

This project is licensed under the Apache 2.0 License.

Acknowledgments

  • MediaPipe for robust hand tracking.
  • PyAutoGUI for mouse and keyboard control.
  • Inspired by innovative touchless interface solutions.

Contact

For issues or suggestions, open an issue on GitHub or contact Pythonpreran.

About

AirCursor: Control your mouse with hand gestures! Uses webcam, MediaPipe, and OpenCV for touchless cursor movement, clicks, and scrolling. 🖐️🖱️

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages