def alignment(filePath, points, ref_points):
'''
@brief: ??????????????
'''
assert(len(points) == len(ref_points))
num_point = len(ref_points) / 2
#??????
dst = np.empty((num_point, 2), dtype = np.int)
k = 0
for i in range(num_point):
for j in range(2):
dst[i][j] = ref_points[k]
k = k+1
#???????
src = np.empty((num_point, 2), dtype = np.int)
k = 0
for i in range(num_point):
for j in range(2):
src[i][j] = points[k]
k = k+1
#???????????????????
tfrom = tf.estimate_transform('affine', dst,src)
#?opencv???,????????,????M
# pts1 = np.float32([[src[0][0],src[0][1]],[src[1][0],src[1][1]],[src[2][0],src[2][1]]])
# pts2 = np.float32([[dst[0][0],dst[0][1]],[dst[1][0],dst[1][1]],[dst[2][0],dst[2][1]]])
# M = cv2.getAffineTransform(pts2,pts1)
#?????????????
pts3 = np.float32([[src[0][0],src[0][1]],[src[1][0],src[1][1]],[src[2][0],src[2][1]],[src[3][0],src[3][1]],[src[4][0],src[4][1]]])
pts4 = np.float32([[dst[0][0],dst[0][1]],[dst[1][0],dst[1][1]],[dst[2][0],dst[2][1]],[dst[3][0],dst[3][1]],[dst[4][0],dst[4][1]]])
N = compute_affine_transform(pts4, pts3)
#
im = skimage.io.imread(filePath)
if im.ndim == 3:
rows, cols, ch = im.shape
else:
rows, cols = im.shape
warpimage_cv2 = cv2.warpAffine(im, N, (cols, rows))
warpimage = tf.warp(im, inverse_map = tfrom)
return warpimage, warpimage_cv2
评论列表
文章目录