Lidar Labeler loads point clouds in the order returned by the dir function? How to sort the files?

2 Ansichten (letzte 30 Tage)
Hi everyone. I have saved Point Clouds as .pcd files in the directory with names e.g. PointClouds1.pcd .......... PointClouds20.pcd.
However the lidar labeler reads them in the order returned by dir function. The order returned by dir function, is as follows,
PointClouds11.pcd PointClouds15.pcd PointClouds19.pcd PointClouds4.pcd PointClouds8.pcd PointClouds12.pcd PointClouds16.pcd PointClouds2.pcd PointClouds5.pcd PointClouds9.pcd PointClouds1.pcd PointClouds13.pcd PointClouds17.pcd PointClouds20.pcd PointClouds6.pcd PointClouds10.pcd PointClouds14.pcd PointClouds18.pcd PointClouds3.pcd PointClouds7.pcd.
How do I make sure that labeler app loads file in correct order (e.g starting from 1 upto 20). Or how do I make sure that files are saved in the correct order?
I think, I am making a mistake while saving the files as .pcd. Here is the code that I used to display the point clouds in pc player as well as save them as .pcd.
%%
% Define pointcloud player
xLimit = [-50,50];
yLimit = [-50,50];
zLimit = [-3,15];
%player
player=pcplayer(xLimit,yLimit,zLimit);
xlabel(player.Axes,'X(m)');
ylabel(player.Axes,'Y(m)');
zlabel(player.Axes,'Z(m)');
%PointClouds.CurrentTime=PointClouds.StartTime+seconds(1);
veloReader.CurrentTime=veloReader.StartTime;
%Use a loop to play and save the point clouds as .pcd
a=0;
filename="PointClouds%d.pcd";
while(hasFrame(veloReader) && isOpen(player) && (veloReader.CurrentTime < veloReader.StartTime + seconds(2)))
a=a+1
%extract point clouds frame by frame from Velodyne scans
PtCloud = readFrame(veloReader, a); % veloReader is 1x1 velodyneROSMessageReader
%save point clouds as struct
PointClouds(a)=PtCloud;
timeDuration(a)=veloReader.Timestamps(a);
pcdfile=sprintf(filename,a); %Generate file name
pcwrite(PointClouds(a),pcdfile,'Encoding','ascii') % save points clouds as .pcd
view(player,PtCloud.Location,PtCloud.Intensity); %view pointclouds in the pc player
pause(0.1);
veloReader.CurrentTime
end
Thank you very much for your time.

Akzeptierte Antwort

Cam Salzberger
Cam Salzberger am 1 Apr. 2022
Hello Sarang,
I'm not sure about getting Lidar Labeler to load in a different order, or if this is the best way to generate point clouds for use with it. But I can at least answer how to save them in order:
filename="PointClouds%02d.pcd";
This will result in filenames like "PointClouds01.pcd", "PointClouds02.pcd", etc.
The "2" is the precision before the decimal point, and the preceding "0" pads out the value with zeros to reach "2" places. If you wanted to have three-digit numbers instead, use "03" instead of "02". See here for more information.
-Cam
  2 Kommentare
Sarang Jokhio
Sarang Jokhio am 1 Apr. 2022
Bearbeitet: Sarang Jokhio am 1 Apr. 2022
Hi Cam. Thank you very much for quick response.
this method indeed saves .pcd files in the correct order in the folder.
However, when I use dir in the current directory to lists files and folders in the current folder, the order given by 'dir' is again wrong. This the order, in which Lidar Labeler App loads the data (which is incorrect).
(PointClouds003.pcd PointClouds007.pcd PointClouds011.pcd PointClouds015.pcd PointClouds019.pcd
PointClouds004.pcd PointClouds008.pcd PointClouds012.pcd PointClouds016.pcd PointClouds020.pcd
PointClouds001.pcd PointClouds005.pcd PointClouds009.pcd PointClouds013.pcd PointClouds017.pcd
PointClouds002.pcd PointClouds006.pcd PointClouds010.pcd PointClouds014.pcd PointClouds018.pcd)
My problem is that I want to have files in order in the folder, at the same dir function also returns the same order.
I am sorry if my question does not make sense at all :D I am super new to Matlab,
Thank you.
Cam Salzberger
Cam Salzberger am 5 Apr. 2022
Hey Sarang,
I think you're confusing display order with actual order. I have a directory set up with PointClouds001.pcd...PointClouds020.pcd. If I just do "dir", I get this:
But if you do this, you can see that the files are in the correct order:
>> info = dir;
>> arrayfun(@(x) disp(x.name), info)
.
..
PointClouds001.pcd
PointClouds002.pcd
PointClouds003.pcd
PointClouds004.pcd
PointClouds005.pcd
Again, not too sure about Lidar Labeler. But that should at least address what "dir" is doing.
-Cam

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Labeling, Segmentation, and Detection finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by