numpy - 我不能用单应矩阵逆变换得到相同的点
问题描述
我得到单应矩阵的反转
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,则会引入错误。此代码返回预期的输出:
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. ]]
推荐阅读
- ios - 应用程序关闭swift iOS后保存字符串变量
- ado.net - 删除单选按钮列表项
- windows - 带有bazel的Tensorflow:avx被忽略了吗?
- python-2.7 - 如何绘制分类数据?
- php - 我们如何从文件中读取 php 函数
- mysql - brew mysqld 没有启动
- angularjs - angularJS表中的格式化日期
- jquery - Bootstrap 3 Carousel:设置单向(垂直)过渡
- mysql - 如何计算具有特定类型的多条记录
- android - 每次我将android项目提交给bitbucket apk以发送到Hokeyapp时,有没有办法