1

i have many pcd files which were collected in every scan of a lidar. I want to convert my pcd files into pointcloud2 format to use them as a rosbag. I saw the pcd_to_pointcloud from point cloud library, however it is only applicable to a single pcd file. How is it possible to iterate this code for multiple pcd files?

rosrun pcl_ros pcd_to_pointcloud <file.pcd> [ <interval> ]

Files are like scan1.pcd scan2.pcd scan3.pcd etc.

Thank you

overflush
  • 25
  • 1
  • 7

2 Answers2

2

You could do the loop in your shell. For example, the bash command would look as follows:

for F in my_pcd_directory/*.pcd; do rosrun pcl_ros pcd_to_pointcloud ${F} 0; done

This loop publishes all pcd files one by one.

Starting a rosbag record --all or rosbag record cloud_pcd in another shell records the published point clouds and stores them in a bag in your current working directory. Of course, you need to start the recording before running the for-loop.

J.P.S.
  • 485
  • 4
  • 11
0

Some solution in Python

import os
from os import listdir
from os.path import isfile, join

path = "/your/path/to/pcd_files/"

pcd_files = [f for f in listdir(path) if isfile(join(path, f))]

for file in pcd_files:
    cmd = "rosrun pcl_ros pcd_to_pointcloud " + path+file
    os.system(cmd)
Hossam Alzomor
  • 149
  • 1
  • 10