计算机竞赛 基于深度学习的人脸表情识别

文章目录

  • 0 前言
  • 1 技术介绍
    • 1.1 技术概括
    • 1.2 目前表情识别实现技术
  • 2 实现效果
  • 3 深度学习表情识别实现过程
    • 3.1 网络架构
    • 3.2 数据
    • 3.3 实现流程
    • 3.4 部分实现代码
  • 4 最后

0 前言

🔥 优质竞赛项目系列,今天要分享的是

基于深度学习的人脸表情识别

该项目较为新颖,适合作为竞赛课题方向,学长非常推荐!

🧿 更多资料, 项目分享:

https://gitee.com/dancheng-senior/postgraduate


1 技术介绍

1.1 技术概括

面部表情识别技术源于1971年心理学家Ekman和Friesen的一项研究,他们提出人类主要有六种基本情感,每种情感以唯一的表情来反映当时的心理活动,这六种情感分别是愤怒(anger)、高兴(happiness)、悲伤
(sadness)、惊讶(surprise)、厌恶(disgust)和恐惧(fear)。

尽管人类的情感维度和表情复杂度远不是数字6可以量化的,但总体而言,这6种也差不多够描述了。

在这里插入图片描述

1.2 目前表情识别实现技术

在这里插入图片描述
在这里插入图片描述

2 实现效果

废话不多说,先上实现效果

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

3 深度学习表情识别实现过程

3.1 网络架构

在这里插入图片描述
面部表情识别CNN架构(改编自 埃因霍芬理工大学PARsE结构图)

其中,通过卷积操作来创建特征映射,将卷积核挨个与图像进行卷积,从而创建一组要素图,并在其后通过池化(pooling)操作来降维。

在这里插入图片描述

3.2 数据

主要来源于kaggle比赛,下载地址。
有七种表情类别: (0=Angry, 1=Disgust, 2=Fear, 3=Happy, 4=Sad, 5=Surprise, 6=Neutral).
数据是48x48 灰度图,格式比较奇葩。
第一列是情绪分类,第二列是图像的numpy,第三列是train or test。

在这里插入图片描述

3.3 实现流程

在这里插入图片描述

3.4 部分实现代码

