An open API service indexing awesome lists of open source software.

https://github.com/prince1604/ctrl-gesture

๐Ÿ–ฑ๏ธ Ctrl+Gesture โ€” A contactless virtual mouse using Python, OpenCV & Mediapipe. Control cursor with hand gestures: left click, right click & movement in real time.
https://github.com/prince1604/ctrl-gesture

autopy machine-learning mediapipe opencv-python python

Last synced: 3 months ago
JSON representation

๐Ÿ–ฑ๏ธ Ctrl+Gesture โ€” A contactless virtual mouse using Python, OpenCV & Mediapipe. Control cursor with hand gestures: left click, right click & movement in real time.

Awesome Lists containing this project

README

          

# ๐Ÿ–ฑ๏ธ Virtual Mouse Using Hand Gestures

![Python](https://img.shields.io/badge/Python-3.8+-blue.svg)
![OpenCV](https://img.shields.io/badge/OpenCV-Image%20Processing-green.svg)
![Mediapipe](https://img.shields.io/badge/Mediapipe-Hand%20Tracking-orange.svg)
![Autopy](https://img.shields.io/badge/Autopy-Mouse%20Control-yellow.svg)
![License: MIT](https://img.shields.io/badge/License-MIT-red.svg)

An **AI-powered Virtual Mouse** that lets you control your computer using **hand gestures** โœ‹.
Built with **OpenCV, Mediapipe, and Autopy**, this project turns your webcam into a futuristic input device. ๐Ÿš€

---

## ๐Ÿ’ก Why This Project?

* Learn **computer vision** with a fun, practical build.
* Explore **gestureโ€‘based interfaces** used in AR/VR & accessibility tech.
* Beginnerโ€‘friendly code with clear comments and modular design.

---

> **Compatibility Note**
> โœ… This project supports **Python 3.8.9** and **pip 3.8.9**.
> โš ๏ธ Using other versions **may show errors** (install/compatibility issues).

---

## ๐ŸŒŸ Features

* ๐Ÿ–๏ธ Real-time **Hand Gesture Recognition**
* ๐Ÿ–ฑ๏ธ Move cursor using just your **index finger**
* ๐Ÿ‘† **Two fingers = Left Click**
* ๐Ÿ‘ **Thumb + Forefinger = Right Click**
* โœ‹ **Open palm = Resume program**
* โœŠ **Closed hand = Stop program**
* ๐ŸŽฅ Works with any **webcam**
* โšก Lightweight and beginner-friendly setup

---
## โœ… Requirements

* **Operating System:** Windows 10/11, macOS, or Ubuntu (with webcam access).
* **Python:** **3.8.9 only** (recommended).
* **pip:** **3.8.9** (paired with Python 3.8.9).
* **Camera:** Builtโ€‘in or USB webcam.

---
## ๐Ÿ› ๏ธ Tech Stack

* **Python 3.8.9** โ†’ Core language (โš ๏ธ Recommended version)
* **OpenCV** โ†’ Image processing
* **Mediapipe** โ†’ Hand tracking
* **Autopy** โ†’ Mouse movement and clicks
* **NumPy** โ†’ Computation

---

## ๐Ÿ”ง Installation Guide (Beginner Friendly)

1. **Clone the Repository**

```
git clone https://github.com/prince1604/Ctrl-Gesture.git
cd AI-Virtual-Mouse
```

2. **Create a Virtual Environment (Optional but Recommended)**

```bash
python -m venv .venv
source .venv/bin/activate # Linux/Mac
.venv\Scripts\activate # Windows
```

3. **Verify versions**

```bash
python --version # should be 3.8.9
pip --version # paired with Python 3.8.9
```
4. **Install dependencies**

```bash
pip install --upgrade pip
pip install -r requirements.txt
```
5. **Run the app**

```bash
python aivirtualmouseproject.py
```

โœ… If you face issues, ensure **Python & pip version = 3.8.9**. Otherwise, errors may appear.

๐Ÿ’Œ For help, contact: **[princekothiya1604@gmail.com](mailto:princekothiya1604@gmail.com)**

---

## ๐ŸŽฎ How to Use

1. Place your **hand in front of the camera**.
2. Gestures:

* ๐Ÿ‘‰ One finger โ†’ Move cursor
* โœŒ๏ธ Two fingers โ†’ Left click
* ๐ŸคŸ Three fingers โ†’ Right click
* โœ‹ Open palm โ†’ Resume program
* โœŠ All fingers closed โ†’ Stop program
3. To exit, press **Ctrl + C** or close the window.

---

## ๐Ÿ”ง Configuration Tips

You can tweak behavior in `aivirtualmouseproject.py`:

* **Camera index** (default webcam = `0`):

```python
cap = cv2.VideoCapture(0) # try 1 or 2 if you have multiple cameras
```
* **Resolution** (smoother on lowโ€‘end systems):

```python
wCam, hCam = 640, 480
cap.set(3, wCam)
cap.set(4, hCam)
```
* **Smoothing & frame reduction** (reduce jitter):

```python
frameR = 100 # reduce active region near edges
smoothening = 7 # increase to reduce cursor jitter
```

---

## ๐Ÿงฐ Troubleshooting (Beginner Friendly)

**1) Camera not opening / Black window**

* Close other apps using the camera (Zoom/Meet).
* Change camera index: `cv2.VideoCapture(0)` โ†’ `cv2.VideoCapture(1)` or `2`.

**2) `ModuleNotFoundError: cv2 / mediapipe / autopy`**

* Ensure your **virtual environment is activated** before installing.
* Run: `pip install -r requirements.txt`.

**3) AutoPy fails to install (Windows)**

* Install **Build Tools for Visual Studio** (C++ tools) if prompted.
* If issues persist, try: `pip install pyautogui` and adapt code to use PyAutoGUI for mouse control.

**4) macOS: โ€œApp needs camera accessโ€**

* Go to **System Settings โ†’ Privacy & Security โ†’ Camera** and allow Terminal/IDE access.

**5) Cursor is jittery / laggy**

