PCL预处理Filtering

预处理Filtering

  • 常用Filtering
    • PassThrough filter
    • VoxelGrid filter
    • StatisticalOutlierRemoval filter
    • Projecting points using a parametric model
    • Extracting indices from a PointCloud
    • Removing outliers using a Conditional or RadiusOutlier removal

常用Filtering

PassThrough filter

沿着指定的维度执行简单的过滤,即截断给定用户范围内或外部的值(x、y、z)。

  pcl::PassThrough<pcl::PointXYZ> pass;
  pass.setInputCloud (cloud);
  pass.setFilterFieldName ("z"); //z轴方向的过滤
  pass.setFilterLimits (0.0, 1.0); //基于点云原点的0-1m
  //pass.setFilterLimitsNegative (true);
  pass.filter (*cloud_filtered);

VoxelGrid filter

使用体素化网格方法缩小点云数据集的采样(降采样)

  pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
  sor.setInputCloud (cloud);
  sor.setLeafSize (0.01f, 0.01f, 0.01f);创建格子大小为1cm的体素网格过滤器
  sor.filter (*cloud_filtered);

StatisticalOutlierRemoval filter

用于移除异常值
使用统计分析技术从点云数据集中移除噪声测量

//所有与查询点的平均距离的标准差大于1的点都将被标记为异常值并被删除
  pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
  sor.setInputCloud (cloud);
  sor.setMeanK (50);//每个点要分析的邻居数设置为50
  sor.setStddevMulThresh (1.0);//标准差乘数设置为1
  sor.filter (*cloud_filtered);

Projecting points using a parametric model

将点投影到参数化模型(例如,平面、球体等)上。参数模型是通过一组系数给出的,在平面的情况下,通过方程:ax+by+cz+d=0。

  // Create a set of planar coefficients with X=Y=0,Z=1
  pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
  coefficients->values.resize (4);
  coefficients->values[0] = coefficients->values[1] = 0;
  coefficients->values[2] = 1.0;
  coefficients->values[3] = 0;

  // Create the filtering object
  pcl::ProjectInliers<pcl::PointXYZ> proj;
  proj.setModelType (pcl::SACMODEL_PLANE);
  proj.setInputCloud (cloud);
  proj.setModelCoefficients (coefficients);
  proj.filter (*cloud_projected);

Extracting indices from a PointCloud

根据分段算法输出的索引从点云中提取点的子集

// Create the filtering object
pcl::ExtractIndices<pcl::PointXYZ> extract;
int i = 0, nr_points = (int) cloud_filtered->points.size ();
// While 30% of the original cloud is still there
//为了处理多个模型,我们在一个循环中运行这个过程,在提取每个模型之后,我们返回获取剩余的点,然后迭代
while (cloud_filtered->points.size () > 0.3 * nr_points)
{
  // Segment the largest planar component from the remaining cloud
  seg.setInputCloud (cloud_filtered);
  seg.segment (*inliers, *coefficients);
  if (inliers->indices.size () == 0)
  {
    std::cerr << "Could not estimate a planar model for the given dataset." << std::endl;
    break;
  }

  // Extract the inliers
  extract.setInputCloud (cloud_filtered);
  extract.setIndices (inliers);
  extract.setNegative (false);
  extract.filter (*cloud_p);
  std::cerr << "PointCloud representing the planar component: " << cloud_p->width * cloud_p->height << " data points." << std::endl;

  std::stringstream ss;
  ss << "table_scene_lms400_plane_" << i << ".pcd";
  writer.write<pcl::PointXYZ> (ss.str (), *cloud_p, false);

  // Create the filtering object
  extract.setNegative (true);
  extract.filter (*cloud_f);
  cloud_filtered.swap (cloud_f);
  i++;
}

return (0);
}

Removing outliers using a Conditional or RadiusOutlier removal

使用条件或半径异常值移除移除异常值,使用筛选器模块中的几种不同方法从点云中删除异常值

if (strcmp(argv[1], "-r") == 0){
    pcl::RadiusOutlierRemoval<pcl::PointXYZ> outrem;
    // build the filter
    //搜索半径设置为0.8,并且一个点在该半径中必须至少有两个邻居
    outrem.setInputCloud(cloud);
    outrem.setRadiusSearch(0.8);
    outrem.setMinNeighborsInRadius (2);
    outrem.setKeepOrganized(true);
    // apply filter
    outrem.filter (*cloud_filtered);
  }
  else if (strcmp(argv[1], "-c") == 0){
    // build the condition
    //大于(GT)0.0和小于(LT)0.8
    pcl::ConditionAnd<pcl::PointXYZ>::Ptr range_cond (new
      pcl::ConditionAnd<pcl::PointXYZ> ());
    range_cond->addComparison (pcl::FieldComparison<pcl::PointXYZ>::ConstPtr (new
      pcl::FieldComparison<pcl::PointXYZ> ("z", pcl::ComparisonOps::GT, 0.0)));
    range_cond->addComparison (pcl::FieldComparison<pcl::PointXYZ>::ConstPtr (new
      pcl::FieldComparison<pcl::PointXYZ> ("z", pcl::ComparisonOps::LT, 0.8)));
    // build the filter
    pcl::ConditionalRemoval<pcl::PointXYZ> condrem;
    condrem.setCondition (range_cond);
    condrem.setInputCloud (cloud);
    condrem.setKeepOrganized(true);
    // apply filter
    condrem.filter (*cloud_filtered);
  }

你可能感兴趣的:(PCL)