Numpy 我能';用单应矩阵反变换求同一点
我得到了单应矩阵的逆矩阵Numpy 我能';用单应矩阵反变换求同一点,numpy,homography,Numpy,Homography,我得到了单应矩阵的逆矩阵 self.inv_homography = np.linalg.inv(self.homography) 还有我的trasnform函数 def doTransform(x, y, homography): p = np.ndarray(shape=(3, 1), dtype=float, order='F') p[0, 0] = x p[1, 0] = y p[2, 0] = 1 res = np.dot(homography, p)
self.inv_homography = np.linalg.inv(self.homography)
还有我的trasnform函数
def doTransform(x, y, homography):
p = np.ndarray(shape=(3, 1), dtype=float, order='F')
p[0, 0] = x
p[1, 0] = y
p[2, 0] = 1
res = np.dot(homography, p)
return res
但第三行和第一行不一样,存在一些像素偏移
ref coords :(768, 512, 1024, 768)
ref to wa coords: 569.5178327464915 185.9395922739289 790.8947327112375 448.7356913249636
wa to ref coords: 767.149391928569 510.19931575332294 1022.283053230326 764.3653307505839
如何修复此滑动?我认为您硬编码了z坐标可能是问题所在。如果z坐标未精确转换为1,则会引入错误。此代码返回预期的输出:
import numpy as np
def transform(x, y, z, homography):
p = np.array([x,y,z]).reshape(3,1)
return np.dot(homography, p)
hom = np.array([1.2,3.1, 4.0, 2.4, 5.4, 3.2, 1.1, 3.0, 1.2]).reshape(3,3)
x, y, z = 2.3, 1.7, 1
inv_hom = np.linalg.inv(hom)
x_wa = transform(x, y, z, hom)[0, 0]
y_wa = transform(x, y, z, hom)[1, 0]
z_wa = transform(x, y, z, hom)[2, 0]
print(transform(x_wa, y_wa, z_wa, inv_hom))
>>[[2.3]
[1.7]
[1. ]]