This is a beginner-friendly, real-time Emotion Detection App using your webcam, powered by Artificial Intelligence (AI) and Computer Vision.
When you run the app, it:
- Opens your webcam 🖥️
- Detects your face 🤖
- Predicts your current emotion (😄 😠 😢 😲 😐)
- Displays it with a label and a confidence score 📊
It's like building your own mini-JARVIS to read human emotions!
| Tool | Role |
|---|---|
Python |
Programming language |
OpenCV |
Access webcam & detect faces |
TensorFlow / Keras |
Load the emotion detection model |
NumPy |
Handle image data efficiently |
✅ How to work with webcam in Python using OpenCV
✅ What is a pre-trained AI model and how to use it
✅ How to detect faces using Haar Cascades
✅ How to feed images to a deep learning model
✅ How to interpret prediction results
You’re a kid learning emotions from thousands of faces: smiling, frowning, surprised.
That’s exactly what this pre-trained AI model has done.
It has seen thousands of labeled images, and now it's like an emotion expert.
When it sees a new face, it says:
"Hmm 🤔 this looks like a happy face — I’m 92% sure it’s happy!"
🕐 Total setup time: ~5–10 minutes
git clone https://github.com/yourusername/emotion-detector-ai.git
cd emotion-detector-ai
### 2. Install dependencies
Run this command in your terminal to install all required Python libraries:
```bash
pip install opencv-python numpy keras tensorflow
````markdown
### 3. Download the Pre-trained Model
Download the `.hdf5` model file from this link:
👉 [fer2013_mini_XCEPTION.102-0.66.hdf5](https://github.com/oarriaga/face_classification/raw/master/trained_models/emotion_models/fer2013_mini_XCEPTION.102-0.66.hdf5)
Place the downloaded file inside your project folder.
---
### 4. Run the App
Run the following command to start the emotion detection app:
```bash
python emotion_detection.pyLook at your webcam 👀 — a rectangle should appear around your face with a label like: Happy (92.3%)
📌 Press q to quit the app.
| Part | What it does |
|---|---|
cv2.VideoCapture(0) |
Opens your webcam |
haarcascade_frontalface*.xml |
Pre-trained file to detect faces |
model.predict(...) |
Predicts your emotion |
cv2.rectangle(...) |
Draws a box around your face |
cv2.putText(...) |
Writes the emotion name above your head 😄 |
Color images have 3 layers: Red, Green, Blue (RGB). That's too much data for face detection!
Grayscale simplifies it into 1 channel (black & white), which makes:
- ⚡ Detection faster
- 🧠 Training simpler
- ✅ Results just as good
| Idea | Description |
|---|---|
| 🔊 Emotion Soundboard | Play a sound depending on your emotion (e.g., cheering for "Happy") |
| 📸 Auto Screenshot | Save a picture when you look "Surprised" 😲 |
| 📊 Emotion Chart | Show live statistics of your mood over 1 minute |
❌ Webcam doesn’t open?
Make sure no other app is using it. Close Zoom, Teams, etc.
❌ No face detected?
Make sure there’s enough light, and your face is facing forward.
❌ Module not found?
Reinstall dependencies:
pip install opencv-python keras tensorflow numpyIf you want to improve the UI, add sounds, or implement face tracking, feel free to open a pull request!
This project is licensed under the MIT License.
Model originally from oarriaga/face_classification
Created with ❤️ for learning purposes.
“If you can make a computer understand a smile, you're already a magician.” 🎩✨
