本文主要是介绍基于matlab点云工具箱对点云进行处理三:对点云进行欧式聚类,使用三角剖分处理后获取点云簇的外接凸多边形,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
基于matlab点云工具箱对点云进行处理三:对点云进行欧式聚类,使用三角剖分处理后获取点云簇的外接凸多边形
步骤:
- 读取velodyne数据包pcap文件内的点云数据
- 使用pcdownsample函数对点云数据进行体素化采样,减少点云数量
- 使用find函数对点云进行筛选
- 使用pcdnoise去除点云内的噪声
- 使用pcsegdist进行欧式聚类
- 使用delaunayTriangulation进行三角剖分
- 使用convexHull获得外接凸包的顶点ID
相关程序在这里https://download.csdn.net/download/rmrgjxeivt/59557139
存在的问题:
弯曲道路的护栏(例如匝道)被识别为半圆形状,误识别区域巨大
基于matlab点云工具箱对点云进行处理一:去除地面,保留剩下的点https://blog.csdn.net/rmrgjxeivt/article/details/121830344
基于matlab点云工具箱对点云进行处理二:对点云进行欧式聚类,获得聚类后点云簇的外接矩形https://blog.csdn.net/rmrgjxeivt/article/details/121830919
基于matlab点云工具箱对点云进行处理三:对点云进行欧式聚类,使用三角剖分处理后获取点云簇的外接凸多边形https://blog.csdn.net/rmrgjxeivt/article/details/121831507
基于matlab点云工具箱对点云进行处理四:对点云进行欧式聚类,并获得包围点云簇的外接凹多边形https://blog.csdn.net/rmrgjxeivt/article/details/121831934
% 读取激光的PCAP文件
% 筛选感兴趣区域
% 播放筛选后的点云veloReader = velodyneFileReader('2021-11-23-12-49-43_Velodyne-HDL-32-Data.pcap','VLP32c');%% 设置感兴趣区域vehPara.length = 5.5;
vehPara.width = 2.2;
vehPara.d = 2.3; % 轴距
vehPara.rearOverhang = 1; % 前悬
vehPara.rearOverhang = 1; % 后悬
vehPara.CG2Rear = 1.45; % 质心到后轴insRegion = [-20 50 -10 10 0 2]; % 感兴趣区域[minX maxX minY maxY]
groundRegion = [-1, 0.2]; % 地面区域,z轴方向xLimits = [insRegion(1), insRegion(2)];
yLimits = [insRegion(3), insRegion(4)];
zLimits = [insRegion(5), insRegion(6)]; % 原点在后轴中心,因此此处相对于轮芯高度player = pcplayer(xLimits,yLimits,zLimits);xlabel(player.Axes,'X (m)');
ylabel(player.Axes,'Y (m)');
zlabel(player.Axes,'Z (m)');veloReader.CurrentTime = veloReader.StartTime + seconds(0.3);disp(['frame数量',num2str(veloReader.NumberOfFrames)])pause(2)frameID = 1000;while(hasFrame(veloReader) && player.isOpen() && (veloReader.CurrentTime < veloReader.EndTime))ptCloudObj = readFrame(veloReader,frameID);frameIDticlidarLo = [3.5 0 1.1 0 0 0];% 取出XYZxTemp = ptCloudObj.Location(:,:,2)+lidarLo(1);yTemp = -ptCloudObj.Location(:,:,1)+lidarLo(2);zTemp = ptCloudObj.Location(:,:,3)+lidarLo(3);pc = [xTemp(:) yTemp(:) zTemp(:) single(ptCloudObj.Intensity(:))];% max(pc(:,1))% min(pc(:,1))% max(pc(:,2))% 对地面的点进行范围筛选zMin = groundRegion(1);zMax = groundRegion(2);pcObj = pointCloud(pc(:,1:3));pcObj.Intensity = pc(:,4);pcOutNum = 30000; % 输出的点云数量objPointVeh = zeros(pcOutNum,4,'single');objPointVeh(:,1) = single(insRegion(2));objPointVeh(:,2) = single(insRegion(4));objPointVeh(:,3) = single(insRegion(6));objPointVeh(:,4) = single(0);% tic%% 降低点云密度 coder会报错gridStep = 0.05;pcObj_downSample = pcdownsample(pcObj,'gridAverage',gridStep); % 降低点云密度% maxNumPoints = 6;% pcObj_downSample = pcdownsample(pcObj,'nonuniformGridSample',maxNumPoints);% percentage = 0.3;% pcObj_downSample = pcdownsample(pcObj,'random',percentage);%% 筛选感兴趣区域(单位米),并排除车身内部的点云xLimits = [insRegion(1), insRegion(2)];yLimits = [insRegion(3), insRegion(4)];zLimits = [insRegion(5), insRegion(6)]; % 原点在后轴中心,因此此处相对于轮芯高度indices = find((pcObj_downSample.Location(:, 2) >= yLimits(1) ...& pcObj_downSample.Location(:,2) <= yLimits(2) ...& pcObj_downSample.Location(:,1) >= xLimits(1) ...& pcObj_downSample.Location(:,1) <= xLimits(2) ...& pcObj_downSample.Location(:,3) <= zLimits(2) ...& pcObj_downSample.Location(:,3) >= zLimits(1) ...& ~(pcObj_downSample.Location(:,1)<(vehPara.length-vehPara.rearOverhang) ...& pcObj_downSample.Location(:,1)>(-vehPara.rearOverhang) ...& pcObj_downSample.Location(:,2)<vehPara.width/2 ...& pcObj_downSample.Location(:,2)>-vehPara.width/2)));% 设置感兴趣的点云区域if ~isempty(indices)pcObj_downSample = select(pcObj_downSample,indices);%% 去除噪声[pcObj_downSample,inlierIndices,~] = pcdenoise(pcObj_downSample);pcID_noNoise = 1:1:pcObj_downSample.Count;if ~isempty(inlierIndices)outlierIndices = [];if ~isempty(outlierIndices) % 非空才输出pcRemainObj = select(pcObj_downSample,pcID_out);elsepcRemainObj = pcObj_downSample;endelsepcRemainObj = pcObj_downSample;endcowPCRemain = size(pcRemainObj.Location)*[1;0];if cowPCRemain>pcOutNumcowPCRemain = pcOutNum;endobjPointVeh(1:cowPCRemain,:) = [pcRemainObj.Location pcRemainObj.Intensity];end% end% figure(2)% % pcshow(plane1)% pcshow(pcPlanel)% title('First Plane')% cowPCRemain = length(pcObj.Location(:,1));% pcRemain(1:cowPCRemain,:) = pcObj.Location;% figure(3)% % pcshow(plane1)% pcshow(pcRemain)% title('remainPtCloud')%% 欧式聚类% 最小聚类欧式距离minDist = 0.5;% 执行欧式聚类分割[labels,numClusters] = pcsegdist(pcRemainObj,minDist);% 显示分割结果hsvColorMap = hsv(numClusters);hsvColorMap_H = hsvColorMap(:,1);hsvColorMap_S = hsvColorMap(:,2);hsvColorMap_V = hsvColorMap(:,3);% view(player,pcRemainObj.Location,[hsvColorMap_H(labels) hsvColorMap_S(labels) hsvColorMap_V(labels)]);% pcshow(pcRemainObj.Location,labels);% colormap(hsv(numClusters));% 遍历所有聚类结果figure(5);clfaxis([insRegion(1) insRegion(2) insRegion(3) insRegion(4)])title('欧式聚类分割');xlabel('X(m)');ylabel('Y(m)');zlabel('Z(m)');hold on;for i = 1:1:numClusters%% 进行多边形框计算pcClusterObjTemp = select(pcRemainObj,find(labels == i));% 求解获得凸多边形进行多边形框计算if length(pcClusterObjTemp.Location(:,1))>=3 % triPart = delaunayTriangulation(double(pcClusterObjTemp.Location(:,1)), ...double(pcClusterObjTemp.Location(:,2)));hull = convexHull(triPart);plot(pcClusterObjTemp.Location(hull,1), pcClusterObjTemp.Location(hull,2), 'r');endendhold offobjVehPoint = objPointVeh;%%pcObjOut = pointCloud(objVehPoint(:,1:3));pcObjOut.Intensity = objVehPoint(:,4);frameID = frameID+1;tocview(player,pcObjOut);% figure(4)% pcshow(pcObjOut.Location)% xlabel('X(m)');% ylabel('Y(m)');% zlabel('Z(m)');% axis([insRegion(1) insRegion(2) insRegion(3) insRegion(4)])pause(0.02);end
这篇关于基于matlab点云工具箱对点云进行处理三:对点云进行欧式聚类,使用三角剖分处理后获取点云簇的外接凸多边形的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!