23A475R commited on
Commit
e3c30ee
1 Parent(s): 61e9d71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -40
app.py CHANGED
@@ -17,51 +17,19 @@ EMOTIONS = ['neutral', 'happiness', 'surprise', 'sadness', 'anger', 'disgust', '
17
  # face_detector_mtcnn = MTCNN()
18
  classifier = load_model(emotion_model_path)
19
 
20
- # def predict_emotion(frame):
21
- # frame = imutils.resize(frame, width=300)
22
- # gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
23
- # faces = face_detection.detectMultiScale(gray, scaleFactor=1.1,
24
- # minNeighbors=5, minSize=(30, 30),
25
- # flags=cv2.CASCADE_SCALE_IMAGE)
26
-
27
- # frame_clone = frame.copy()
28
- # if len(faces) > 0:
29
- # faces = sorted(faces, reverse=True,
30
- # key=lambda x: (x[2] - x[0]) * (x[3] - x[1]))[0]
31
- # (fX, fY, fW, fH) = faces
32
-
33
- # # Extract the ROI of the face from the grayscale image, resize it to a fixed 28x28 pixels, and then prepare
34
- # # the ROI for classification via the CNN
35
- # roi = gray[fY:fY + fH, fX:fX + fW]
36
- # roi = cv2.resize(roi, (48, 48))
37
- # roi = roi.astype("float") / 255.0
38
- # roi = img_to_array(roi)
39
- # roi = np.expand_dims(roi, axis=0)
40
-
41
- # preds = emotion_classifier.predict(roi)[0]
42
- # label = EMOTIONS[preds.argmax()]
43
-
44
- # # Overlay a box over the detected face
45
- # cv2.putText(frame_clone, label, (fX, fY + 100),
46
- # cv2.FONT_HERSHEY_DUPLEX, 1, (238, 164, 64), 1)
47
- # cv2.rectangle(frame_clone, (fX, fY), (fX + fW, fY + fH),
48
- # (238, 164, 64), 2)
49
-
50
- # else:
51
- # label = "Can't find your face"
52
-
53
- # return frame_clone
54
-
55
-
56
  def predict_emotion(frame):
57
  frame = imutils.resize(frame, width=300)
58
  gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
59
  faces = face_detection.detectMultiScale(gray, scaleFactor=1.1,
60
  minNeighbors=5, minSize=(30, 30),
61
  flags=cv2.CASCADE_SCALE_IMAGE)
62
- frame_clone = frame.copy()
63
 
64
- for (fX, fY, fW, fH) in faces:
 
 
 
 
 
65
  # Extract the ROI of the face from the grayscale image, resize it to a fixed 28x28 pixels, and then prepare
66
  # the ROI for classification via the CNN
67
  roi = gray[fY:fY + fH, fX:fX + fW]
@@ -79,7 +47,10 @@ def predict_emotion(frame):
79
  cv2.rectangle(frame_clone, (fX, fY), (fX + fW, fY + fH),
80
  (238, 164, 64), 2)
81
 
82
- return frame
 
 
 
83
 
84
 
85
 
@@ -102,7 +73,7 @@ demo = gr.Interface(
102
  os.path.join(os.path.dirname(__file__), "images/gunther.jpeg")
103
 
104
  ],
105
- title = "Whatchu feeling?",
106
  theme = "shivi/calm_seafoam"
107
  )
108
 
 
17
  # face_detector_mtcnn = MTCNN()
18
  classifier = load_model(emotion_model_path)
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  def predict_emotion(frame):
21
  frame = imutils.resize(frame, width=300)
22
  gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
23
  faces = face_detection.detectMultiScale(gray, scaleFactor=1.1,
24
  minNeighbors=5, minSize=(30, 30),
25
  flags=cv2.CASCADE_SCALE_IMAGE)
 
26
 
27
+ frame_clone = frame.copy()
28
+ if len(faces) > 0:
29
+ faces = sorted(faces, reverse=True,
30
+ key=lambda x: (x[2] - x[0]) * (x[3] - x[1]))[0]
31
+ (fX, fY, fW, fH) = faces
32
+
33
  # Extract the ROI of the face from the grayscale image, resize it to a fixed 28x28 pixels, and then prepare
34
  # the ROI for classification via the CNN
35
  roi = gray[fY:fY + fH, fX:fX + fW]
 
47
  cv2.rectangle(frame_clone, (fX, fY), (fX + fW, fY + fH),
48
  (238, 164, 64), 2)
49
 
50
+ else:
51
+ label = "Can't find your face"
52
+
53
+ return frame_clone
54
 
55
 
56
 
 
73
  os.path.join(os.path.dirname(__file__), "images/gunther.jpeg")
74
 
75
  ],
76
+ title = "How are you feeling?",
77
  theme = "shivi/calm_seafoam"
78
  )
79