Real-Time Emotion Detection using CNN

Samrat

Samrat Ghorui

๐Ÿ˜Š Real-Time Emotion Detection using CNN

This project detects human emotions (like Happy, Sad, Angry, etc.) in real-time using your webcam, powered by Convolutional Neural Networks (CNN) and OpenCV.

๐Ÿ“ Project Structure

real-time-emotion-detection/
โ”‚
โ”œโ”€โ”€ emotion_detector.py # Main Python script to run the model
โ”œโ”€โ”€ emotion_model.h5 # Trained CNN model file
โ”œโ”€โ”€ haarcascade_frontalface.xml # Haar Cascade for face detection
โ”œโ”€โ”€ README.md # Project documentation

๐Ÿง  Emotion Classes Detected

Angry
Disgust
Fear
Happy
Sad
Surprise
Neutral

๐Ÿ“ฆ Step-by-Step Setup Instructions

โœ… 1. Prerequisites

Python 3.7 or higher
Webcam (built-in or external)

๐Ÿ“ 2. Clone the Repository

git clone https://github.com/samrat0033/Emotion_Detection.git
cd Emotion-Detection

๐Ÿงช 3. Create a Virtual Environment (Optional but Recommended)

python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate

๐Ÿ“š 4. Install Required Libraries

pip install keras tensorflow numpy opencv-python

๐ŸŽฏ 5. Run the Application

Make sure the files emotion_model.h5 and haarcascade_frontalface.xml are in the same directory as your Python script.
python emotion_detector.py
This will activate your webcam and start detecting emotions in real time.

๐Ÿง  Libraries Used

Keras โ€“ For loading the pre-trained CNN model
TensorFlow โ€“ Backend for Keras
OpenCV โ€“ For webcam access and face detection
NumPy โ€“ For image array manipulation

โš™๏ธ How It Works

The webcam feed is captured using cv2.VideoCapture().
Faces are detected in each frame using Haar Cascades.
The face region is preprocessed and passed through a CNN model.
The model outputs an emotion class which is displayed on the screen.

๐Ÿ–ผ๏ธ Sample Output

Emotion label is overlaid on the detected face in real-time video feed.

๐Ÿ“ž Contact

For questions, suggestions, or collaboration:
Like this project

Posted May 29, 2025

Developed a real-time emotion detection system using CNN and OpenCV.