Other

项目介绍

manish-9245/Facial-Emotion-Recognition-using-OpenCV-and-Deepface 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 Other 许可证,目前获得 237 个 Star、77 次 Fork。

仓库全名
manish-9245/Facial-Emotion-Recognition-using-OpenCV-and-Deepface
开源许可证
Other
Star 数
237
Fork 数
77

README 摘要

Facial-Emotion-Recognition-using-OpenCV-and-Deepface This project implements real-time facial emotion detection using the deepface library and OpenCV. It captures video from the webcam, detects faces, and predicts the emotions associated with each face. The emotion labels are displayed on the frames in real-time. This is probably the shortest code to implement realtime emotion monitoring. Give this repository a ⭐ if…

完整内容见 GitHub 原始 README 或本页 。

常见问题

Facial-Emotion-Recognition-using-OpenCV-and-Deepface 用什么语言开发?

主要使用 Python 编写,采用 Other 许可证,目前有 237 个 Star。

Facial-Emotion-Recognition-using-OpenCV-and-Deepface 可以免费商用吗?

仓库标注的许可证为 Other,商用前请先阅读仓库 LICENSE 文件确认授权范围。

如何获取 Facial-Emotion-Recognition-using-OpenCV-and-Deepface 的源码?

可以直接克隆仓库:git clone https://github.com/manish-9245/Facial-Emotion-Recognition-using-OpenCV-and-Deepface.git,默认分支为 main;安装与运行步骤见仓库 README。

Facial-Emotion-Recognition-using-OpenCV-and-Deepface 最近还在维护吗?

仓库最近一次更新为 2025年3月14日,当前没有未关闭的 Issue;Star 数为 237,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

Facial Emotion Recognition using OpenCV and Deepface

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

语言占比

Python

贡献者

README

Facial-Emotion-Recognition-using-OpenCV-and-Deepface

This project implements real-time facial emotion detection using the deepface library and OpenCV. It captures video from the webcam, detects faces, and predicts the emotions associated with each face. The emotion labels are displayed on the frames in real-time. This is probably the shortest code to implement realtime emotion monitoring.

  • Give this repository a ⭐ if you liked it, since it took me time to understand and implement this
  • Made with ❤️ by Manish Tiwari

Dependencies

  • deepface: A deep learning facial analysis library that provides pre-trained models for facial emotion detection. It relies on TensorFlow for the underlying deep learning operations.
  • OpenCV: An open-source computer vision library used for image and video processing.

Usage

Initial steps:

  • Git clone this repository Run: git clone https://github.com/manish-9245/Facial-Emotion-Recognition-using-OpenCV-and-Deepface.git
  • Run: cd Facial-Emotion-Recognition-using-OpenCV-and-Deepface
  1. Install the required dependencies:

    • You can use pip install -r requirements.txt
    • Or you can install dependencies individually:
      • pip install deepface
      • pip install tf_keras
      • pip install opencv-python
  2. Download the Haar cascade XML file for face detection:

  3. Run the code:

    • Execute the Python script.
    • The webcam will open, and real-time facial emotion detection will start.
    • Emotion labels will be displayed on the frames around detected faces.

Approach

  1. Import the necessary libraries: cv2 for video capture and image processing, and deepface for the emotion detection model.

  2. Load the Haar cascade classifier XML file for face detection using cv2.CascadeClassifier().

  3. Start capturing video from the default webcam using cv2.VideoCapture().

  4. Enter a continuous loop to process each frame of the captured video.

  5. Convert each frame to grayscale using cv2.cvtColor().

  6. Detect faces in the grayscale frame using face_cascade.detectMultiScale().

  7. For each detected face, extract the face ROI (Region of Interest).

  8. Preprocess the face image for emotion detection using the deepface library’s built-in preprocessing function.

  9. Make predictions for the emotions using the pre-trained emotion detection model provided by the deepface library.

  10. Retrieve the index of the predicted emotion and map it to the corresponding emotion label.

  11. Draw a rectangle around the detected face and label it with the predicted emotion using cv2.rectangle() and cv2.putText().

  12. Display the resulting frame with the labeled emotion using cv2.imshow().

  13. If the ‘q’ key is pressed, exit the loop.

  14. Release the video capture and close all windows using cap.release() and cv2.destroyAllWindows().

image

评论

暂无评论