本帖最后由 lqhenwunai 于 2021-9-18 13:22 编辑
谢谢大家的回复!!!
如果不嫌长,我把相关代码贴一下 for i in range(1):
# find the nearest neighbors between the current source and destination points
distances, indices = nearest_neighbor(src[:dim,:].T, dst[:dim,:].T)
# compute the transformation between the current source and nearest destination points
Transformation_Mat , Rotation, translation = best_fit_transform(src[:dim,:].T, dst[:dim,indices].T)
# update the current source
src = np.dot(Transformation_Mat, src)
# check error
mean_error = np.mean(distances)
if np.abs(prev_error - mean_error) < thresh:
break
prev_error = mean_error
# calculate final transformation
Transformation_Mat,Rotation,translation = best_fit_transform(chull1, src[:dim,:].T)
这里我只做一次循环,调用best_fit_transform 函数,并且在循环外再调用一次。
而在best_fit_transform函数中,我有这么一段话: tmp=np.dot(R,centroid_A.T)
tmp=np.array(tmp)
t = centroid_B.T - tmp
print("check t...")
print(type(tmp),tmp.shape)
print(centroid_B.T)
print(np.dot(R,centroid_A.T))
print(t)
print("..................")
# homogeneous transformation
T = np.identity(dim+1)
T[:dim, :dim] = R
T[:dim, dim] = t
不懂为什么,两次打印出来的tmp就如一楼所显示的一样,而这造成的后果就是得到的t第一次是1×3的行向量,第二次就是个3*3的矩阵了。然后后面对T赋值就报错了。 |