This Python program detects the location of a face in an input image or frame and classifies the emotion on the face. It utilizes machine learning algorithms, such as Convolutional Neural Networks (CNNs), to perform facial expression recognition.
- Python 3.x
- OpenCV (cv2) library
- TensorFlow library
- Keras library
-
Clone or download the project repository from GitHub.
-
Install the required libraries using the following command:
pip install opencv-python
pip install tensorflow
pip install keras
-
Download the pre-trained Haar cascade classifier XML file for face detection from the OpenCV GitHub repository. Place the XML file in the
Harcascade
directory. -
Download the pre-trained emotion classification model file (in HDF5 format) and place it in the
Models
directory.
-
In the Python script
Emotion_Detection.py
, set theimage_path
variable to the path of the input image or frame you want to analyze. -
Run the Python script using the following command:
python Emotion_Detection.py
-
Download the pre-trained Haar cascade classifier XML file for face detection from the OpenCV GitHub repository. Place the XML file in the
Harcascade
directory. -
Download the pre-trained emotion classification model file (in HDF5 format) and place it in the
Models
directory.
-
In the Python script
Emotion_Detection.py
, set theimage_path
variable to the path of the input image or frame you want to analyze. -
Run the Python script using the following command:
-
The program will load the input image, detect faces using the Haar cascade classifier, draw bounding boxes around the faces, and classify the emotions on the faces.
-
The output image with bounding boxes and emotion labels will be displayed. Press any key to close the image window.
-
You can modify the class labels in the
class_labels
dictionary to match your specific emotion classification labels. -
Adjust the parameters of the
face_classifier.detectMultiScale()
function to change the face detection sensitivity.
- OpenCV documentation
- TensorFlow documentation
- Keras documentation
- "A Convolutional Neural Network Cascade for Face Detection" by R. Lienhart and J. Maydt: ResearchGate
- "Facial Expression Recognition Using Convolutional Neural Networks: State of the Art" by I. Barros and J. Y. Kam: arXiv
- Cascade Classifier: OpenCV documentation
- Face Detection with Haar Cascade: Towards Data Science
The accuracy of emotion classification depends on the quality of the pre-trained model and the input images or frames.