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

https://github.com/aayushinit/aibackgroundsubtractor

Real-time background subtraction using OpenCV + Flask with switchable detection algorithms and stylish frontend
https://github.com/aayushinit/aibackgroundsubtractor

ai-project background-subtraction computer-vision flask image-processing knn mog2 opencv python realtime tailwindcss video-processing webcam

Last synced: 6 months ago
JSON representation

Real-time background subtraction using OpenCV + Flask with switchable detection algorithms and stylish frontend

Awesome Lists containing this project

README

          

# ๐Ÿง  AI Background Subtractor

A real-time background subtraction web application built using **Python**, **OpenCV**, and **Flask**. It features dynamic foreground detection using classic computer vision algorithms โ€” **KNN** and **MOG2** โ€” with a smooth, modern UI.

---

## ๐Ÿš€ Features

- ๐Ÿ“ธ Live Webcam Feed
- โœ‚๏ธ Real-time Background Subtraction
- ๐Ÿง  Toggle Between KNN and MOG2 Algorithms
- ๐ŸŒˆ Colored Foreground & Shadow Detection (Green = Foreground, Red = Shadows)
- ๐Ÿ–ผ๏ธ Side-by-Side Original vs Processed Display
- ๐Ÿงช Algorithm Selection UI
- ๐ŸŽจ Stylish Tailwind CSS Interface
- โœ… Fully Local Python-Flask App (No external API needed)

---

## ๐Ÿ“‚ Folder Structure

```
AiBackgroundSubtractor/
โ”œโ”€โ”€ templates/
โ”‚ โ””โ”€โ”€ index.html # Web UI
โ””โ”€โ”€ app.py # Flask backend with OpenCV logic
```

---

## โš™๏ธ Technologies Used

| Technology | Purpose |
|-----------------|------------------------------------------|
| **Python** | Backend logic and OpenCV processing |
| **OpenCV** | Video capture and background subtraction |
| **Flask** | Local web server and API routes |
| **Tailwind CSS**| Modern, responsive UI styling |
| **HTML / JS** | Frontend structure and interactivity |

---

## ๐ŸŽฏ How It Works

- Your webcam provides a live video stream via **OpenCV**.
- Each frame is processed by a **background subtractor**:
- `KNN`: K-Nearest Neighbors method.
- `MOG2`: Gaussian Mixture Model approach.
- Foreground and shadows are highlighted using color masks:
- ๐ŸŸฉ Foreground โ†’ Green
- ๐ŸŸฅ Shadows โ†’ Red
- The processed output is streamed in real-time alongside the raw feed.

---

## ๐Ÿ› ๏ธ How to Run Locally

1. **Clone the repository**:
```bash
git clone https://github.com/Aayushinit/AiBackgroundSubtractor.git
cd AiBackgroundSubtractor
```

2. **Install dependencies**:
```bash
pip install flask opencv-python
```

3. **Run the app**:
```bash
python app.py
```

4. **View in browser**:
Open [http://127.0.0.1:5000](http://127.0.0.1:5000) in your browser.

> ๐Ÿ“ธ Make sure your webcam is connected and not being used by another app.

---

## ๐Ÿ“Œ Use Cases

- Motion detection and surveillance
- Human-computer interaction projects
- Educational demos for Computer Vision
- Lightweight vision system for robotics

---

## ๐Ÿ“ƒ License

This project is licensed under the [MIT License](LICENSE).

---

## ๐Ÿ‘จโ€๐Ÿ’ป Author

**Aayush Kadam**
Final Year AI & Robotics Enthusiast
GitHub: [github.com/your-username](https://github.com/Aayushinit)

---

---

> โญ If you found this project useful, give it a star and share it!