Robotics StackExchange | Archived questions

How to copy sensor_msgs::PointCloud2 to tensorflow::Tensor fast?

Hi,

i am trying to copy a sensor_msgs::PointCloud2 into a tensorflow::Tensor.

Currently, it is done like this:

void pclCallback(const sensor_msgs::PointCloud2 &pcl2_msg){
pcl::PointCloud<pcl::PointXYZI> cloud;
pcl::fromROSMsg(pcl2_msg, cloud);

const int number_of_points = cloud.points.size();
tensorflow::Tensor points_tensor{tensorflow::DataType::DT_FLOAT, tensorflow::TensorShape({1,number_of_points,4})};

auto pointsMapped = points_tensor.tensor<float, 3>();
for(int i=0; i<number_of_points; i++){
    pointsMapped(0,i,0) = cloud.points[i].x;
    pointsMapped(0,i,1) = cloud.points[i].y;
    pointsMapped(0,i,2) = cloud.points[i].z;
    pointsMapped(0,i,3) = cloud.points[i].intensity /255.0;
}

The performance is quiet bad (both for the for loop and the pcl::fromROSMsg(pcl2_input, cloud).

Is there a recommended way to do this?

Asked by danilobr94 on 2020-02-13 07:20:41 UTC

Comments

You could reduce cost using pointers in both PCL ans Sensormsgs point cloud types

Asked by Fetullah Atas on 2020-02-13 08:43:30 UTC

Answers