def _get_alignment(im_ref, im_to_align, key):
if key is not None:
cached_path = Path('align_cache').joinpath('{}.alignment'.format(key))
if cached_path.exists():
with cached_path.open('rb') as f:
return pickle.load(f)
logger.info('Getting alignment for {}'.format(key))
warp_mode = cv2.MOTION_TRANSLATION
warp_matrix = np.eye(2, 3, dtype=np.float32)
criteria = (
cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 5000, 1e-8)
cc, warp_matrix = cv2.findTransformECC(
im_ref, im_to_align, warp_matrix, warp_mode, criteria)
if key is not None:
with cached_path.open('wb') as f:
pickle.dump((cc, warp_matrix), f)
logger.info('Got alignment for {} with cc {:.3f}: {}'
.format(key, cc, str(warp_matrix).replace('\n', '')))
return cc, warp_matrix
评论列表
文章目录