uncomment debugging
Browse files
app.py
CHANGED
|
@@ -21,30 +21,30 @@ def facial_emotion_recognition(img):
|
|
| 21 |
|
| 22 |
img = resize(img, target_size)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
return img
|
| 50 |
|
|
|
|
| 21 |
|
| 22 |
img = resize(img, target_size)
|
| 23 |
|
| 24 |
+
faces = face_detector.get(img)
|
| 25 |
+
|
| 26 |
+
if len(faces) > 0:
|
| 27 |
+
|
| 28 |
+
highest_score_box = (0, 0, 0, 0) # x, y, w, h
|
| 29 |
+
highest_score = 0
|
| 30 |
+
|
| 31 |
+
for face in faces:
|
| 32 |
+
if face['det_score'] > highest_score:
|
| 33 |
+
highest_score = face['det_score']
|
| 34 |
+
x1, y1, x2, y2 = face['bbox'].astype(int)
|
| 35 |
+
x_margin = int((x2 - x1) * face_margin)
|
| 36 |
+
y_margin = int((y2 - y1) * face_margin)
|
| 37 |
+
x = max(0, x1 - x_margin)
|
| 38 |
+
y = max(0, y1 - y_margin)
|
| 39 |
+
w = min(x2 + x_margin, img.shape[1]) - x
|
| 40 |
+
h = min(y2 + y_margin, img.shape[0]) - y
|
| 41 |
+
highest_score_box = (x, y, w, h)
|
| 42 |
+
|
| 43 |
+
x, y, w, h = highest_score_box
|
| 44 |
+
emotion, _ = hse_emo_model.predict_emotions(img[y:y+h, x:x+w], logits=True)
|
| 45 |
+
|
| 46 |
+
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 0, 255), 2)
|
| 47 |
+
cv2.putText(img, emotion, (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 48 |
|
| 49 |
return img
|
| 50 |
|