import cv2import sysimport jsonimport numpy as npfrom keras.models import model_from_jsonemotions = ['angry', 'fear', 'happy', 'sad', 'surprise', 'neutral']cascPath = sys.argv[1]faceCascade = cv2.CascadeClassifier(cascPath)noseCascade = cv2.CascadeClassifier(cascPath)# load json and create model archjson_file = open('model.json','r')loaded_model_json = json_file.read()json_file.close()model = model_from_json(loaded_model_json)# load weights into new modelmodel.load_weights('model.h5')# overlay meme facedef overlay_memeface(probs):if max(probs) > 0.8:emotion = emotions[np.argmax(probs)]return 'meme_faces/{}-{}.png'.format(emotion, emotion)else:index1, index2 = np.argsort(probs)[::-1][:2]emotion1 = emotions[index1]emotion2 = emotions[index2]return 'meme_faces/{}-{}.png'.format(emotion1, emotion2)def predict_emotion(face_image_gray): # a single cropped faceresized_img = cv2.resize(face_image_gray, (48,48), interpolation = cv2.INTER_AREA)# cv2.imwrite(str(index)+'.png', resized_img)image = resized_img.reshape(1, 1, 48, 48)list_of_list = model.predict(image, batch_size=1, verbose=1)angry, fear, happy, sad, surprise, neutral = [prob for lst in list_of_list for prob in lst]return [angry, fear, happy, sad, surprise, neutral]video_capture = cv2.VideoCapture(0)while True:# Capture frame-by-frameret, frame = video_capture.read()img_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY,1)faces = faceCascade.detectMultiScale(img_gray,scaleFactor=1.1,minNeighbors=5,minSize=(30, 30),flags=cv2.cv.CV_HAAR_SCALE_IMAGE)# Draw a rectangle around the facesfor (x, y, w, h) in faces:face_image_gray = img_gray[y:y+h, x:x+w]filename = overlay_memeface(predict_emotion(face_image_gray))print filenamememe = cv2.imread(filename,-1)# meme = (meme/256).astype('uint8')try:meme.shape[2]except:meme = meme.reshape(meme.shape[0], meme.shape[1], 1)# print meme.dtype# print meme.shapeorig_mask = meme[:,:,3]# print orig_mask.shape# memegray = cv2.cvtColor(orig_mask, cv2.COLOR_BGR2GRAY)ret1, orig_mask = cv2.threshold(orig_mask, 10, 255, cv2.THRESH_BINARY)orig_mask_inv = cv2.bitwise_not(orig_mask)meme = meme[:,:,0:3]origMustacheHeight, origMustacheWidth = meme.shape[:2]roi_gray = img_gray[y:y+h, x:x+w]roi_color = frame[y:y+h, x:x+w]# Detect a nose within the region bounded by each face (the ROI)nose = noseCascade.detectMultiScale(roi_gray)for (nx,ny,nw,nh) in nose:# Un-comment the next line for debug (draw box around the nose)#cv2.rectangle(roi_color,(nx,ny),(nx+nw,ny+nh),(255,0,0),2)# The mustache should be three times the width of the nosemustacheWidth =  20 * nwmustacheHeight = mustacheWidth * origMustacheHeight / origMustacheWidth# Center the mustache on the bottom of the nosex1 = nx - (mustacheWidth/4)x2 = nx + nw + (mustacheWidth/4)y1 = ny + nh - (mustacheHeight/2)y2 = ny + nh + (mustacheHeight/2)# Check for clippingif x1 < 0:x1 = 0if y1 < 0:y1 = 0if x2 > w:x2 = wif y2 > h:y2 = h# Re-calculate the width and height of the mustache imagemustacheWidth = (x2 - x1)mustacheHeight = (y2 - y1)# Re-size the original image and the masks to the mustache sizes# calcualted abovemustache = cv2.resize(meme, (mustacheWidth,mustacheHeight), interpolation = cv2.INTER_AREA)mask = cv2.resize(orig_mask, (mustacheWidth,mustacheHeight), interpolation = cv2.INTER_AREA)mask_inv = cv2.resize(orig_mask_inv, (mustacheWidth,mustacheHeight), interpolation = cv2.INTER_AREA)# take ROI for mustache from background equal to size of mustache imageroi = roi_color[y1:y2, x1:x2]# roi_bg contains the original image only where the mustache is not# in the region that is the size of the mustache.roi_bg = cv2.bitwise_and(roi,roi,mask = mask_inv)# roi_fg contains the image of the mustache only where the mustache isroi_fg = cv2.bitwise_and(mustache,mustache,mask = mask)# join the roi_bg and roi_fgdst = cv2.add(roi_bg,roi_fg)# place the joined image, saved to dst back over the original imageroi_color[y1:y2, x1:x2] = dstbreak#     cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)#     angry, fear, happy, sad, surprise, neutral = predict_emotion(face_image_gray)#     text1 = 'Angry: {}     Fear: {}   Happy: {}'.format(angry, fear, happy)#     text2 = '  Sad: {} Surprise: {} Neutral: {}'.format(sad, surprise, neutral)## cv2.putText(frame, text1, (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 0, 0), 3)# cv2.putText(frame, text2, (50, 150), cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 0, 0), 3)# Display the resulting framecv2.imshow('Video', frame)if cv2.waitKey(1) & 0xFF == ord('q'):break# When everything is done, release the capturevideo_capture.release()cv2.destroyAllWindows()

4 最后

🧿 更多资料, 项目分享:

https://gitee.com/dancheng-senior/postgraduate

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/69681.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

LeetCode:1143. 最长公共子序列 - Python

