欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

点云PCL中小细节

程序员文章站 2022-06-22 18:10:55
...

计算点与点之间的距离的平局距离

double
computeCloudResolution (const pcl::PointCloud<PointType>::ConstPtr &cloud)
{
  double res = 0.0;
  int n_points = 0;
  int nres;
  std::vector<int> indices (2);
  std::vector<float> sqr_distances (2);
  pcl::search::KdTree<PointType> tree;
  tree.setInputCloud (cloud);

  for (size_t i = 0; i < cloud->size (); ++i)
  {
    if (! pcl_isfinite ((*cloud)[i].x))
    {
      continue;
    }
    //Considering the second neighbor since the first is the point itself.
    nres = tree.nearestKSearch (i, 2, indices, sqr_distances);
    if (nres == 2)
    {
      res += sqrt (sqr_distances[1]);
      ++n_points;
    }
  }
  if (n_points != 0)
  {
    res /= n_points;
  }
  return res;
}

PCL中

对于 pcl::UniformSampling函数在PCL1.7版本里  该函数放在keypoints
用法如下:
pcl::PointCloud<int> keypointIndices;
filter.compute(keypointIndices);
pcl::copyPointCloud(*cloud, keypointIndices.points, *filteredCloud);

之后在PCL1.8版本里就将该函数放在filters模块里。并在keypoints模块里也包含了这个头文件
#warning UniformSampling is not a Keypoint anymore, use <pcl/filters/uniform_sampling.h> instead.
这是keypoints模块下的说明
用法是:
PointCloud<PointXYZ> output_;
  filter.filter (output_);