简体   繁体   中英

Fit a least-square mean plane to point cloud data in Matlab

I am really struggling to fit a mean plane to point cloud data in Matlab (least square). I've tried numerous other approaches as exemplified on this page, but get the same mean plane as in the image, which obviously is terribly wrong. Do you have any idea what may be wrong?

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;

Result from the script run

Link to matlab point cloud data

Try using the pcfitplane function. It does a robust fit using RANSAC.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM