# Emotion Detector (Django + MediaPipe + OpenCV)
A real-time webcam-based emotion detection application built as a Django assignment project. It uses MediaPipe and OpenCV to detect facial landmarks and classify emotions—Happy, Sad, or Neutral—in live video streams.
---
## 🧠 Features
- Real-time emotion detection via webcam.
- Detects **Happy**, **Sad**, and **Neutral** emotions.
- Utilizes **MediaPipe** for facial landmark tracking.
- Displays emotion overlays on video frames using **OpenCV**.
- Cleanly integrated into a Django backend.
---
## 🛠️ Tech Stack
| Component | Technology |
|------------------|----------------|
| Backend Framework| Django |
| Video Processing | OpenCV |
| Landmark Detection | MediaPipe |
| Numerical Computation | NumPy |
| UI | HTML / CSS / JS (via Django templates) |
---
## ⚙️ Installation & Setup
1. **Clone the repository**
```bash
git clone https://github.com/devesssi/emotion-detect-mediapipe-opencv-.git
cd emotion-detect-mediapipe-opencv-
-
Set up a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Apply Django migrations
python manage.py migrate
-
Run the development server
python manage.py runserver
-
Access the web app
Visit
http://127.0.0.1:8000/
in your browser. Grant webcam access when prompted to start emotion detection.
emotion-detect-mediapipe-opencv-/
│
├── emotion_detector/ # Django application
│ ├── migrations/
│ ├── views.py # Handles video streaming and processing
│ ├── urls.py # Routes for the app
│ └── templates/ # HTML templates (index.html, etc.)
│
├── emotion_detector.py # Standalone script (if present)
├── manage.py # Django management script
├── requirements.txt # Project dependencies
└── README.md # Project documentation
- When you access the app in your browser, it initializes the webcam.
- OpenCV captures video frames.
- MediaPipe processes each frame to find facial landmarks.
- A simple expression classifier (based on NumPy thresholds or distances) categorizes emotions.
- The current emotion label is overlayed on the video feed and sent back to the web client via Django's streaming view.
- Happy
- Sad
- Neutral
-

(These are the only emotions currently supported, but more can be added by extending the logic.)
- Launch the app:
python manage.py runserver
- Open your browser to
http://127.0.0.1:8000/
- Allow webcam permissions, then observe real-time emotion detection.
This project is built as an academic assignment. It focuses on:
- Integrating MediaPipe and OpenCV in a Django environment.
- Real-time emotion tracking from live webcam data.
- Simple yet effective algorithm for classifying basic emotions.
- Add more emotion classes (e.g. angry, surprised).
- Improve classifier using ML (e.g. train lightweight ConvNet).
- Option to record and download emotion logs.
- Enhance front-end for better UI/UX and performance.
As an assignment project, direct contributions are limited. However, feedback, bug reports, or suggestions are welcome via GitHub Issues.
This project is licensed under the MIT License. © 2025 devesssi