Skip to content

A Python-based Virtual Mouse using Mediapipe for real-time hand tracking and OpenCV for gesture recognition. Control your computer cursor with hand gestures like point, click, drag, and scroll—no physical mouse needed! 🚀

Notifications You must be signed in to change notification settings

manumishra12/Virtual-Mouse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

Virtual Mouse Using Hand Tracking 🖱️

This project implements a Virtual Mouse that allows users to control their computer cursor using hand gestures. It leverages Mediapipe for real-time hand tracking and OpenCV for computer vision processing, providing an innovative and touch-free interface.

Results

Results


📖 Introduction

The Virtual Mouse enables cursor control through hand gestures, bypassing the need for traditional input devices. By detecting hand landmarks and interpreting gestures, it maps hand movements to cursor movements, making it a versatile tool for accessibility and innovation.


✨ Features

  • Real-time hand tracking using Mediapipe.
  • Click, drag, and scroll gestures.
  • Easy-to-use and lightweight solution.
  • Compatible with any webcam-enabled device.

⚙️ Requirements

  • Python 3.7+
  • OpenCV
  • Mediapipe
  • PyAutoGUI (for controlling mouse functions)
  • HandTrackingModule

💻 Installation

  1. Clone this repository:

    git clone https://github.com/username/virtual-mouse.git
    cd virtual-mouse
  2. Install the required dependencies:

pip install -r requirements.txt

🚀 Usage

  • Connect a webcam to your computer.

  • Run the script

    python virtual_mouse.py

🛠️ Technical Details

Hand Detection

  • Mediapipe detects 21 key landmarks on each hand.
  • These landmarks are analyzed to determine gestures and control logic.

Gesture Recognition

  • Specific hand gestures are mapped to mouse functions:
    • Single Finger Up: Cursor control.
    • Two Fingers Up: Click.
    • Pinch Gesture: Drag.
    • Closed Fist: Scroll.

Cursor Movement

  • The screen resolution and hand detection region are mapped using OpenCV to accurately translate hand movements into cursor movements.

Mouse Interaction

  • PyAutoGUI handles the actual mouse events, such as:
    • Moving the cursor.
    • Simulating left and right clicks.
    • Performing drag and drop.
    • Implementing scrolling functionality.

🚀 Future Enhancements

  • Add support for multi-hand gesture control.
  • Implement additional gestures for keyboard emulation.
  • Optimize performance for low-spec devices.
  • Explore 3D gesture-based interactions to enhance functionality.

🛠️ Steps to Run the Virtual Mouse in a Virtual Environment

1. Create a Virtual Environment

  • Open a terminal and navigate to the project directory.
  • Create a virtual environment using venv:
    python -m venv venv

2. Activate the Virtual Environment

  • Windows:
    .\venv\Scripts\activate
  • Linux/macOS:
    source venv/bin/activate

3. Install Required Dependencies

  • Install all the necessary packages from the requirements.txt file:
    pip install -r requirements.txt

4. Run the Virtual Mouse Script

  • Execute the Python script to start the Virtual Mouse:
    python virtual_mouse.py

5. Control the Mouse with Gestures

  • Ensure your webcam is connected and follow these gestures:
    • Index Finger Up: Move the cursor.
    • Index and Middle Finger Up: Left-click.
    • Pinch Gesture: Drag.
    • Closed Fist: Scroll.

🔄 Deactivating the Virtual Environment

  • To deactivate the virtual environment after you're done:
    deactivate

📋 Notes

  • Make sure your Python version is 3.7 or above.
  • Ensure the webcam is enabled and accessible by the script.
  • For better performance, use a well-lit environment for hand tracking.

Enjoy controlling your mouse with gestures! 🖐️ Feel free to contribute, suggest improvements, or report issues to make this project even better! 🚀

About

A Python-based Virtual Mouse using Mediapipe for real-time hand tracking and OpenCV for gesture recognition. Control your computer cursor with hand gestures like point, click, drag, and scroll—no physical mouse needed! 🚀

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published