大坑:perspectiveTransform

计算出透视变换的变换矩阵之后,准备对一组关键点进行变换,以得到关键点变换之后的位置。
先是采用如下函数计算,结果错误。
def transform_points(points, trans_mat):
points_expand = np.ones((len(points), 3), dtype=np.float32)
points_expand[:, 0:2] = points
new_points = np.matmul(trans_mat, points_expand.T)
new_points = new_points.T
return new_points[:, 0:2]
后来网上查到可以用cv2.perspectiveTransform 进行变换。但是变换前,一定对数据进行如下整理:
points = points.reshape(1, -1, 2).astype(np.float32)  #二维变三维, 整形转float型, 一个都不能少    
new_points = cv2.perspectiveTransform(points, trans_mat)




原文地址:https://www.cnblogs.com/rabitvision/p/14044150.html