This repository contains a real-time facial emotion recognition system designed to estimate player confidence and mood from live webcam video. The system detects faces in the video stream, preprocesses each face region, and classifies the emotion using a trained convolutional neural network saved in model.h5.
The project is implemented in Python using OpenCV for video capture and face detection, and Keras / TensorFlow for emotion prediction.
- University: Sukkur IBA University
- Department: Computer Science
- Course: Artificial Intelligence (Spring 2026)
- Project title: Real-Time Player Confidence & Mood Analysis System
- Supervisor: Dr. Muhammad Ismail Mangrio, Assistant Professor & Coordinator (CS)
- Team members:
- Ali Tawassul [023-23-0061]
- Muhammad Taha [023-23-0070]
- Inamullah [023-23-0048]
- Real-time webcam video capture
- Face detection using Haar cascades (
haarcascade_frontalface_default.xml) - Emotion classification into seven categories:
- Angry
- Disgust
- Fear
- Happy
- Neutral
- Sad
- Surprise
- Live annotation of detected faces with emotion labels
- Lightweight inference pipeline for desktop use
face-mood-recognition.py- Main application script for real-time mood detection using webcam input.haarcascade_frontalface_default.xml- Pre-trained OpenCV cascade file for detecting frontal faces.model.h5- Trained Keras emotion classification model.train/- Notebook and dataset organization for training and validation.train/train.ipynb- Training notebook for model development.train/dataset/- Image folders for training and validation data.train/subfolders: angry, disgust, fear, happy, neutral, sad, surprisevalidation/subfolders: angry, disgust, fear, happy, neutral, sad, surprise
- Python 3.8 or newer
- Webcam or video capture device connected to the system
- Installation of required Python packages
- Clone the repository or download the files.
- Create a Python virtual environment (recommended):
python3 -m venv venv
source venv/bin/activate- Install required packages:
pip install opencv-python-headless numpy tensorflow kerasNote: If you want GUI support for OpenCV windows, use
opencv-pythoninstead ofopencv-python-headless.
Run the main script to start the real-time emotion recognition system:
python face-mood-recognition.pyControls:
- Press
qto quit the application
The script will open a window displaying the video stream. When a face is detected, a green rectangle is drawn and the predicted emotion label is shown.
- The webcam video stream is initialized via OpenCV.
- Each frame is converted to grayscale.
- Faces are detected using the Haar cascade classifier.
- Each face region is resized to 48x48 pixels and normalized.
- The pre-trained Keras model predicts the most likely emotion.
- The predicted emotion label is overlaid on the live video.
The train/ folder contains the dataset and a training notebook that demonstrates how the model can be trained. The dataset is organized into standard emotion categories and separated into training and validation splits.
If you want to retrain or improve the model:
- Open
train/train.ipynbin Jupyter Notebook or JupyterLab. - Prepare the dataset under
train/dataset/train/andtrain/dataset/validation/. - Train a model using the notebook, then save the resulting model as
model.h5.
- The current system assumes a single webcam input and works best with good lighting.
- If you want to support multiple faces, the system already processes all detected faces in each frame.
- For improved accuracy, consider training on a larger emotion dataset or using a more advanced face detection model.
- You can extend the application with a GUI dashboard, logging, or confidence scoring for each prediction.
- If the webcam does not open, ensure the device is connected and accessible.
- If the model fails to load, verify that
model.h5exists and is compatible with the installed Keras/TensorFlow version. - If face detection is unstable, check that
haarcascade_frontalface_default.xmlis present and correctly referenced.
This project is provided as-is for educational and research purposes. Adjust the license text as needed for your intended use.