MATLAB 从点云中删除平面代码例程
Detect Multiple Planes from Point Cloud
从点云中删除多平面
Load the point cloud. 加载点云例程
load('object3d.mat')
Display and label the point cloud. 显示点云和标签
figure
pcshow(ptCloud)
xlabel('X(m)')
ylabel('Y(m)')
zlabel('Z(m)')
title('Original Point Cloud')
Set the maximum point-to-plane distance (2cm) for plane fitting. 设置平面拟合的最大点平面距离(2cm)
maxDistance = 0.02;
Set the normal vector of the plane. 设置平面的法向量
referenceVector = [0,0,1];
Set the maximum angular distance to 5 degrees. 设置最大角度距离为5度。
maxAngularDistance = 5;
Detect the first plane, the table, and extract it from the point cloud. 检测第一个平面,即表,并从点云中提取它.
[model1,inlierIndices,outlierIndices] = pcfitplane(ptCloud,...
maxDistance,referenceVector,maxAngularDistance);
plane1 = select(ptCloud,inlierIndices);
remainPtCloud = select(ptCloud,outlierIndices);
Set the region of interest to constrain the search for the second plane, left wall.
设置感兴趣的区域来约束搜索第二个平面,左墙。
roi = [-inf,inf;0.4,inf;-inf,inf];
sampleIndices = findPointsInROI(remainPtCloud,roi);
Detect the left wall and extract it from the remaining point cloud. 检测左壁并从剩余的点云中提取它。
[model2,inlierIndices,outlierIndices] = pcfitplane(remainPtCloud,...
maxDistance,'SampleIndices',sampleIndices);
plane2 = select(remainPtCloud,inlierIndices);
remainPtCloud = select(remainPtCloud,outlierIndices);
Plot the two planes and the remaining points. 画出两个平面和剩下的点。
figure
pcshow(plane1)
title('First Plane')
figure
pcshow(plane2)
title('Second Plane')
figure
pcshow(remainPtCloud)
title('Remaining Point Cloud')
例程地址:
D:\Users\41644\Documents\MATLAB\Examples\R2019a\vision\DetectMultiplePlanesFromPointCloudExample
其中 "D:\Users\41644\Documents\"是MATLAB安装地址