Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There is probably a more direct method, but I've used PCL's .pcd format to accomplish this. Use a ROS node to convert the PointCloud2 msg into PCL's PointCloud<PointT> type -- where PointT is one of PointXYZ, PointXYZRGB, or PointXYZRGBA -- and then save it in an ASCII-formatted .pcd. (In a moment I'll post a link to a my node on GitHub)

In a ROS node, subscribe to a PointCloud2 topic, and within the subscriber, use the following:

pcl::PointCloud<pcl::PointXYZRGB> pclCloud; //create a pcl::PointCloud to be filled
pcl::fromROSMsg(*cloudMsg, pclCloud); //convert the msg->pcl::PointCloud
pcl::io::savePCDFileASCII( filename_ + ".pcd", pclCloud);

Then parse the .pcd. For PointXYZRGB, after the header the points are listed one per line: x y z rgb. Note that PCL packs the RBG (and sometimes aplha) channels into a single float.

Related docs and tutorials: (coming soon)

There is probably a more direct method, but I've used PCL's .pcd format to accomplish this. Use a ROS node to convert the PointCloud2 msg into PCL's PointCloud<PointT> type -- where PointT is one of PointXYZ, PointXYZRGB, or PointXYZRGBA -- and then save it in an ASCII-formatted .pcd. (In a moment I'll post a link to a my node on GitHub)

In a ROS node, subscribe to a PointCloud2 topic, and within the subscriber, use the following:

pcl::PointCloud<pcl::PointXYZRGB> pclCloud; //create a pcl::PointCloud to be filled
pcl::fromROSMsg(*cloudMsg, pclCloud); //convert the msg->pcl::PointCloud
pcl::io::savePCDFileASCII( filename_ + ".pcd", pclCloud);
pclCloud); // save it

Then parse the .pcd. For PointXYZRGB, after the header the points are listed one per line: x y z rgb. Note that PCL packs the RBG (and sometimes aplha) alpha) channels into a single float.

Related docs and tutorials: (coming soon)

pcl::fromROSmsg | writing to a .pcd file | .pcd file format

There is probably a more direct method, but I've used PCL's .pcd format to accomplish this. Use a ROS node to convert the PointCloud2 msg into PCL's PointCloud<PointT> type -- where PointT is one of PointXYZ, PointXYZRGB, or PointXYZRGBA -- and then save it in an ASCII-formatted .pcd. (In a moment I'll post a link to a my node (I have cpp code on GitHub)GitHub that does this.)

In a ROS node, subscribe to a PointCloud2 topic, and within the subscriber, use the following:

pcl::PointCloud<pcl::PointXYZRGB> pclCloud; //create a pcl::PointCloud to be filled
pcl::fromROSMsg(*cloudMsg, pclCloud); //convert the msg->pcl::PointCloud
pcl::io::savePCDFileASCII( filename_ + ".pcd", pclCloud); // save it

Then parse the .pcd. For PointXYZRGB, after the header the points are listed one per line: x y z rgb. Note that PCL packs the RBG (and sometimes alpha) alpha, if you're using it) channels into a single float.

Related docs and tutorials: pcl::fromROSmsg | writing to a .pcd file | .pcd file format

There is probably a more direct method, but I've used PCL's .pcd format to accomplish this. Use a ROS node to convert the PointCloud2 msg into PCL's PointCloud<PointT> type -- where PointT is one of PointXYZ, PointXYZRGB, or PointXYZRGBA -- and then save it in an ASCII-formatted .pcd. (I have cpp code on GitHub that does this.)

In EDIT: Dan Lazewatsky pointed out pointcloud_to_pcd, which converts a ROS node, subscribe PointCloud2 msg to a PointCloud2 topic, and within .pcd file. See his comment for the subscriber, use the following:docs.

pcl::PointCloud<pcl::PointXYZRGB> pclCloud; //create 

Once you have it as a pcl::PointCloud to be filled pcl::fromROSMsg(*cloudMsg, pclCloud); //convert the msg->pcl::PointCloud pcl::io::savePCDFileASCII( filename_ + ".pcd", pclCloud); // save it

Then parse the .pcd. For PointXYZRGB, after it should be fairly easy to parse. After the header the points are listed one per line: x y z rgb. Note that PCL packs the RBG (and alpha, if you're using it) channels into a single float.

Related docs and tutorials: pcl::fromROSmsg | writing to a .pcd file | .pcd file format