资源简介
基于深度学习的表情识别,内含基于cv2的人脸检测分类器,以及训练好的模型,能识别检测出七种人脸表情。

代码片段和文件信息
from statistics import mode
import cv2
from keras.models import load_model
import numpy as np
from src.utils.datasets import get_labels
from src.utils.inference import detect_faces
from src.utils.inference import draw_text
from src.utils.inference import draw_bounding_box
from src.utils.inference import apply_offsets
from src.utils.inference import load_detection_model
from src.utils.preprocessor import preprocess_input
# 面部表情识别分类
# parameters for loading data and images
detection_model_path = ‘../trained_models/detection_models/haarcascade_frontalface_default.xml‘
emotion_model_path = ‘../trained_models/emotion_models/fer2013_mini_XCEPTION.102-0.66.hdf5‘
emotion_labels = get_labels(‘fer2013‘)
# hyper-parameters for bounding boxes shape
frame_window = 10
emotion_offsets = (20 40)
# loading models
face_detection = load_detection_model(detection_model_path)
emotion_classifier = load_model(emotion_model_path compile=False)
# getting input model shapes for inference
emotion_target_size = emotion_classifier.input_shape[1:3]
# starting lists for calculating modes
emotion_window = []
# starting video streaming
cv2.namedWindow(‘window_frame‘)
video_capture = cv2.VideoCapture(0)
while True:
bgr_image = video_capture.read()[1]
gray_image = cv2.cvtColor(bgr_image cv2.COLOR_BGR2GRAY)
rgb_image = cv2.cvtColor(bgr_image cv2.COLOR_BGR2RGB)
faces = detect_faces(face_detection gray_image)
for face_coordinates in faces:
x1 x2 y1 y2 = apply_offsets(face_coordinates emotion_offsets)
gray_face = gray_image[y1:y2 x1:x2]
try:
gray_face = cv2.resize(gray_face (emotion_target_size))
except:
continue
gray_face = preprocess_input(gray_face True)
gray_face = np.expand_dims(gray_face 0)
gray_face = np.expand_dims(gray_face -1)
emotion_prediction = emotion_classifier.predict(gray_face)
emotion_probability = np.max(emotion_prediction)
emotion_label_arg = np.argmax(emotion_prediction)
emotion_text = emotion_labels[emotion_label_arg]
emotion_window.append(emotion_text)
if len(emotion_window) > frame_window:
emotion_window.pop(0)
try:
emotion_mode = mode(emotion_window)
except:
continue
if emotion_text == ‘angry‘:
color = emotion_probability * np.asarray((255 0 0))
elif emotion_text == ‘sad‘:
color = emotion_probability * np.asarray((0 0 255))
elif emotion_text == ‘happy‘:
color = emotion_probability * np.asarray((255 255 0))
elif emotion_text == ‘surprise‘:
color = emotion_probability * np.asarray((0 255 255))
else:
color = emotion_probability * np.asarray((0 255 0))
color = color.astype(int)
color = color.tolist()
draw_bounding_box(face_coordinates rgb_image color)
draw_text(face_coordinates rgb_image emotion_m
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 930127 2018-10-23 15:13 表情识别检测\haarcascade_frontalface_default.xm
文件 3218 2018-12-25 09:54 表情识别检测\video_emotion_color_demo.py
文件 3672 2018-12-25 09:54 表情识别检测\video_emotion_gender_demo.py
目录 0 2018-12-25 10:46 表情识别检测\
- 上一篇:软件学院第六次上机
- 下一篇:虚拟机linux和开发板网卡通信.pdf
相关资源
- 基于bp神经网络的表情识别
- 论文研究-人脸表情识别综述.pdf
- 人脸表情识别,笑脸,哭脸等7种表情
- eigenface 人脸表情识别源代码
- 人脸情绪识别 表情识别
- zw_qq_18179941-9734156-表情识别.zip
- 结合Gabor特征与Adaboost的人脸表情识别
- 基于opencv的人脸表情识别的预处理
- 人脸表情模型学习
- 表情识别源代码
- fer2013 情感识别 表情识别 人脸图像
- JAFFE人脸数据库
- 人脸表情识别源代码
- 人脸识别 表情识别 疲劳驾驶 论文资
- intraFace人脸对齐
- 基于Gabor特征提取和神经网络的表情识
- 基于深度学习的人脸表情识别Tensorf
- 关于人脸表情识别相关英文文献 IE
- 人脸表情识别 源代码
- 人脸表情识别数据集-CMU_PIE_Face-PIE和
- 表情识别数据集
- CK+人脸表情数据集151357
- PCA+KNN人脸表情识别
- opencv2+vs2013实现表情识别 ,SVM+BP神经
- 68人脸特征点Hog+SVM人脸表情识别
- keras人脸表情识别.rar
- 表情识别fer2013数据集
- 基于Gabor小波+PCA+LDA特征提取方法的
- 面部表情识别实验 报告
- 微表情识别
评论
共有 条评论