• PCL中的半径离群点去噪-RadiusOutlierRemoval


    该滤波器会计算每个点周围一定半径内点的密度,并将密度低于一个阈值的点移除。

    1. template <typename PointT> void
    2. pcl::RadiusOutlierRemoval::applyFilterIndices (std::vector<int> &indices)
    3. {
    4. //首先检查search_radius_是否为0,如果是,则输出错误信息,并清空indices和removed_indices_,然后返回。
    5. if (search_radius_ == 0.0)
    6. {
    7. PCL_ERROR ("[pcl::%s::applyFilter] No radius defined!\n", getClassName ().c_str ());
    8. indices.clear ();
    9. removed_indices_->clear ();
    10. return;
    11. }
    12. //如果searcher_为空指针,则根据输入的点云是否有组织结构来选择初始化OrganizedNeighbor或者KdTree的搜索类,并将输入点云的指针传递给搜索类。
    13. // Initialize the search class
    14. if (!searcher_)
    15. {
    16. if (input_->isOrganized ())
    17. searcher_.reset (new pcl::search::OrganizedNeighbor ());
    18. else
    19. searcher_.reset (new pcl::search::KdTree (false));
    20. }
    21. searcher_->setInputCloud (input_);
    22. // The arrays to be used
    23. std::vector<int> nn_indices (indices_->size ());
    24. std::vector<float> nn_dists (indices_->size ());
    25. indices.resize (indices_->size ());
    26. removed_indices_->resize (indices_->size ());
    27. int oii = 0, rii = 0; // oii = output indices iterator, rii = removed indices iterator
    28. // If the data is dense => use nearest-k search
    29. if (input_->is_dense)
    30. {
    31. // Note: k includes the query point, so is always at least 1
    32. int mean_k = min_pts_radius_ + 1;
    33. double nn_dists_max = search_radius_ * search_radius_;
    34. for (std::vector<int>::const_iterator it = indices_->begin (); it != indices_->end (); ++it)
    35. {
    36. //采用最近K邻搜索。对于每个输入点,在搜索半径内找到最近的K个点,然后根据条件判断是否将该点加入输出索引或移除索引。
    37. // Perform the nearest-k search
    38. int k = searcher_->nearestKSearch (*it, mean_k, nn_indices, nn_dists);
    39. // Check the number of neighbors
    40. // Note: nn_dists is sorted, so check the last item
    41. bool chk_neighbors = true;
    42. if (k == mean_k)
    43. {
    44. if (negative_)
    45. {
    46. chk_neighbors = false;
    47. if (nn_dists_max < nn_dists[k-1])
    48. {
    49. chk_neighbors = true;
    50. }
    51. }
    52. else
    53. {
    54. chk_neighbors = true;
    55. if (nn_dists_max < nn_dists[k-1])
    56. {
    57. chk_neighbors = false;
    58. }
    59. }
    60. }
    61. else
    62. {
    63. if (negative_)
    64. chk_neighbors = true;
    65. else
    66. chk_neighbors = false;
    67. }
    68. // Points having too few neighbors are outliers and are passed to removed indices
    69. // Unless negative was set, then it's the opposite condition
    70. if (!chk_neighbors)
    71. {
    72. if (extract_removed_indices_)
    73. (*removed_indices_)[rii++] = *it;
    74. continue;
    75. }
    76. // Otherwise it was a normal point for output (inlier)
    77. indices[oii++] = *it;
    78. }
    79. }
    80. // NaN or Inf values could exist => use radius search
    81. else
    82. {
    83. for (std::vector<int>::const_iterator it = indices_->begin (); it != indices_->end (); ++it)
    84. {
    85. //采用半径搜索。对于每个输入点,在搜索半径内找到点,然后根据条件判断是否将该点加入输出索引或移除索引。最后,调整输出数组的大小。
    86. // Perform the radius search
    87. // Note: k includes the query point, so is always at least 1
    88. int k = searcher_->radiusSearch (*it, search_radius_, nn_indices, nn_dists);
    89. // Points having too few neighbors are outliers and are passed to removed indices
    90. // Unless negative was set, then it's the opposite condition
    91. if ((!negative_ && k <= min_pts_radius_) || (negative_ && k > min_pts_radius_))
    92. {
    93. if (extract_removed_indices_)
    94. (*removed_indices_)[rii++] = *it;
    95. continue;
    96. }
    97. // Otherwise it was a normal point for output (inlier)
    98. indices[oii++] = *it;
    99. }
    100. }
    101. // Resize the output arrays
    102. indices.resize (oii);
    103. removed_indices_->resize (rii);
    104. }

  • 相关阅读:
    PIE-engine 教程 ——影像集合的使用for循环函数(北京市NDVI计算)
    Web实验总
    10:00面试,10:06就出来了,问题问的实在有点变态
    深入理解比特币原理4----比特币网络设计
    基于openGauss的五子棋AI项目
    Chrome 扩展教程之如何使用 React 构建 Chrome 扩展(教程含源码)
    用visa进行仪表通信
    【C语言】深入理解数组和指针——初识指针
    【每日一题Day336】LC146最近最少使用缓存 | 哈希表+链表
    c:Bubble Sort
  • 原文地址:https://blog.csdn.net/jacken123456/article/details/134437937