栅格化处理激光雷达点云数据

栅格化处理激光雷达点云数据

    • matlab版本

matlab版本

lidardata=load('D:\论文相关数据\高速路数据\highwaypoints1.txt');
lidardata1=load('D:\论文相关数据\高速路数据\highwaypoints3.txt');
length_lidardata=length(lidardata);
k=1;
for i=1:length_lidardata
    if (lidardata(i,2)>=-20 && lidardata(i,2)<=40 && lidardata(i,1)>=-12 && lidardata(i,1)<=12 )
        after_lidardata(k,1:3)=lidardata(i,:);
        k=k+1;
        
    end        
end
x=after_lidardata(:,1);
y=after_lidardata(:,2);
z=after_lidardata(:,3);
figure(1);
plot3(x,y,z,'.');
xlabel('X');
ylabel('Y');
zlabel('Z');
set(gca,'XTick',-15:0.5:15);%设置坐标轴的刻度间隔
set(gca,'YTick',-10:5:40);
view(0,90);
grid on;

length_lidardata1=length(lidardata1);
a=1;
for j=1:length_lidardata1
    if (lidardata1(j,2)>=-20 && lidardata1(j,2)<=40 && lidardata1(j,1)>=-12 && lidardata1(j,1)<=12 )
        after_lidardata1(j,1:3)=lidardata1(j,:);
        a=a+1;
        
    end        
end
x1=after_lidardata1(:,1)+20;
y1=after_lidardata1(:,2)+20;
z1=after_lidardata1(:,3);
figure(2);
plot3(x1,y1,z1,'.');
xlabel('X');
ylabel('Y');
zlabel('Z');
set(gca,'XTick',0:2:40);%设置坐标轴的刻度间隔
set(gca,'YTick',0:5:60);
view(0,90);
%view(90,0);
%view(-37.5,30);
% view(-7,-10);
grid on;
% %画出栅格地图用cell创建 2*5(宽为2,长为5% scoring_cell=cell(40/2,60/5); %创建一个计数cell数组,用来记录各个栅格中的存点的当前次数。先将各个元素初始化为0
% for i_1=1:20
%     for j_1=1:12
%         scoring_cell{i_1,j_1}=1;
%     end
% end
% grid_cell=cell(40/2,60/5);
% %将原帧数据x方向向右平移20,y方向上向上平移20
% after_lidardata2=after_lidardata1;
% after_lidardata2(:,1)=after_lidardata2(:,1)+20;
% after_lidardata2(:,2)=after_lidardata2(:,2)+20;
% %将数据放入划分的栅格区域中
% length_after_lidardata2=length(after_lidardata2);
% for i_2=1:length_after_lidardata2
%     W=ceil(after_lidardata2(i_2,1)/2);
%     L=ceil(after_lidardata2(i_2,2)/5);
%     grid_cell{W,L}(scoring_cell{W,L},1)=after_lidardata2(i_2,1);
%     grid_cell{W,L}(scoring_cell{W,L},2)=after_lidardata2(i_2,2);
%     grid_cell{W,L}(scoring_cell{W,L},3)=after_lidardata2(i_2,3);
%     scoring_cell{W,L}=scoring_cell{W,L}+1;
% end

%画出栅格地图用cell创建 2*5(宽为2,长为5%scoring_cell=cell(40/2,60/5); %创建一个计数cell数组,用来记录各个栅格中的存点的当前次数。先将各个元素初始化为0
scoring_cell=cell(60/5,40/2);
for i_1=1:12
    for j_1=1:20
        scoring_cell{i_1,j_1}=1;
    end
end
grid_cell=cell(60/5,40/2);

%将原帧数据x方向向右平移20,y方向上向上平移20
after_lidardata2=after_lidardata1;
after_lidardata2(:,1)=after_lidardata2(:,1)+20;
after_lidardata2(:,2)=after_lidardata2(:,2)+20;

%将数据放入划分的栅格区域中
length_after_lidardata2=length(after_lidardata2);
for i_2=1:length_after_lidardata2
    W=ceil(after_lidardata2(i_2,1)/2);%W对应于列
    L=ceil(after_lidardata2(i_2,2)/5);%L对应于行
    grid_cell{L,W}(scoring_cell{L,W},1)=after_lidardata2(i_2,1);
    grid_cell{L,W}(scoring_cell{L,W},2)=after_lidardata2(i_2,2);
    grid_cell{L,W}(scoring_cell{L,W},3)=after_lidardata2(i_2,3);
    scoring_cell{L,W}=scoring_cell{L,W}+1;
end

%逆向将栅格中数据画出来,以验证的程序的正确性
x3=[];
y3=[];
z3=[];
for i_3=1:12
    for j_2=1:20
        if (isempty(grid_cell{i_3,j_2})==0)%isempty 如何数组为空则返回1,反之为0
            %如何解决元素覆盖问题?
            x2=grid_cell{i_3,j_2}(:,1);
            y2=grid_cell{i_3,j_2}(:,2);
            z2=grid_cell{i_3,j_2}(:,3);
            x3=[x3;x2];%采用向量拼接的方式,将各个栅格中的元素拼接到一个列向量中,用于验证栅格是否正确
            y3=[y3;y2];%注意拼接中的两个连接符号,逗号与冒号
            z3=[z3;z2];
        end
    end
end
figure(3);
plot3(x3,y3,z3,'.');
view(0,90);

你可能感兴趣的:(编程语言)