毕业设计 基于深度学习的人脸表情识别(源码+论文)

📅 2026/7/1 17:34:31
毕业设计 基于深度学习的人脸表情识别(源码+论文)
文章目录0 前言1 项目运行效果2 技术介绍2.1 技术概括2.2 目前表情识别实现技术3 深度学习表情识别实现过程3.1 网络架构3.2 数据3.3 实现流程3.4 部分实现代码4 最后0 前言这两年开始毕业设计和毕业答辩的要求和难度不断提升传统的毕设题目缺少创新和亮点往往达不到毕业答辩的要求这两年不断有学弟学妹告诉学长自己做的项目系统达不到老师的要求。并且很难找到完整的毕设参考学习资料。为了大家能够顺利以及最少的精力通过毕设学长分享优质毕业设计项目提供大家参考学习今天要分享的是毕业设计 基于深度学习的新闻文本分类算法系统(源码论文)学长这里给一个题目综合评分(每项满分5分)难度系数3分工作量3分创新点4分项目分享见主页任意置顶文章1 项目运行效果视频效果毕业设计 深度学习表情识别2 技术介绍2.1 技术概括面部表情识别技术源于1971年心理学家Ekman和Friesen的一项研究他们提出人类主要有六种基本情感每种情感以唯一的表情来反映当时的心理活动这六种情感分别是愤怒anger、高兴(happiness)、悲伤 (sadness)、惊讶(surprise)、厌恶(disgust)和恐惧(fear)。尽管人类的情感维度和表情复杂度远不是数字6可以量化的但总体而言这6种也差不多够描述了。2.2 目前表情识别实现技术3 深度学习表情识别实现过程3.1 网络架构面部表情识别CNN架构改编自 埃因霍芬理工大学PARsE结构图其中通过卷积操作来创建特征映射将卷积核挨个与图像进行卷积从而创建一组要素图并在其后通过池化pooling操作来降维。3.2 数据主要来源于kaggle比赛下载地址。有七种表情类别 (0Angry, 1Disgust, 2Fear, 3Happy, 4Sad, 5Surprise, 6Neutral).数据是48x48 灰度图格式比较奇葩。第一列是情绪分类第二列是图像的numpy第三列是train or test。3.3 实现流程3.4 部分实现代码importcv2importsysimportjsonimportnumpyasnpfromkeras.modelsimportmodel_from_json emotions[angry,fear,happy,sad,surprise,neutral]cascPathsys.argv[1]faceCascadecv2.CascadeClassifier(cascPath)noseCascadecv2.CascadeClassifier(cascPath)# load json and create model archjson_fileopen(model.json,r)loaded_model_jsonjson_file.read()json_file.close()modelmodel_from_json(loaded_model_json)# load weights into new modelmodel.load_weights(model.h5)# overlay meme facedefoverlay_memeface(probs):ifmax(probs)0.8:emotionemotions[np.argmax(probs)]returnmeme_faces/{}-{}.png.format(emotion,emotion)else:index1,index2np.argsort(probs)[::-1][:2]emotion1emotions[index1]emotion2emotions[index2]returnmeme_faces/{}-{}.png.format(emotion1,emotion2)defpredict_emotion(face_image_gray):# a single cropped faceresized_imgcv2.resize(face_image_gray,(48,48),interpolationcv2.INTER_AREA)# cv2.imwrite(str(index).png, resized_img)imageresized_img.reshape(1,1,48,48)list_of_listmodel.predict(image,batch_size1,verbose1)angry,fear,happy,sad,surprise,neutral[probforlstinlist_of_listforprobinlst]return[angry,fear,happy,sad,surprise,neutral]video_capturecv2.VideoCapture(0)whileTrue:# Capture frame-by-frameret,framevideo_capture.read()img_graycv2.cvtColor(frame,cv2.COLOR_BGR2GRAY,1)facesfaceCascade.detectMultiScale(img_gray,scaleFactor1.1,minNeighbors5,minSize(30,30),flagscv2.cv.CV_HAAR_SCALE_IMAGE)# Draw a rectangle around the facesfor(x,y,w,h)infaces:face_image_grayimg_gray[y:yh,x:xw]filenameoverlay_memeface(predict_emotion(face_image_gray))printfilename memecv2.imread(filename,-1)# meme (meme/256).astype(uint8)try:meme.shape[2]except:memememe.reshape(meme.shape[0],meme.shape[1],1)# print meme.dtype# print meme.shapeorig_maskmeme[:,:,3]# print orig_mask.shape# memegray cv2.cvtColor(orig_mask, cv2.COLOR_BGR2GRAY)ret1,orig_maskcv2.threshold(orig_mask,10,255,cv2.THRESH_BINARY)orig_mask_invcv2.bitwise_not(orig_mask)memememe[:,:,0:3]origMustacheHeight,origMustacheWidthmeme.shape[:2]roi_grayimg_gray[y:yh,x:xw]roi_colorframe[y:yh,x:xw]# Detect a nose within the region bounded by each face (the ROI)nosenoseCascade.detectMultiScale(roi_gray)for(nx,ny,nw,nh)innose:# Un-comment the next line for debug (draw box around the nose)#cv2.rectangle(roi_color,(nx,ny),(nxnw,nynh),(255,0,0),2)# The mustache should be three times the width of the nosemustacheWidth20*nw mustacheHeightmustacheWidth*origMustacheHeight/origMustacheWidth# Center the mustache on the bottom of the nosex1nx-(mustacheWidth/4)x2nxnw(mustacheWidth/4)y1nynh-(mustacheHeight/2)y2nynh(mustacheHeight/2)# Check for clippingifx10:x10ify10:y10ifx2w:x2wify2h:y2h# 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 abovemustachecv2.resize(meme,(mustacheWidth,mustacheHeight),interpolationcv2.INTER_AREA)maskcv2.resize(orig_mask,(mustacheWidth,mustacheHeight),interpolationcv2.INTER_AREA)mask_invcv2.resize(orig_mask_inv,(mustacheWidth,mustacheHeight),interpolationcv2.INTER_AREA)# take ROI for mustache from background equal to size of mustache imageroiroi_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_bgcv2.bitwise_and(roi,roi,maskmask_inv)# roi_fg contains the image of the mustache only where the mustache isroi_fgcv2.bitwise_and(mustache,mustache,maskmask)# join the roi_bg and roi_fgdstcv2.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), (xw, yh), (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)ifcv2.waitKey(1)0xFFord(q):break# When everything is done, release the capturevideo_capture.release()cv2.destroyAllWindows()篇幅有限更多详细设计见设计论文4 最后项目包含内容上万字 完整详细设计论文项目分享见主页任意置顶文章