我无法通过单应矩阵逆变换得到相同的点

I can't get same point with homography matrix reverse transform

我得到了单应矩阵的逆

self.inv_homography = np.linalg.inv(self.homography)

和我的转换函数

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,则会引入错误。此代码 returns 预期输出:

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. ]]