in source/containers/face-comparison/recognizer/predictor.py [0:0]
def detect_and_align(cls, raw_input_image, is_source_image=False, threshold=0.70):
face_detector, _ = cls.get_model()
height, width, _ = raw_input_image.shape
short_size = height if height < width else width
scale = 1.0 if short_size < 480.0 else 480.0 / short_size
bbox_list, pts5_list = face_detector.detect(raw_input_image, threshold=threshold, scale=scale)
if bbox_list.shape[0] == 0:
return None
if is_source_image:
max_face_index = cls.get_largest_face(bbox_list)
bbox = bbox_list[max_face_index, :]
pts5 = pts5_list[max_face_index, :]
aligned_source_face = face_align.norm_crop(raw_input_image, pts5)
face = Face(
bbox=[float(bbox[0]), float(bbox[1]), float(bbox[2]), float(bbox[3])],
aligned_face_img=aligned_source_face,
confidence=float(bbox[-1]),
key_points={
'eyeLeft': [float(pts5[0][0]), float(pts5[0][1])],
'eyeRight': [float(pts5[1][0]), float(pts5[1][1])],
'nose': [float(pts5[2][0]), float(pts5[2][1])],
'mouthLeft': [float(pts5[3][0]), float(pts5[3][1])],
'mouthRight': [float(pts5[4][0]), float(pts5[4][1])],
}
)
return face
else:
face_list = list()
for index in range(len(bbox_list)):
bbox = bbox_list[index]
pts5 = pts5_list[index]
aligned_target_face = face_align.norm_crop(raw_input_image, pts5)
face = Face(
bbox=[float(bbox[0]), float(bbox[1]), float(bbox[2]), float(bbox[3])],
aligned_face_img=aligned_target_face,
confidence=float(bbox[-1]),
key_points={
'eyeLeft': [float(pts5[0][0]), float(pts5[0][1])],
'eyeRight': [float(pts5[1][0]), float(pts5[1][1])],
'nose': [float(pts5[2][0]), float(pts5[2][1])],
'mouthLeft': [float(pts5[3][0]), float(pts5[3][1])],
'mouthRight': [float(pts5[4][0]), float(pts5[4][1])],
}
)
face_list.append(face)
return face_list