Invalid argument passed to canTransform argument source_frame in tf2 frame_ids cannot be empty错误.

PCL库中copyPointCloud两种原型

第一种:有点云索引值

 template <typename PointT> void
 pcl::copyPointCloud (const pcl::PointCloud<PointT> &cloud_in, 
                      const pcl::PointIndices &indices,
                      pcl::PointCloud<PointT> &cloud_out)
 {
   // Do we want to copy everything?
   if (indices.indices.size () == cloud_in.points.size ())
   {
     cloud_out = cloud_in;
     return;
   }
 
   // Allocate enough space and copy the basics
   cloud_out.points.resize (indices.indices.size ());
   cloud_out.header   = cloud_in.header;
   cloud_out.width    = indices.indices.size ();
   cloud_out.height   = 1;
   cloud_out.is_dense = cloud_in.is_dense;
   cloud_out.sensor_orientation_ = cloud_in.sensor_orientation_;
   cloud_out.sensor_origin_ = cloud_in.sensor_origin_;
 
   // Iterate over each point
   for (std::size_t i = 0; i < indices.indices.size (); ++i)
     cloud_out.points[i] = cloud_in.points[indices.indices[i]];
 }

第二种:无点云索引值

 template <typename PointInT, typename PointOutT> void
pcl::copyPointCloud (const pcl::PointCloud<PointInT> &cloud_in,
                     pcl::PointCloud<PointOutT> &cloud_out)
{
  // Allocate enough space and copy the basics
  cloud_out.header   = cloud_in.header;
  cloud_out.width    = cloud_in.width;
  cloud_out.height   = cloud_in.height;
  cloud_out.is_dense = cloud_in.is_dense;
  cloud_out.sensor_orientation_ = cloud_in.sensor_orientation_;
  cloud_out.sensor_origin_ = cloud_in.sensor_origin_;
  cloud_out.points.resize (cloud_in.points.size ());

  if (cloud_in.points.empty ())
    return;

  if (isSamePointType<PointInT, PointOutT> ())
    // Copy the whole memory block
    memcpy (&cloud_out.points[0], &cloud_in.points[0], cloud_in.points.size () * sizeof (PointInT));
  else
    // Iterate over each point
    for (std::size_t i = 0; i < cloud_in.points.size (); ++i)
      copyPoint (cloud_in.points[i], cloud_out.points[i]);
}

可以看到上述点云在copy的时候是将原点云的一些属性值也一同赋值了,比如header等,这个时候我们就要注意,如果我们不使用这个函数,而是使用push_back函数一个一个将点云的索引值push的时候,在索引值push结束的时候,一定要将原点云的属性值赋值给新的点云,如header,is_dence等,否则,新点云虽然可以使用,但是在使用rviz显示的时候,会出现Invalid argument passed to canTransform argument source_frame in tf2 frame_ids cannot be empty的错误.

你可能感兴趣的:(PCL)