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
- Host: GitHub
- URL: https://github.com/aayushinit/aibackgroundsubtractor
- Owner: Aayushinit
- License: mit
- Created: 2025-07-08T07:40:19.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-07-08T07:54:14.000Z (6 months ago)
- Last Synced: 2025-07-08T08:22:17.158Z (6 months ago)
- Topics: ai-project, background-subtraction, computer-vision, flask, image-processing, knn, mog2, opencv, python, realtime, tailwindcss, video-processing, webcam
- Language: HTML
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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!