Skip to content

Commit

Permalink
remove faces with too small eye distance: side faces or too small faces
Browse files Browse the repository at this point in the history
  • Loading branch information
xinntao committed Sep 10, 2021
1 parent 3c06885 commit 24493fc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion facexlib/utils/face_restoration_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ def read_image(self, img):

self.input_img = img

def get_face_landmarks_5(self, only_keep_largest=False, only_center_face=False, resize=None, blur_ratio=0.01):
def get_face_landmarks_5(self,
only_keep_largest=False,
only_center_face=False,
resize=None,
blur_ratio=0.01,
eye_dist_threshold=10):
if resize is None:
scale = 1
input_img = self.input_img
Expand All @@ -125,6 +130,11 @@ def get_face_landmarks_5(self, only_keep_largest=False, only_center_face=False,
with torch.no_grad():
bboxes = self.face_det.detect_faces(input_img, 0.97) * scale
for bbox in bboxes:
# remove faces with too small eye distance: side faces or too small faces
eye_dist = np.linalg.norm([bbox[6] - bbox[8], bbox[7] - bbox[9]])
if eye_dist_threshold is not None and (eye_dist < eye_dist_threshold):
continue

if self.template_3points:
landmark = np.array([[bbox[i], bbox[i + 1]] for i in range(5, 11, 2)])
else:
Expand Down

0 comments on commit 24493fc

Please sign in to comment.