* Increase `smoothening` value and ensure good lighting.
* Lower camera resolution to `640ร—480`.

**6) Wrong Python version detected**

* Install **Python 3.8.9** and reโ€‘run

If you still face issues, feel free to **contact** me (see below). I usually respond quickly.

---

## ๐Ÿ—‚๏ธ Project Structure

```
AI-Virtual-Mouse/
โ”œโ”€ aivirtualmouseproject.py # Main application (run this)
โ”œโ”€ HandTrackingModule.py # Hand landmark detection utils
โ”œโ”€ volume.py # (Optional) volume control via gestures
โ”œโ”€ requirements.txt # Pinned dependencies
โ”œโ”€ README.md # This file
โ””โ”€ LICENSE # MIT License
```
---

## ๐Ÿ“Š Workflow (Easy-to-Understand Diagram)

![Workflow Diagram](./docs/virtual-mouse-flow.png)

**Simple Steps in Workflow:**

1. Capture **Image Input** ๐ŸŽฅ
2. Detect & Segment Hand โœ‹
3. Preprocess โ†’ Grayscale, Filter, Enhance ๐Ÿ–ผ๏ธ
4. Extract Hand Region โœ‚๏ธ
5. Analyze Features ๐Ÿ”
6. Classify Gesture ๐Ÿค–
7. Perform Mouse Action ๐Ÿ–ฑ๏ธ

---

## ๐Ÿค Contributing

We โค๏ธ contributions!

1. **Fork** the repo
2. **Create a feature branch** (`feat/yourโ€‘idea`)
3. **Commit** your changes
4. **Open a Pull Request**

For major features, please open an **issue** first to discuss your proposal.

---

## ๐Ÿ“œ License

Licensed under **MIT License** โ€“ see [LICENSE](LICENSE).

---
## ๐Ÿ“ฌ Contact

Questions or bugs? Email **[princekothiya1604@gmail.com](mailto:princekothiya1604@gmail.com)**
You can also open a **GitHub Issue** with detailed logs/screenshots.
---