veloReader = velodyneFileReader('wang.pcap', 'HDL32E');%读取pacp格式的点云
% Define X, Y, Z-axes limits, for pcplayer, in meters(m).每次根据点云的坐标范围修改
xlimits = [-83 91];
ylimits = [-100 106];
zlimits = [-3 12];
% Create the point cloud player.
player = pcplayer(xlimits, ylimits, zlimits);
% Set labels for pcplayer axes.
xlabel(player.Axes, 'X (m)');
ylabel(player.Axes, 'Y (m)');
zlabel(player.Axes, 'Z (m)');
% Specify that point cloud reading should start at 0.3 seconds from
% the beginning of file.
ptCloudObj = readFrame(veloReader); %获取可用的下一帧
view(player, ptCloudObj.Location, ptCloudObj.Intensity);
%Pt=pcread('ptCloudObj.Location');
B=single(ptCloudObj.Location); %转换为单精度
C=pointCloud(B);
% A=pointCloud(ptCloudObj.Location);
% pcwrite(A,'shu.pcd'); %将数据存为pcd格式
%%使用下采样,大矩阵转化为常见的矩阵格式
gridStep = 0.8; %修改0.8,决定下采样的密度,值越小,采样点越多
ptcloudout=pcdownsample(C,'gridAverage',gridStep);
pcwrite(ptcloudout,'shu4.pcd');