Skip to content

Commit a9da3de

Browse files
Fix face image preprocessing (#78)
1 parent 9680609 commit a9da3de

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

restapi/memegen/app.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ def detect_face(img):
4949
if len(faces) == 0:
5050
return False
5151
for x, y, w, h in faces:
52-
roi_gray = img[y : y + h, x : x + w]
52+
# Crop the detected face region from the grayscale image and
53+
# prepare it for model inference.
54+
roi = gray[y : y + h, x : x + w]
5355
cropped_img = np.expand_dims(
54-
np.expand_dims(cv2.resize(roi_gray, (224, 224)), -1), 0
56+
np.expand_dims(cv2.resize(roi, (224, 224)), -1), 0
5557
)
56-
return roi_gray
58+
return cropped_img
5759

5860

5961
def get_font_size(text):
@@ -151,9 +153,8 @@ def upload_file():
151153
img = add_text_to_image("noface", img)
152154
else:
153155
img = cv2.resize(img, (224, 224))
154-
face_img = cv2.resize(face_img, (224, 224))
155156
interpreter = get_interpreter("models/memegen1.tflite")
156-
results = predict_emotion(interpreter, LABELS, [face_img])
157+
results = predict_emotion(interpreter, LABELS, face_img)
157158
dominant_emotion = max(results, key=results.get)
158159
img = add_text_to_image(dominant_emotion, img)
159160

0 commit comments

Comments
 (0)