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