大坑: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)





免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM