www.gusucode.com > vision 源码程序 matlab案例代码 > vision/DetectSphereFromPointCloudExample.m
%% Detect Sphere from Point Cloud % Load the point cloud. % Copyright 2015 The MathWorks, Inc. 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 a maximum point-to-sphere distance of 1cm for sphere fitting. maxDistance = 0.01; %% % Set the region of interest to constrain the search. roi = [-inf,0.5;0.2,0.4;0.1,inf]; sampleIndices = findPointsInROI(ptCloud,roi); %% % Detect the sphere, a globe, and extract it from the point cloud. [model,inlierIndices] = pcfitsphere(ptCloud,maxDistance,'SampleIndices',sampleIndices); globe = select(ptCloud,inlierIndices); %% % Plot the globe. figure pcshow(globe) title('Globe Point Cloud')