Rosanswers logo

Does sensor_msgs/PointCloud2 data type also contains the rgb value of the image? Currentely i'm using below code, and when i publish the converted pcl type, it also shows rgb values, how is that possible?

cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
    pcl::PointCloud<pcl::PointXYZRGB> output;
    main (int argc, char** argv)
  // Initialize ROS
  ros::init (argc, argv, "training");
  ros::NodeHandle nh;

  ros::Subscriber sub = nh.subscribe<sensor_msgs::PointCloud2> ("input", 1, cloud_cb);
  marker_pub = nh.advertise<visualization_msgs::Marker> ("visualization_marker",1);

  // Spin
  ros::spin ();

as i can see in the sensor_msgs/pointcloud2 documentations it shows below values:

std_msgs/Header header
uint32 height
uint32 width
sensor_msgs/PointField[] fields
bool is_bigendian
uint32 point_step
uint32 row_step
uint8[] data
bool is_dense 

where data should be representing only the depth of the voxels. how is it returning rgb values when converted to pcl data type? i'm little confused, cas i didn't used this code for year.

Originally posted by dinesh on ROS Answers with karma: 932 on 2018-12-01

Post score: 0


1 Answer 1


Rosanswers logo

Yes the PointCloud2 message can represent color point clouds.

The sensor_msgs/PointCloud2 message type can represent an unlimited range of different point cloud types, simple XYZ points, XYZ intenstiy, XYZ color, XYZ with normals. There is no limit since each message uses the sensor_msgs/PointField[] fields declaraion to define the point data structure structure it uses.

The actual data of the point cloud is stored as a raw data buffer in the data element, this needs to be decoded by the receiver using the point structure defined. This is the why the message definition doesn't explicitly include the the XYZ, RGB or any other representation of point data.

Hope this clears this up.

Originally posted by PeteBlackerThe3rd with karma: 9529 on 2018-12-01

This answer was ACCEPTED on the original site

Post score: 2


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.