A deep learning-based project for recognizing emotions through facial expressions in real-time! This project leverages OpenCV for face detection and a trained deep learning model for emotion classification. Perfect for exploring AI applications in human emotion analysis!
- Real-Time Face Detection: Detect faces from a live webcam feed using OpenCV's Haar Cascade Classifier.πΉ
- Emotion Prediction: Recognize emotions such as Happy, Sad, Angry, Neutral, and more using a trained convolutional neural network (CNN).π π’ π‘ π
- Efficient Preprocessing: Grayscale conversion, normalization, and resizing for optimal model input.π
- Interactive Output: Display detected faces and their predicted emotions directly on the webcam feed.π‘
- Flask Web App: A web interface to interact with the emotion recognition model, providing a user-friendly way to test real-time emotion detection.π
Emotion-Recognition-Using-Face-Detection/
βββ data/ # Dataset folder
βββ static/ # Static files (CSS, JS, etc.)
βββ templates/ # HTML templates for Flask app
βββ uploads/ # Uploaded files for processing
βββ runtime_emotion_detection.py # Script for real-time detection
βββ model.py # Training and model definition
βββ my_model.h5 # Pre-trained model
βββ haarcascade_frontalface_default.xml # Haar Cascade file
βββ app.py # Main Flask app
βββ README.md # Project documentation
βββ requirements.txt # Dependencies for the project
- Programming Language: Python π
- Deep Learning Framework: TensorFlow/Keras
- Computer Vision Library: OpenCV
- Numerical Computing: NumPy
- Visualization: Matplotlib (optional)
- Face Detection: Haar Cascade Classifier
-
Clone the Repository:
git clone https://github.com/yourusername/Emotion-Recognition-Using-Face-Detection.git cd Emotion-Recognition-Using-Face-Detection
-
Install Dependencies:
Install the required libraries using pip:pip install -r requirements.txt
-
Download Haar Cascade File: Ensure the
haarcascade_frontalface_default.xml
file is in the project directory. If not, download it from the [OpenCV GitHub repository] (https://github.com/opencv/opencv/tree/master/data/haarcascades). -
Run the Application: Start the real-time emotion recognition script:
python real_time_emotion.py
The emotion recognition model is a Convolutional Neural Network (CNN) trained on a dataset of facial expressions. It processes grayscale images resized to 48x48 pixels for efficient and accurate emotion classification.
Predicted Emotions:
- Happy π
- Sad π’
- Angry π‘
- Neutral π
- Surprise π²
The model achieves an accuracy of 75% on the FER-2013 test dataset. While this provides a solid foundation for recognizing emotions from facial expressions, there's room for improvement. We aim to fine-tune the model for better real-world performance.
- β¨ Add More Emotions: Train the model to recognize additional emotions like Fear, Disgust, etc.
- π§ Improve Accuracy: Fine-tune the model for better real-world performance.
- π₯ Multi-Face Detection: Extend the application to predict emotions for multiple faces simultaneously.
- π Web Integration: Create a web-based interface for wider accessibility.
The model was trained using the FER-2013 dataset, which contains labeled facial expressions.
Learn more about the dataset here.
Real-Time Emotion Detection in Action
Real-Time Emotion Detection through the Flask interface
Contributions are welcome! Feel free to fork the repository and submit pull requests with improvements, bug fixes, or new features.
Aymen Baig
A passionate developer and aspiring Data Scientist specializing in Machine Learning and Natural Language Processing. Experienced in building lightweight and efficient chatbot systems for small businesses. Always open to collaborations and learning new technologies.
- GitHub: Aymen Baig
- LinkedIn: Aymen Baig