Robotics StackExchange | Archived questions

Losing intensity data when converting between sensor_msgs::PointCloud2 and pcl::PointCloud<T>

Hello,

Am I supposed to lose intensity data when converting between sensormsgs::PointCloud2 and pcl::PointCloud? Specifically, I am getting an accumulated laser data from laserassembler in sensor_msgs::PointCloud2 form. I want to work with the individual points, so I converted it to pcl::PointCloudpcl::PointXYZI using pcl::fromROSMsg. However, during runtime I get the warning "Failed to find match for field 'intensity'", and the resulting pcl PointCloud has the value 1 for the intensity of each point.

Here is the part where I periodically assemble laser scan and convert it into a pcl PointCloud:

ros::service::waitForService("assemble_scans");
ros::ServiceClient assembler_client = nh.serviceClient<laser_assembler::AssembleScans2>("assemble_scans2");
laser_assembler::AssembleScans2 assembler_srv;

frame_pub = nh.advertise<CloudXYZI>("assembled_laser", 1);

while (ros::ok()) {
    if (ros::Time::now() - t_last_assemble > ros::Duration(t_skip)) {
        assembler_srv.request.begin = ros::Time::now() - ros::Duration(t_frame);
        assembler_srv.request.end   = ros::Time::now();
        if (assembler_client.call(assembler_srv)) {
            sensor_msgs::PointCloud2 framecloud = assembler_srv.response.cloud; //I still have intensity
            CloudXYZI framecloud_pcl;
            pcl::fromROSMsg(framecloud, framecloud_pcl); //Failed to find match for field 'intensity'
            frame_pub.publish(framecloud);
            t_last_assemble = ros::Time::now();
        }
    }
    ros::spinOnce();
}

Asked by samudra on 2014-06-11 07:08:21 UTC

Comments

Answers

Same here! Have you come up with any solution yet?

Asked by canibalon on 2014-09-02 00:47:48 UTC

Comments

Had the same problem too. Found out that It is caused by pcl calling the intensity field 'intensity' and ros calling it 'intensities'.

I guess the real fix would be pcl and ros to use same naming convention or to have fromROSMsg to handle the difference. Luckily, the problem is easy to circumvent by just changing the field name of the sensor_msgs::PointCloud2 from intensities to intensity.

sensor_msgs::PointCloud2 response = srv.response.cloud;
response.fields[3].name = "intensity";
pcl::PointCloud<pcl::PointXYZI> response_pcl;
pcl::fromROSMsg(response,response_pcl);

I'm not sure if the intensity field index is always 3 so you might want to check the names of all of the fields in the message first to be sure.

Asked by Raitalaama on 2014-10-22 05:48:58 UTC

Comments

This fixed it, thanks!

Asked by nbanyk on 2015-04-29 15:03:48 UTC