Ask Your Question
2

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

asked 2014-06-11 07:08:21 -0500

samudra gravatar image

Hello,

Am I supposed to lose intensity data when converting between sensor_msgs::PointCloud2 and pcl::PointCloud<t>? Specifically, I am getting an accumulated laser data from laser_assembler in sensor_msgs::PointCloud2 form. I want to work with the individual points, so I converted it to pcl::PointCloud<pcl::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();
}

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2014-10-22 05:48:58 -0500

Raitalaama gravatar image

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.

edit flag offensive delete link more

Comments

This fixed it, thanks!

nbanyk gravatar image nbanyk  ( 2015-04-29 15:03:48 -0500 )edit
0

answered 2014-09-02 00:47:48 -0500

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2014-06-11 07:08:21 -0500

Seen: 3,732 times

Last updated: Jun 11 '14