#coding=utf-8
#表情识别
importcv2
fromkeras.modelsimportload_model
importnumpyasnp
importchineseText
importdat来自etime
startTime=外异专械种刻静铁起***.***.now()
emotion_classifier=load_model360问答(
'classifier/emotion_models/simple_CNN.530-0.65.hdf5')
endTime=***.***.化若为高玉找阻死较now()
print(endTime-startTime)
emotion_labels={
0:'生气',
1:'厌恶',
2:'恐惧',
3:'开心绿亲举',
4:'难过',
5:内迅'惊喜',
6:'平静'
}
img=cv2.imread("img/emotion/emotion.png")
face_clas光决厚南沙们重东饭sifier=cv2.CascadeClassifier(
"C:\Python升带责准验36\Lib\site担掌示要批家-packages\opencv-master\data\haarcascades\haarcascade_fronta互祖井lface_default.xml"
)
gray修河侵告音短甚达=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=fa协跟见切ce_classi背服叶这支草苗fier.detectMultiScale(
gray,频查倒题良翻行城scaleFactor=1.2,minNeighbors=3,minSize=(40,40))
color=(255,0,0)
for(注属环x,y,w,h)infaces:
gray_face=双游伤晶最请领证座文剧gray[(y):(图庆密y+h),(x):(x+w)]
gray_face=cv2.resize(gray_face,(48,48))
gray_face=gray_face/255.0
gray_face=np.expand_dims(gray_face,0)
gray_face=np.expand_dims(gray_face,-1)
emotion_label_arg=np.argmax(emotion_classifier.predict(gray_face))
emotion=emotion_labels[emotion_label_arg]
cv2.rectangle(img,(x+10,y+10),(x+h-10,y+w-10),
(255,255,255),2)
img=chineseText.cv2ImgAddText(img,emotion,x+h*0.3,y,color,20)
cv2.imshow("Image",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
标签:双演,张据,思刻务