竞赛 深度学习人脸表情识别算法 - opencv python 机器视觉

文章目录

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

0 前言

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

🚩 深度学习人脸表情识别系统

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

🥇学长这里给一个题目综合评分(每项满分5分)

  • 难度系数:3分
  • 工作量:3分
  • 创新点:4分

🧿 更多资料, 项目分享:

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/118993.shtml

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

相关文章

用Flask快速生成报表

一、前言 《用Python快速生成报表之一》 我们介绍了用html-table快速生成表格数据报表&#xff0c;今天我们再介绍一下用Python Flask 快速开发报表&#xff0c;使用的是最古老的套页面方式。 二、Flask快速生成报表 Python有N多Web框架&#xff0c;最强大最出名的是Django&…

某全球领先的晶圆代工企业:替代FTP实现大规模文件的高效传输

全球领先的集成电路晶圆代工企业之一 该企业不仅是全球领先的集成电路晶圆代工企业之一&#xff0c;也是中国内地技术最先进、配套最完善、规模最大、跨国经营的集成电路制造企业集团。主要业务是根据客户本身或第三者的集成电路设计&#xff0c;为客户制造集成电路芯片&#…

Python Opencv实践 - 入门使用Tesseract识别图片中的文字

做车牌识别项目前试一试tesseract识别中文。tesseract的安装使用请参考&#xff1a; Python OCR工具pytesseract详解 - 知乎pytesseract是基于Python的OCR工具&#xff0c; 底层使用的是Google的Tesseract-OCR 引擎&#xff0c;支持识别图片中的文字&#xff0c;支持jpeg, png…

IBM展示非冯·诺依曼架构AI芯片NorthPole

我们正处于人工智能的“寒武纪大爆发”时期。在过去的十年中&#xff0c;人工智能已经从理论和小型测试发展到企业规模的使用案例。但是&#xff0c;用于运行人工智能系统的硬件虽然越来越强大&#xff0c;但在设计时却没有考虑到当今的人工智能。随着人工智能系统规模的扩大&a…

3ds Max2023安装教程(最新最详细)

目录 一.简介 二.安装步骤 软件&#xff1a;3ds Max版本&#xff1a;2023语言&#xff1a;简体中文大小&#xff1a;6.85G安装环境&#xff1a;Win11/Win10/Win8/Win7硬件要求&#xff1a;CPU3GHz 内存16G(或更高&#xff09;下载通道①百度网盘丨64位下载链接&#xff1a; …

Vue中的加密方式(js-base64、crypto-js、jsencrypt、bcryptjs)

目录 1.安装js-base64库 2. 在Vue组件中引入js-base64库 3.使用js-base64库进行加密 4.Vue中其他加密方式 1.crypto-js 2.jsencrypt 3.bcryptjs 1.安装js-base64库 npm install js-base64 --save-dev 2. 在Vue组件中引入js-base64库 import { Base64 } from js-ba…

Shopee买家通系统全自动化操作简单方便又快速

Shopee买家通系统是一款专门针对虾皮买家号所开发的全自动化操作系统&#xff0c;可以自动注册、自动加购加心愿单、自动下单等。 1、全自动化注册 准备好账号需要的资料后即可运行注册任务&#xff0c;程序运行时可以自动输入手机号、自动接收短信、自动输入账号密码。账号支…

用Visual Studio(VS)开发UNIX/Linux项目

目录 FTP是免不了的 正确设置头文件 组织项目结构 创建何种项目类型 FTP自动上传 大部分具有Windows开发经验的程序员会比较喜欢使用Visual Studio&#xff0c;而大部分Unix/Linux程序员则喜欢使用UltraEdit直接在主机上写代码。 为什么直接在主机上写代码呢&#xff0c;因…

FlutterUnit 周边 | 收录排序算法可视化

theme: cyanosis 1. FlutterUnit 更新&#xff1a;排序算法可视化 排序算法可视化是用视图层表现出算法执行过程中排序的过程&#xff0c;感谢 编程的平行世界 在 《十几种排序算法的可视化效果&#xff0c;快来看看&#xff01;&#x1f440;》》 一文中提供的算法支持。我进行…

单目3D目标检测[基于深度辅助篇]

