作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有两个(python)列表(数量有限)的 3D 点。我如何找到一个刚性转换来尽可能匹配这些点。对于每个列表的每个点,已知该点对应于哪个其他点。有这方面的算法/库吗?
我找到了迭代最近点算法,但这假设没有已知的对应关系,而且它似乎是为大点云制作的。我说的是 3 到 8 点的有限组数。
可能的点集(根据列表中的索引对应)
a = [[0,0,0], [1,0,0],[0,1,0]]
b = [[0,0,0.5], [1,0,1],[0,0,2]]
最佳答案
事实证明实际上有一个解析解。在Arun et al., 1987, Least square fitting of two 3D point sets的论文中有描述
我写了一个测试脚本来测试他们的算法,它似乎工作正常(如果你想要一个最小化平方误差和的解决方案,如果你有异常值,这可能不是理想的):
import numpy as np
##Based on Arun et al., 1987
#Writing points with rows as the coordinates
p1_t = np.array([[0,0,0], [1,0,0],[0,1,0]])
p2_t = np.array([[0,0,1], [1,0,1],[0,0,2]]) #Approx transformation is 90 degree rot over x-axis and +1 in Z axis
#Take transpose as columns should be the points
p1 = p1_t.transpose()
p2 = p2_t.transpose()
#Calculate centroids
p1_c = np.mean(p1, axis = 1).reshape((-1,1)) #If you don't put reshape then the outcome is 1D with no rows/colums and is interpeted as rowvector in next minus operation, while it should be a column vector
p2_c = np.mean(p2, axis = 1).reshape((-1,1))
#Subtract centroids
q1 = p1-p1_c
q2 = p2-p2_c
#Calculate covariance matrix
H=np.matmul(q1,q2.transpose())
#Calculate singular value decomposition (SVD)
U, X, V_t = np.linalg.svd(H) #the SVD of linalg gives you Vt
#Calculate rotation matrix
R = np.matmul(V_t.transpose(),U.transpose())
assert np.allclose(np.linalg.det(R), 1.0), "Rotation matrix of N-point registration not 1, see paper Arun et al."
#Calculate translation matrix
T = p2_c - np.matmul(R,p1_c)
#Check result
result = T + np.matmul(R,p1)
if np.allclose(result,p2):
print("transformation is correct!")
else:
print("transformation is wrong...")
关于python - 具有已知对应关系的两个点云的刚性配准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66923224/
我正在尝试创建(在Java中)一个包含指定数量的整数k(例如,50、500、1000等)的整数数组,该数组不使用库函数或集合,但包含随机数范围内(即从 1 到 k)的数字分类,具有指定的重复百分比。
例如: MY_MESSAGE = 'Dear %s, hello.' # ... name = "jj" print MY_MESSAGE % name python 是否具有完成类似我上面的代码的功
我有一个使用 NUnit 3.4.1、NSubstitute 1.10.0 和 NCrunch 2.23.0.2 的文本夹具 此夹具中在任何时间点都有 2 个失败测试。每次我更改某些内容时,哪个测试失
我是一名优秀的程序员,十分优秀!