ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To get raw XYZ data from the pointcloud2 rosmsg, I used the pcl library to convert the complicated pointcloud2 format to something easier. Below a code snippet to read the xyz data, you can then write it to whatever file you want using your favorite filewriting commands.

pcl::PointCloud< pcl::PointXYZ > PointCloudXYZ;
pcl::fromROSMsg(cloud_t,PointCloudXYZ);
std::cout << "width is " << PointCloudXYZ.width << std::endl;
std::cout << "height is " << PointCloudXYZ.height << std::endl;
int cloudsize = (PointCloudXYZ.width) * (PointCloudXYZ.height);
for (int i=0; i< cloudsize; i++){
std::cout << "(x,y,z) = " << PointCloudXYZ.points[i] << std::endl;
}

cloud_t here points to the rosmsg you want to read the pointcloud from. You can find more information about this in the pcl conversions files (which also uses cloud_t) or I can look into my code for you next week.