1143. 最长公共子序列 问题描述&#xff1a; 给定两个字符串 text1 和 text2&#xff0c;返回这两个字符串的最长 公共子序列 的长度。如果不存在公共子序列 &#xff0c;返回 0 。 一个字符串的 子序列 是指这样一个新的字符串&#xff1a;它是由原字符串在不改变字符的相对…

Web前端自动化测试Cypress实践总结

本文主要首先主要介绍了什么是自动化测试&#xff0c;接着对常用的自动化测试框架进行了对比分析&#xff0c;最后&#xff0c;介绍了如果将自动化测试框架Cypress运用在项目中。 一、自动化测试概述 为了保障软件质量&#xff0c;并减少重复性的测试工作&#xff0c;自动化测…

Java中网络的基本介绍。网络通信,网络,ip地址,域名,端口,网络通信协议,TCP/IP传输过程,网络通信协议模型,TCP协议,UDP协议

- 网络通信 概念&#xff1a;网络通信是指通过计算机网络进行信息传输的过程&#xff0c;包括数据传输、语音通话、视频会议等。在网络通信中&#xff0c;数据被分成一系列的数据包&#xff0c;并通过网络传输到目的地。在数据传输过程中&#xff0c;需要确保数据的完整性、准…

golang高精度十进制数扩展包decimal用法

在Go语言中&#xff0c;没有内置的十进制数&#xff08;decimal&#xff09;类型或相关的标准库。然而&#xff0c;有一些第三方包可用于处理十进制数&#xff0c;其中比较常用的是decimal包。 decimal包提供了一个big.Float的子类型decimal.Decimal&#xff0c;可以用于表示和…

1773_把vim的tab键设置为4个空格显示

全部学习汇总&#xff1a; GitHub - GreyZhang/editors_skills: Summary for some common editor skills I used. 有时候自己觉得自己很奇怪&#xff0c;看着Linux的命令窗口就觉得很顺眼。那些花花绿绿的字符以及繁多的方便命令工具&#xff0c;确实是比Windows强不少。不过&a…

FBX SDK 开发环境配置 visual studio 2022

FBX | Adaptable File Formats for 3D Animation Software | Autodesk. 下载windows的sdk并安装. 创建一个c console 工程 设置include目录 添加预处理宏 FBX_SHARED1 添加fbx sdk lib 目录 添加依赖lib : libfbxsdk-md.lib libxml2-md.lib zlib-md.lib 配置完毕.

activiti 通过xml上传 直接部署模型

通过流程xml 直接先发布模型&#xff0c;然后再通过发布模型之后的流程定义获取bpmn model来创建Model. 1、通过xml先发布模型 InputStream bpmnStream multipartFile.getInputStream() deployment repositoryService.createDeployment().addInputStream(multipartFile.getO…

JS 方法实现复制粘贴

背景 以前我们一涉及到复制粘贴功能&#xff0c;实现思路一般都是&#xff1a; 创建一个 textarea 标签 让这个 textarea 不可见&#xff08;定位&#xff09; 给这个 textarea 赋值 把这个 textarea 塞到页面中 调用 textarea 的 select 方法 调用 document.execCommand…

SpringBoot2.0集成WebSocket,多客户端

适用于单客户端&#xff0c;一个账号登陆一个客户端&#xff0c;登陆多个客户端会报错 The remote endpoint was in state [TEXT_FULL_WRITING] 这是因为此时的session是不同的&#xff0c;只能锁住一个session&#xff0c;解决此问题的方法把全局静态对象锁住&#xff0c;因…

go锁-waitgroup

如果被等待的协程没了&#xff0c;直接返回 否则&#xff0c;waiter加一&#xff0c;陷入sema add counter 被等待协程没做完&#xff0c;或者没人在等待&#xff0c;返回 被等待协程都做完&#xff0c;且有人在等待&#xff0c;唤醒所有sema中的协程 WaitGroup实现了一组协程…

