我正在使用Opencv python接口并获得单应矩阵H.它似乎正常工作,因为我可以使用warp透视来从源图像中获取扭曲图像.我现在尝试使用H和In H来在两个坐标之间来回转换点(而不是图像)并且没有得到预期的结果.
为了得到矩阵,我这样做了:
pts1 = np.float32(corners)
pts2 = np.float32([[0,0], [400,0], [400,400], [0,400]])
self.transform_matrix = cv2.getPerspectiveTransform(pts1, pts2)
Run Code Online (Sandbox Code Playgroud)
给定此矩阵,我使用以下内容进行正向和反向变换:
def transformPoints(self, x, y, reverse=False, integer=True):
if reverse == False:
H = self.transform_matrix
else:
val, H = cv2.invert(self.transform_matrix)
# get the elements in the transform matrix
h0 = H[0,0]
h1 = H[0,1]
h2 = H[0,2]
h3 = H[1,0]
h4 = H[1,1]
h5 = H[1,2]
h6 = H[2,0]
h7 = H[2,1]
h8 = H[2,2]
tx = (h0*x + h1*y + h2)
ty = …Run Code Online (Sandbox Code Playgroud)