基于深度辅助的方法 1. Pseudo-LiDAR Pseudo-LiDAR from Visual Depth Estimation: Bridging the Gap in 3D Object Detection for Autonomous Driving康奈尔大学https://zhuanlan.zhihu.com/p/52803631 首先利用DRON或PSMNET从单目 (Monocular)或双目 (Stereo)图像获取对应的…

设计院图纸加密防泄密方案——天锐绿盾加密软件@德人合科技

天锐绿盾是一款专业的企业信息化防泄密软件&#xff0c;主要针对文档全生命周期进行加密保护&#xff0c;包括创建、修改、传输、归档、分发、销毁等全过程。它可以加强外发数据及终端离线的管理&#xff0c;对正常授权外带范围内的数据流程进行规范。设计图纸、文档等成果数据…

(免费领源码)java#Springboot#mysql装修选购网站99192-计算机毕业设计项目选题推荐

摘 要 随着科学技术&#xff0c;计算机迅速的发展。在如今的社会中&#xff0c;市场上涌现出越来越多的新型的产品&#xff0c;人们有了不同种类的选择拥有产品的方式&#xff0c;而电子商务就是随着人们的需求和网络的发展涌动出的产物&#xff0c;电子商务网站是建立在企业与…

顺序表的定义与实现(数据结构与算法)

一、顺序表的定义 1. 顺序表的定义 #define MaxSize 10 //定义最大长度 typedef struct{ ElemType data[MaxSize]; //用静态的“数组”存放数据元素int length; //顺序表的当前长度 …

SparkSQL的Shuffle分区设定及异常数据处理API(去重、缺失值处理)

一、Spark SQL的Shuffle分区数目设定 二、异常数据处理API &#xff08;1&#xff09;去重方法dropDuplicates &#xff08;2&#xff09;删除有缺失值的行方法dropna &#xff08;3&#xff09;填充缺失值数据fillna 一、Spark SQL的Shuffle分区数目设定 在允许spark程序时&a…

Python实验项目4 :面对对象程序设计

1&#xff1a;运行下面的程序&#xff0c;回答问题。 &#xff08;1&#xff09;说明程序的执行过程&#xff1b; &#xff08;2&#xff09;程序运行结果是什么&#xff1f; # &#xff08;1&#xff09;说明程序的执行过程&#xff1b; # &#xff08;2&#xff09;程序运行…

android开发使用OkHttp自带的WebSocket实现IM功能

一、背景 android app开发经常会有IM需求&#xff0c;很多新手不晓得如何入手&#xff0c;难点在于通讯不中断。其实android发展到今天&#xff0c;很多技术都很完善&#xff0c;有很多类似框架可以实现。例如有&#xff1a;okhttp自带的websocket框架、easysocket等等。本文主…

如何做一个无符号数识别程序

1.状态分析 我们可以把无符号数分为&#xff1a;整数&#xff0c;带小数&#xff0c;带指数部分三种形式。以此构建一个DFA。首先需识别输入是整数还是小数点&#xff0c;若是整数部分输入然后还要再循环识别一次是否有小数点&#xff0c;最后识别是否有指数部分&#xff0c;指…

Spring学习笔记—JDK动态代理

✅作者简介&#xff1a;大家好&#xff0c;我是Leo&#xff0c;热爱Java后端开发者&#xff0c;一个想要与大家共同进步的男人&#x1f609;&#x1f609; &#x1f34e;个人主页&#xff1a;Leo的博客 &#x1f49e;当前专栏&#xff1a; Spring专栏 ✨特色专栏&#xff1a; M…

Redis -- 基础知识2

1.Redis客户端介绍 1.基础介绍 Redis是一种客户端-服务器结构的程序&#xff0c;通过网络进行互动 客户端的多种形态 1.自带了命令行客户端&#xff1a;redis-cil 2.图形化界面的客户端&#xff1a;依赖windows系统&#xff0c;连接服务器有诸多限制&#xff0c;不建议使用 3.基…

打印机连接网络后怎么安装驱动?

打印机在我们办公和生活中算是比较常见的设备&#xff0c;特别是在上班时需要时常打印各种文件&#xff0c;但是有时电脑上的打印机也会有无法打印的问题&#xff0c;或者新买的打印机需要先安装驱动才能正常打印的。 那么这个时候我们需要先检查电脑上的打印机是否有安装驱动&…