Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

19 Commits

Folders and files

Repository files navigation

🎭 Real-Time Emotion Detection with Python & AI

Python OpenCV Keras Status

emotion-detection-demo


📸 What is this project?

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:

  1. Opens your webcam 🖥️
  2. Detects your face 🤖
  3. Predicts your current emotion (😄 😠 😢 😲 😐)
  4. Displays it with a label and a confidence score 📊

It's like building your own mini-JARVIS to read human emotions!


🧠 Technologies Used

Tool Role
Python Programming language
OpenCV Access webcam & detect faces
TensorFlow / Keras Load the emotion detection model
NumPy Handle image data efficiently

🎯 What You Will Learn

✅ 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


🧪 How it Works – Real Life Analogy

🔍 Imagine this:

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!"


📦 Setup Instructions

🕐 Total setup time: ~5–10 minutes

1. Clone the repo

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.py

Look at your webcam 👀 — a rectangle should appear around your face with a label like: Happy (92.3%)

📌 Press q to quit the app.


🧠 Code Structure Explained

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 😄

🖼️ Why Convert to Grayscale?

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

🎉 Bonus Ideas for Fun

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

⚠️ Troubleshooting

❌ 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 numpy

🤝 Contributing

If you want to improve the UI, add sounds, or implement face tracking, feel free to open a pull request!


📜 License

This project is licensed under the MIT License.


🧑‍🏫 Credits

Model originally from oarriaga/face_classification

Created with ❤️ for learning purposes.


🌈 Final Thought

“If you can make a computer understand a smile, you're already a magician.” 🎩✨

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages