在 Matlab 中将最小二乘平均平面拟合到点云数据



我真的很难在 Matlab(最小二乘)中将平均平面拟合到点云数据。我已经尝试了许多其他方法,如本页所示,但得到了与图像中相同的平均平面,这显然是非常错误的。你知道可能出了什么问题吗?

load('xyz.mat'); %//load the variable 'a' that is 44005x3 in size
x = a(:,1);
y = a(:,2);
z = a(:,3);
%//Calculate coeffs for a mean plane for points x,y,z
%//eq: xh(1) xh(2)*x + xh(3)y +  - z = 0
[X,Y] = meshgrid(min(x):10:max(x),min(y):10:max(y));
A = [ones(length(x),1) x y ];
xh = A'*A(A'*z);
Zp = X.*(xh(2)) + Y.*xh(3) + xh(1);
%//plot mean plane
mesh(X,Y,Zp,'EdgeColor','Black');
hold on;
%//plot pointcloud
pcshow(a)
hold off;

脚本运行的结果

链接到 matlab 点云数据

尝试使用 pcfitplane 函数。它使用 RANSAC 进行强大的配合。

最新更新