Main Content
Extract Ground Points and Non-Ground Points from Lidar Data
Read lidar data from a PCAP file by using the velodyneFileReader
function.
veloReader = velodyneFileReader("lidarData_ConstructionRoad.pcap","HDL32E");
Specify a time interval to extract a set of lidar data frames from the input lidar data.
veloReader.CurrentTime = veloReader.StartTime + seconds(0.5); StopTime = veloReader.StartTime + seconds(10);
Configure the figure window to display the input lidar data frames and the extracted ground points by using the pcplayer
function.
fig = figure(Position=[0 0 800 600]); xlimits = [-30 30]; ylimits = [-30 30]; zlimits = [-10 20]; hPanel = uipanel(fig,Position=[0 0.5 1 0.5]); hPlot = axes(hPanel); player = pcplayer(xlimits,ylimits,zlimits,Parent=hPlot); hPanel_groundData = uipanel(fig,Position=[0 0 0.5 0.5]); hPlot_groundData = axes(hPanel_groundData); player_groundData = pcplayer(xlimits,ylimits,zlimits,Parent=hPlot_groundData); hPanel_nongroundData = uipanel(fig,Position=[0.5 0 0.5 0.5]); hPlot_nongroundData = axes(hPanel_nongroundData); player_nongroundData = pcplayer(xlimits,ylimits,zlimits,Parent=hPlot_nongroundData);
Read the lidar data frames and extract the ground points in the lidar data by using the segmentGroundFromLidarData
function. Then, use the indices of the extracted ground points to segment the non-ground points from the frame.
while (hasFrame(veloReader) && veloReader.CurrentTime < StopTime) % Read a lidar data frame ptCloud = readFrame(veloReader); % Extract ground points from lidar data frame groundPtsIdx = segmentGroundFromLidarData(ptCloud); ptCloudGround = select(ptCloud,groundPtsIdx,OutputSize="full"); % Extract non-ground points from lidar data frame ptCloudNonGround = select(ptCloud,~groundPtsIdx,OutputSize="full"); % Display the input lidar data and the extracted points view(player,ptCloud) title(hPlot,"Input Lidar Data") view(player_groundData,ptCloudGround) title(hPlot_groundData,"Extracted Ground Points") view(player_nongroundData,ptCloudNonGround) title(hPlot_nongroundData,"Extracted Non-Ground Points") colormap(autumn) pause(0.01); end