From 2e5a5ce00d0a85c8f1dd6e8790916e98b69a8fd3 Mon Sep 17 00:00:00 2001
From: Guillaume HEUSCH <guillaume.heusch@idiap.ch>
Date: Wed, 26 Feb 2020 10:13:42 +0100
Subject: [PATCH] [FaceCropAlign] inversed x,y coordinates when getting eyes
 and mouth center, to be consistent with how annotations are computed and
 sored

---
 bob/pad/face/preprocessor/FaceCropAlign.py | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/bob/pad/face/preprocessor/FaceCropAlign.py b/bob/pad/face/preprocessor/FaceCropAlign.py
index 387e7681..a4b76bb6 100644
--- a/bob/pad/face/preprocessor/FaceCropAlign.py
+++ b/bob/pad/face/preprocessor/FaceCropAlign.py
@@ -102,7 +102,8 @@ def get_mouth_center(lm):
 
     mouth_center_t = (lm[48, :] + lm[54, :]) / 2.0
 
-    mouth_center = (int(mouth_center_t[1]), int(mouth_center_t[0]))
+    #mouth_center = (int(mouth_center_t[1]), int(mouth_center_t[0]))
+    mouth_center = (int(mouth_center_t[0]), int(mouth_center_t[1]))
 
     return mouth_center
 
@@ -159,7 +160,8 @@ def get_eye_center(lm):
     left_eye_t = (lm[36, :] + lm[39, :]) / 2.0
     right_eye_t = (lm[42, :] + lm[45, :]) / 2.0
 
-    eye_center = (int((left_eye_t[1]+right_eye_t[1])/2.0), int((left_eye_t[0]+right_eye_t[0])/2.0))
+    # eye_center = (int((left_eye_t[1]+right_eye_t[1])/2.0), int((left_eye_t[0]+right_eye_t[0])/2.0))
+    eye_center = (int((left_eye_t[0]+right_eye_t[0])/2.0), int((left_eye_t[1]+right_eye_t[1])/2.0))
 
     return eye_center
 
@@ -304,6 +306,10 @@ def normalize_image_size_in_grayscale(image, annotations,
         An image of the cropped face of the size (face_size, face_size).
     """
 
+
+    # WARNING : landmarks existing as annotations for BATL2 are (x,y) and not (y,x)
+    # As a consequence, when loading new landmarks, eyes and mouth center are wrong ...
+
     if use_face_alignment:
 
 
@@ -323,7 +329,6 @@ def normalize_image_size_in_grayscale(image, annotations,
         elif alignment_type=='lightcnn': # This option overrides the facesize argument
 
             # This is the size of the image that this model expects
-
             CROPPED_IMAGE_HEIGHT = 128
             CROPPED_IMAGE_WIDTH = 128
 
@@ -345,6 +350,7 @@ def normalize_image_size_in_grayscale(image, annotations,
 
             annotations['mouth_center']=mouth_center
 
+
             light_cnn_face_cropper=bob.bio.face.preprocessor.FaceCrop(
                 cropped_image_size=(CROPPED_IMAGE_HEIGHT, CROPPED_IMAGE_WIDTH),
                 cropped_positions={'eye_center': EYE_CENTER_POS, 'mouth_center': MOUTH_CENTER_POS})
@@ -415,6 +421,7 @@ def normalize_image_size(image, annotations, face_size,
         RGB 3D or gray-scale 2D.
     """
 
+
     if len(image.shape) == 3:
 
         if not (rgb_output_flag):
@@ -426,9 +433,10 @@ def normalize_image_size(image, annotations, face_size,
         image = [image]  # make gray-scale image an iterable
 
     result = []
+    
 
     for image_channel in image:  # for all color channels in the input image
-
+    
         cropped_face = normalize_image_size_in_grayscale(
             image_channel, annotations, face_size, use_face_alignment,alignment_type=alignment_type)
 
@@ -621,7 +629,7 @@ class FaceCropAlign(Preprocessor):
             An image of the cropped / aligned face, of the size:
             (self.face_size, self.face_size), RGB 3D or gray-scale 2D.
         """
-
+        
         # sanity check:
         if not self.rgb_output_flag and len(image.shape) != 2:
           logger.warning("This image has 3 channels")
-- 
GitLab