All projects

Project 04 · Computer vision · 2025

Real-Time Emotion Recognition

Facial-expression recognition from a live webcam, turned into a game for visitors at our TEKNOFEST 2025 stand.

Top-down illustration of a festival stand: a table with a monitor, laptop and webcam on a tripod, three visitors watching and Erva presenting

Overview

A convolutional neural network reads a live webcam feed and classifies each face into one of seven expressions — angry, disgust, fear, happy, sad, surprise and neutral — with a confidence score, in real time on ordinary hardware.

At TEKNOFEST 2025 it ran as Duygu Tanıma Oyunu, the emotion-recognition game: visitors typed their name, played a round in front of the camera and landed on the leaderboard.

The TEKNOFEST 2025 stand: the emotion-recognition game on a large screen with name entry and a leaderboard, a webcam on a tripod and a laptop
our stand at TEKNOFEST 2025

How it works

  1. DetectOpenCV’s Haar cascade finds every face in each frame.
  2. PrepareEach face is cropped, converted to grayscale and resized to 48 × 48.
  3. ClassifyThe CNN predicts one of seven expressions with a confidence score.
  4. ShowA box and the predicted label are drawn over each face as the video plays.

The model

  1. Conv2D 32 · 3×3 · ReLU
  2. MaxPooling 2×2
  3. Conv2D 64 · 3×3 · ReLU
  4. MaxPooling 2×2
  5. Conv2D 128 · 3×3 · ReLU
  6. MaxPooling 2×2
  7. Flatten
  8. Dense 128 · ReLU
  9. Dropout 0.5
  10. Dense 7 · softmax

Trained with Adam and categorical cross-entropy for 30 epochs (batch 64), with rotation, shift, shear, zoom and horizontal-flip augmentation.

What’s in the source code

Two Python scripts — one to train the model, one to run it on the webcam — plus the trained weights.

  • train_emotion_model.pyBuilds and trains the CNN on dataset/train, validates on dataset/test, saves the model
  • real_time_emotion.pyWebcam loop: face detection, 48×48 preprocessing, prediction and on-screen labels
  • emotion_model.h5Trained model weights
  • dataset/Training and test images for the seven classes