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

asked 2020-02-13 06:49:53 -0600

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?

edit retag flag offensive close merge delete

Comments

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

atas gravatar imageatas ( 2020-02-13 07:43:30 -0600 )edit