Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Data type conversion from PCL PointCloud <pointt> to ROS sensor_msgs/Image

I am doing RGBDSLAM with people filtering, i.e. I filtered out people from the point cloud and then output the remaining cluster for RGBDSLAM node to process. However, the RGBDSLAM node only subscribes to sensor_msgs/Image (rgb) and sensor_msgs/Image (depth). I tried to extract RGB and Depth messages directly from the pcl::PointCloud<pointt> before converting it into ROS sensor_msgs/Image. Here is part of my code in the cloud callback function:

typedef pcl::PointXYZRGB PointT;
typedef pcl::PointCloud<PointT> PointCloudT;

PointCloudT::Ptr no_man_cloud (new PointCloudT) ;

sensor_msgs::Image rgbImage ;
sensor_msgs::Image depthImage ;

// RGB Topic
pcl::toROSMsg ( *no_man_cloud, rgbImage ) ;

// Depth Topic
pcl::PointCloud<pcl::PointXYZ> cloud_xyz ;
PointCloudT cloud_xyzrgb ;
pcl::copyPointCloud (*no_man_cloud, cloud_xyz) ;
pcl::copyPointCloud (cloud_xyz, cloud_xyzrgb) ;

pcl::toROSMsg ( cloud_xyzrgb, depthImage ) ;

rtabmap_rgbImage_pub.publish (rgbImage) ;
rtabmapDepthImage_pub.publish (depthImage) ;

It worked in theory, but actually renders nothing on the sensor_msgs/Image depth. Since I am outputting depth and rgb images out a a processed cloud, I cannot extract corresponding topics directly from the RGB-D sensor. Bearing this in mind, this article: How to convert pointcloud2 to separate depth and rgb image messages may not help me. Is there a proper way to output depth and rgb images from point cloud? Thanks !