This directory contains example scripts demonstrating facial emotion recognition (FER) and sentiment analysis.
Real-time emotion recognition using our custom FER module with DeepFace backend.
Real-time emotion recognition using the lightweight fer library.
Analyzes pre-recorded videos and generates comprehensive sentiment reports.
Video analysis using the lightweight fer library.
Install DeepFace for accurate emotion recognition:
pip install deepface numpy opencv-pythoncd examples
python fer_demo.py- Real-time webcam emotion recognition with 7 emotions: happy, sad, angry, surprise, fear, disgust, neutral
- Live visualization with colored bounding boxes, emotion labels, and probability bars
- Temporal smoothing for stable predictions
- Interactive controls: Q (quit), R (reset), S (statistics)
If emotions are always neutral or seem random:
-
Install DeepFace (most important):
pip install deepface
-
Check lighting: Ensure your face is well-lit
-
Face the camera: Look directly at the camera
-
Wait for initialization: First run downloads models (~50-100MB)
Minimal (Testing Only - Returns Neutral):
- numpy
- opencv-python
Recommended (Accurate Emotions):
- deepface ← Install this for real emotion detection!
- numpy
- opencv-python
- With DeepFace: 15-30 FPS with accurate emotion recognition
- Without DeepFace: Fast but only returns "neutral" (fallback mode)
If you prefer different options:
HSEmotion (Fast & Accurate):
pip install hsemotionFER Package (Simple):
pip install fer- Real-time face detection using OpenCV Haar Cascade
- Emotion recognition with confidence scores
- Satisfaction scores (0-1) based on emotions
- Emotion probability distributions
- FPS counter and session statistics
- Emotion distribution over time
python fer_demo_live.py# Analyze video without saving output
python fer_demo_video.py input.mp4
# Analyze and save annotated video
python fer_demo_video.py input.mp4 --output result.mp4
# Process without preview (faster)
python fer_demo_video.py input.mp4 --no-previewWhen working correctly with DeepFace, you'll see:
- Colored boxes around detected faces
- Emotion labels (e.g., "HAPPY (0.89)")
- Satisfaction score (e.g., "Satisfaction: 0.92")
- Probability bars for all 7 emotions
- Real-time FPS and face count
- Comprehensive sentiment report (video analysis)
Lightweight alternative using the fer library with built-in face detection.
pip install ferpython fer_library_demo_live.py# Analyze video
python fer_library_demo_video.py input.mp4
# With output video
python fer_library_demo_video.py input.mp4 --output result.mp4
# No preview (faster)
python fer_library_demo_video.py input.mp4 --no-preview- Simpler setup - just one pip install
- Built-in face detection - uses Haar Cascade or MTCNN
- Good performance - 20-40 FPS on webcam
- 7 emotions detected - same as DeepFace version
- Satisfaction scoring - emotion to sentiment mapping
- Comprehensive reports - detailed video analysis
| Feature | Custom FER (DeepFace) | FER Library |
|---|---|---|
| Accuracy | ★★★★★ Very High | ★★★★☆ High |
| Speed | ★★★★☆ Good (15-30 FPS) | ★★★★★ Fast (20-40 FPS) |
| Setup | pip install deepface | pip install fer |
| Dependencies | Heavy (TensorFlow) | Light |
| Best For | Production, High Accuracy | Quick tests, Demos |
examples/
├── fer_demo_live.py # Custom FER + DeepFace (Live)
├── fer_demo_video.py # Custom FER + DeepFace (Video)
├── fer_library_demo_live.py # FER Library (Live)
├── fer_library_demo_video.py # FER Library (Video)
├── fer_demo_old.py # Old demo (backup)
└── README.md # This file