def img_process(im, landmark, print_img=False):
"""
Image processing, rotate, resize, and crop the face image.
Args:
im: numpy array, Original image
landmark: 5 landmark points
Return:
Crop face region
"""
if landmark is None:
im_rez = cv2.resize(im, (cfg.crop_size, cfg.crop_size))
return im_rez
im_rot, ang, r_landmark = im_rotate(im, landmark)
im_rez, resize_scale, rez_landmark = im_resize(im_rot, r_landmark, ang)
crop = im_crop(im_rez, rez_landmark, resize_scale)
if cfg.forcegray == True:
crop = cv2.cvtColor(crop, cv2.COLOR_RGB2GRAY)
# print('Shapes' + str(im_rot.shape) + str(im_rez.shape) + str(crop.shape))
# return im_rot, im_rez, crop, (crop.astype(np.float) - cfg.PIXEL_MEANS) / cfg.scale
if print_img:
return im, im_rot, im_rez, crop
return crop
评论列表
文章目录