A real-time emotion recognition system using a Convolutional Neural Network (CNN) trained on the FER2013 dataset. Detects 7 emotions live from a webcam feed using OpenCV for face detection.
| Metric | Score |
|---|---|
| Test Accuracy | 66.59% |
| Best Epoch | 46 |
| Dataset | FER2013 (35,000+ images) |
| Emotions | 7 classes |
| Emotion | Precision | Recall | F1-Score |
|---|---|---|---|
| 😊 Happy | 0.87 | 0.84 | 0.86 |
| 😲 Surprise | 0.76 | 0.83 | 0.80 |
| 🤢 Disgust | 0.75 | 0.56 | 0.64 |
| 😠 Angry | 0.57 | 0.59 | 0.58 |
| 😐 Neutral | 0.62 | 0.63 | 0.62 |
| 😢 Sad | 0.53 | 0.56 | 0.55 |
| 😨 Fear | 0.54 | 0.48 | 0.51 |
- Real-time emotion detection from webcam
- Detects and tracks faces automatically using OpenCV
- Supports 7 primary emotions
- Runs entirely on local hardware — no cloud or API required
- Trained on FER2013 (35,000+ labelled facial images)
| Layer | Technology |
|---|---|
| Deep Learning | TensorFlow / Keras |
| Computer Vision | OpenCV |
| Model Type | Convolutional Neural Network (CNN) |
| Dataset | FER2013 (Kaggle) |
| Language | Python |
1. Clone the repo
git clone https://github.com/manny2341/Emotion-Detection.git
cd Emotion-Detection2. Create a virtual environment
python3 -m venv venv
source venv/bin/activate3. Install dependencies
pip install -r requirements.txt4. Download the FER2013 dataset
Download from Kaggle and place it in the project folder.
5. Process the data
python3 data_processing.py6. Train the model
python3 train_model.py7. Run live emotion detection
python3 emotion_detection.pyPress Q to quit the webcam window.
Emotion-Detection/
├── data_processing.py # Prepares and processes FER2013 dataset
├── train_model.py # Builds and trains the CNN model
├── emotion_detection.py # Live webcam emotion detection
├── Emotion_Detection.h5 # Saved trained model
├── training_history.png # Accuracy and loss curves
├── haarcascade_frontalface_default.xml # OpenCV face detector
└── requirements.txt
- OpenCV captures video from the webcam frame by frame
- Haar Cascade detects face regions in each frame
- Detected face is resized to 48×48 pixels and converted to grayscale
- CNN predicts the emotion from the face image
- Emotion label and confidence are displayed on the video feed in real time