www.gusucode.com > vision 源码程序 matlab案例代码 > vision/DetectACylinderFromPointCloudExample.m

    %% Extract Cylinder from Point Cloud
% 
%%
% Load the point cloud.
load('object3d.mat');
%%
% Display the point cloud.
figure
pcshow(ptCloud)
xlabel('X(m)')
ylabel('Y(m)')
zlabel('Z(m)')
title('Original Point Cloud')
%%
% Set the maximum point-to-cylinder distance (5 mm) for cylinder fitting.
maxDistance = 0.005;
%%
% Set the region of interest to constrain the search.
roi = [0.4,0.6,-inf,0.2,0.1,inf];
sampleIndices = findPointsInROI(ptCloud,roi);
%%
% Set the orientation constraint.
referenceVector = [0,0,1];
%%
% Detect the cylinder and extract it from the point cloud by specifying
% the inlier points.
[model,inlierIndices] = pcfitcylinder(ptCloud,maxDistance,...
        referenceVector,'SampleIndices',sampleIndices);
pc = select(ptCloud,inlierIndices);
%%
% Plot the extracted cylinder.
figure
pcshow(pc)
title('Cylinder Point Cloud')