in one_shot_domain_adaptation.py [0:0]
def crop_and_rotate_img(opt, src_img, landmarks_det_68, img_name):
"""Crop and rotate the image based on facial landmarks, with post-processing
to scale it to [-1, 1] and add extra axis on first dimension.
Parameters
----------
src_img : HXWXC numpy array.
Returns
-------
numpy array
1XCXHXW numpy array scaled to [-1, 1].
"""
face_landmark = landmarks_det_68.get_landmarks(src_img)
if face_landmark is None:
logging.info("no landmark detected for {}".format(img_name))
return None
rotated_img_256 = image_align(src_img, face_landmark, output_size=256)
imageio.imsave(
"{}/{}_rotated.png".format(opt.output_folder, img_name), rotated_img_256
)
# scale to [-1, 1] and reshape to 1xcxhxw
rotated_img_256 = (rotated_img_256 - 127.5) / 127.5
rotated_img_256 = np.rollaxis(rotated_img_256, 2, 0)
rotated_img_256 = np.expand_dims(rotated_img_256, 0)
return rotated_img_256