mano66 commited on
Commit
1dd90b7
·
verified ·
1 Parent(s): fd135df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -35
app.py CHANGED
@@ -1,36 +1,36 @@
1
- import cv2
2
- import numpy as np
3
- from keras.models import load_model
4
-
5
- model=load_model('C:/Users/radha manohar kumar/Downloads/Facial Emotion Recognition/Facial Emotion/model.keras')
6
-
7
- video=cv2.VideoCapture(0)
8
-
9
- faceDetect=cv2.CascadeClassifier('C:/Users/radha manohar kumar/Downloads/Facial Emotion Recognition/Facial Emotion/haarcascade_frontalface_default.xml')
10
-
11
- labels_dict={0:'Angry',1:'Disgust', 2:'Fear', 3:'Happy',4:'Neutral',5:'Sad',6:"Smirk",7:'Surprise'}
12
-
13
- while True:
14
- ret,frame=video.read()
15
- gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
16
- faces= faceDetect.detectMultiScale(gray, 1.3, 3)
17
- for x,y,w,h in faces:
18
- sub_face_img=gray[y:y+h, x:x+w]
19
- resized=cv2.resize(sub_face_img,(48,48))
20
- normalize=resized/255.0
21
- reshaped=np.reshape(normalize, (1, 48, 48, 1))
22
- result=model.predict(reshaped)
23
- label=np.argmax(result, axis=1)[0]
24
- print(label)
25
- cv2.rectangle(frame, (x,y), (x+w, y+h), (0,0,255), 1)
26
- cv2.rectangle(frame,(x,y),(x+w,y+h),(50,50,255),2)
27
- cv2.rectangle(frame,(x,y-40),(x+w,y),(50,50,255),-1)
28
- cv2.putText(frame, labels_dict[label], (x, y-10),cv2.FONT_HERSHEY_SIMPLEX,0.8,(255,255,255),2)
29
-
30
- cv2.imshow("Frame",frame)
31
- k=cv2.waitKey(1)
32
- if k==ord('q'):
33
- break
34
-
35
- video.release()
36
  cv2.destroyAllWindows()
 
1
+ import cv2
2
+ import numpy as np
3
+ from keras.models import load_model
4
+
5
+ model=load_model('model.keras')
6
+
7
+ video=cv2.VideoCapture(0)
8
+
9
+ faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
10
+
11
+ labels_dict={0:'Angry',1:'Disgust', 2:'Fear', 3:'Happy',4:'Neutral',5:'Sad',6:"Smirk",7:'Surprise'}
12
+
13
+ while True:
14
+ ret,frame=video.read()
15
+ gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
16
+ faces= faceDetect.detectMultiScale(gray, 1.3, 3)
17
+ for x,y,w,h in faces:
18
+ sub_face_img=gray[y:y+h, x:x+w]
19
+ resized=cv2.resize(sub_face_img,(48,48))
20
+ normalize=resized/255.0
21
+ reshaped=np.reshape(normalize, (1, 48, 48, 1))
22
+ result=model.predict(reshaped)
23
+ label=np.argmax(result, axis=1)[0]
24
+ print(label)
25
+ cv2.rectangle(frame, (x,y), (x+w, y+h), (0,0,255), 1)
26
+ cv2.rectangle(frame,(x,y),(x+w,y+h),(50,50,255),2)
27
+ cv2.rectangle(frame,(x,y-40),(x+w,y),(50,50,255),-1)
28
+ cv2.putText(frame, labels_dict[label], (x, y-10),cv2.FONT_HERSHEY_SIMPLEX,0.8,(255,255,255),2)
29
+
30
+ cv2.imshow("Frame",frame)
31
+ k=cv2.waitKey(1)
32
+ if k==ord('q'):
33
+ break
34
+
35
+ video.release()
36
  cv2.destroyAllWindows()