Importing ROS bag file of LIDAR scan into Matlab as point cloud structure

32 views (last 30 days)
how to derive point cloud data structure for matlab with points, x y z limit and intensity from ROS bag file.
I need point cloud data in this form for postprocessing in Matlab:
I have ROS bag file imported in Matlab in this form:
I have ROS topics and messages in the bag file with the points. I want to know how to get the point cloud data needed for implementing all the algortihms in Matlab. I could not get much help online. Thank you.

Accepted Answer

Cam Salzberger
Cam Salzberger on 24 Nov 2020
So you have the XYZ points from the PointCloud2 message after you use readXYZ, and you want to get it in the format of the pointCloud object? That's simple enough, you can just call pointCloud with the XYZ points as input.
If there is color data in the ROS message, you can get that out using readRGB and then provide that to the pointCloud constructor:
xyz = readXYZ(ptCloudMsgs{1});
rgb = readRGB(ptCloudMsgs{1});
ptCloudObj = ptCloud(xyz, "Color", rgb);
-Cam
  3 Comments
Aadithya Iyer
Aadithya Iyer on 28 Nov 2020
Hi Cam,
xyz1 = readXYZ(ptcloudf{1,1}) is what I am using to read the coordinates. I want to know why I get so many sets of xyz coordinates per scan with my LIDAR and what is the difference in each scan. Thank you,
Cam Salzberger
Cam Salzberger on 30 Nov 2020
I'm a bit confused about what you are asking. If you are asking why, when you use readXYZ on a single scan, there are multiple sets of (x, y, z) coordinates in that, then the answer is because that is what a lidar scan is. It contains multiple points, because the lidar is used to sense range readings on multiple points in the area. If you want just a single point of data, then you probably want to use a laser rangefinder or similar sensor that just takes the distance to a single point.
If you are asking why you have multiple lidar scans, that is (I'm assuming) because you are reading multiple messages out of the rosbag at one time. If you only want to read one message out of the rosbag at a time, you can provide a "rows" argument to readMessages. However, I'd recommend that you continue to read all messages out at once (as long as it fits in your computer's RAM), and then loop through them to process them individually.
-Cam

Sign in to comment.

More Answers (0)

Categories

Find more on Specialized Messages in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!