www.gusucode.com > IPCV_Eval_Kit_R2019a_0ce6858工具箱matlab程序源码 > IPCV_Eval_Kit_R2019a_0ce6858/code/demo_files/I4_10_2_segmentGroundPlane.m

    %% LiDAR偺揰孮僨乕僞偐傜楬柺専弌

%% Velodyne PCAP僼傽僀儖儕乕僟乕傪掕媊
velodyneFileReaderObj = velodyneFileReader('lidardata_ConstructionRoad.pcap','HDL32E');

%% pcplayer傪掕媊
xlimits = [-40 40];
ylimits = [-15 15];
zlimits = [-3 3];
player = pcplayer(xlimits,ylimits,zlimits);
xlabel(player.Axes,'X (m)')
ylabel(player.Axes,'Y (m)')
zlabel(player.Axes,'Z (m)')

%% 僇儔乕儅僢僾傪掕媊
colors = [0 1 0; 1 0 0]; % 椢偲愒
greenIdx = 1; % 椢偺僀儞僨僢僋僗
redIdx = 2; % 愒偺僀儞僨僢僋僗
colormap(player.Axes,colors)
title(player.Axes,'Segmented Ground Plane of Lidar Point Cloud');

%% 嵟弶偺200揰孮傪楬柺専弌偟丄寢壥傪昞帵
for i = 1 : 200
    % 尰嵼偺揰孮傪撉傒崬傒
    ptCloud = velodyneFileReaderObj.readFrame(i);
    
    % 儔儀儖峴楍嶌惉
    colorLabels = zeros(size(ptCloud.Location,1),size(ptCloud.Location,2));
    
    % 楬柺専弌
    groundPtsIdx = segmentGroundFromLidarData(ptCloud);
    
    % 楬柺傪椢偺僀儞僨僢僋僗偵偡傞
    colorLabels(groundPtsIdx (:)) = greenIdx;
    % 楬柺埲奜傪愒偺僀儞僨僢僋僗偵偡傞
    colorLabels(~groundPtsIdx (:)) = redIdx;
    
    % 寢壥偺壜帇壔
    view(player,ptCloud.Location,colorLabels)
end

%%
% Copyright 2018 The MathWorks, Inc.