为什么Open3D的 compute_transformation会产生错误的矩阵?
这个使用Open3D 0.19.0的 Python 3.12脚本会产生一个错误的变换矩阵 m:
import open3d as o3d, numpy as np
s = np.array([[50.7, 107.8, 2282.5], [0.7, 0.5, -0.4], [-0.0, -0.6, -0.7], [-0.6, 0.5, -0.4]], dtype='f4')
t = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype='f4')
source = o3d.geometry.PointCloud()
target = o3d.geometry.PointCloud()
source.points = o3d.utility.Vector3dVector(s)
target.points = o3d.utility.Vector3dVector(t)
corres = o3d.utility.Vector2iVector(np.array([[0, 0], [1, 1], [2, 2], [3, 3]]))
tf = o3d.pipelines.registration.TransformationEstimationPointToPoint()
tf.with_scaling = True
m = tf.compute_transformation(source, target, corres)
output = source.transform(m)
print(np.asarray(output.points))
而不是这个期望的输出:
[[ 0. -0. -0.]
[ 1. -0. -0.]
[-0. 1. -0.]
[-0. -0. 1.]]
我得到的是:
[[-0.00039798 -0.00055862 -0.00041059]
[ 0.33360291 0.33342299 0.33337208]
[ 0.33342299 0.33370331 0.33343232]
[ 0.33337208 0.33343232 0.33360619]]
一个使用OpenCV的类似脚本 estimateAffine3D 产生了正确的结果。到底哪里出了问题?
解决方案
看来 TransformationEstimationPointToPoint 可能不是我想要用于3D变换的函数。使用 registration_ransac_based_on_correspondence 可以得到所需的结果,尽管没有缩放,但这对我的用例并不关键。以下是我修改后的脚本:
import open3d as o3d, numpy as np
np.set_printoptions(legacy='1.25', precision=5, suppress=True, linewidth=130)
s = np.array([[50.7, 107.8, 2282.5], [0.7, 0.5, -0.4], [-0.0, -0.6, -0.7], [-0.6, 0.5, -0.4]], dtype='f4')
t = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype='f4')
source = o3d.geometry.PointCloud()
target = o3d.geometry.PointCloud()
source.points = o3d.utility.Vector3dVector(s)
target.points = o3d.utility.Vector3dVector(t)
corres = o3d.utility.Vector2iVector(np.array([[0, 0], [1, 1], [2, 2], [3, 3]]))
res = o3d.pipelines.registration.registration_ransac_based_on_correspondence(source, target, corres, max_correspondence_distance=1)
output = source.transform(res.transformation)
print(np.asarray(output.points))
以及输出如下:
[ 0.95982 0.01108 0.0291 ]
[ 0.01108 0.95442 0.0345 ]
[ 0.0291 0.0345 0.9364 ]]
由于输入未归一化且变换为刚性变换,因此单位向量会有轻微偏差。
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。