def _aligned(im_ref, im, im_to_align=None, key=None):
w, h = im.shape[:2]
im_ref = cv2.resize(im_ref, (h, w), interpolation=cv2.INTER_CUBIC)
im_ref = _preprocess_for_alignment(im_ref)
if im_to_align is None:
im_to_align = im
im_to_align = _preprocess_for_alignment(im_to_align)
assert im_ref.shape[:2] == im_to_align.shape[:2]
try:
cc, warp_matrix = _get_alignment(im_ref, im_to_align, key)
except cv2.error as e:
logger.info('Error getting alignment: {}'.format(e))
return im, False
else:
im = cv2.warpAffine(im, warp_matrix, (h, w),
flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP)
im[im == 0] = np.mean(im)
return im, True
评论列表
文章目录