【shell】限制任务并发

shell - 限制任务并发 遇到问题如何解决知识点 遇到问题 数千个任务同时执行会导致服务器资源不足, 处理速度越来越慢直到夯住、崩溃 如何解决 通过限制任务最大并发数来解决, 下面提供两种方式, 假设循环 sh aaa.sh 通过 ps -ef | grep aaa.sh 获取当前任务并发数, 来判断…

TCP的滑动窗口协议有什么用?

分析&回答 滑动窗口协议&#xff1a; TCP协议的使用维持发送方/接收方缓冲区 缓冲区是 用来解决网络之间数据不可靠的问题&#xff0c;例如丢包&#xff0c;重复包&#xff0c;出错&#xff0c;乱序 在TCP协议中&#xff0c;发送方和接受方通过各自维护自己的缓冲区。通…

Android图形-架构2

目录 引言 组件概述 底层组件&#xff1a; 上层组件&#xff1a; 引言 Android图形架构主要涉及些什么呢&#xff1f; 1&#xff09;Android 系统级图形架构的基本元素&#xff1f; 2&#xff09;应用框架和多媒体系统如何使用这些元素&#xff1f; 3&#xff09;图形数据…

csharp开发日常之Activator.CreateInstance构造函数生成实例

目录 一、需求&#xff1a;项目中经常需要动态生成对象&#xff0c;而非采用new关键字方式&#xff0c;例如Java里面的根据类全限定名反射生成对象实例。 二、方案&#xff1a;采用Activator.CreateInstance 三、代码例子演示 1、代码结构 2、创建接口 3、创建IObjcet接口的…

FPN模型

【简介】 2017年&#xff0c;T.-Y.Lin等人在Faster RCNN的基础上进一步提出了特征金字塔网络FPN(Feature Pyramid Networks)技术。在FPN技术出现之前&#xff0c;大多数检测算法的检测头都位于网络的最顶层(最深层)&#xff0c;虽说最深层的特征具备更丰富的语义信息&#xff0…

数仓开发:更新变动数据

数仓 一、数据更新检查二、更新目标表三、更新中间表在数仓建设过程中,经常会遇到上游数据变动,进而更新下游目标表的情况,这个时候只需要根据主键update/insert即可,但也会遇到某些特殊情况,比如说下游update数据库后,还要update缓存中的数据,这时候为了提高效率,必须采取增量…

【ES6】CommonJS模块和ES6模块

在JavaScript中&#xff0c;模块是一种将功能代码组织成逻辑单元的方式&#xff0c;以便在其他项目中重复使用。有两种主要的模块系统&#xff1a;CommonJS和ES6。 1、CommonJS 在CommonJS中&#xff0c;我们使用require来引入模块&#xff0c;使用module.exports来导出模块。…

Python类的方法

Python类的方法主要分为实例方法、类方法和静态方法三种。 1 实例方法 以self作为第一个参数的方法&#xff0c;就是类的实例方法。该方法由类的实例调用&#xff0c;Python会把调用该方法的实例对象传递给self。 如下代码定义了一个名为A的类。 class A:def __init__(self…

空间曲线的参数方程

空间曲线的参数方程 二维直线 经过一点 P ( x 0 &#xff0c; y 0 ) P(x_0&#xff0c;y_0) P(x0​&#xff0c;y0​)的方向向量为 n ( c o s θ &#xff0c; s i n θ ) n(cos\theta&#xff0c;sin\theta) n(cosθ&#xff0c;sinθ)的直线参数方程为&#xff1a; [ x y …

单元测试和集成测试的区别

单元测试和集成测试是软件开发中常用的两种测试方法&#xff0c;它们的主要区别如下&#xff1a; 范围不同&#xff1a;单元测试关注于对软件中的最小功能单元进行测试&#xff0c;通常是对独立的函数、方法或类进行测试。而集成测试则更加综合&#xff0c;涉及多个模块、组件或…