【问题标题】:Point cloud extraction depending on normal direction根据法线方向提取点云
【发布时间】:2021-03-26 03:31:38
【问题描述】:

我想使用 PCL(点云库)仅提取法线向上或接近向上的点。有一个用于估计表面法线的示例代码,但没有如何提取它。有人已经这样做了吗?

#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>

{
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);

  // read, pass in or create a point cloud ...

  // Create the normal estimation class, and pass the input dataset to it
  pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
  ne.setInputCloud (cloud);

  // Create an empty kdtree representation, and pass it to the normal estimation object.
  // Its content will be filled inside the object, based on the given input dataset (as no other search surface is given).
  pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());
  ne.setSearchMethod (tree);

  // Output datasets
  pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);

  // Use all neighbors in a sphere of radius 3cm
  ne.setRadiusSearch (0.03);

  // Compute the features
  ne.compute (*cloud_normals);

  // cloud_normals->size () should have the same size as the input cloud->size ()*
}

【问题讨论】:

    标签: c++ point-cloud-library


    【解决方案1】:

    没有专门的类可以做到这一点,但实现起来相当简单。您遍历所有法线点,如果法线与您想要的方向“足够接近”(由 dot product 确定 - 假设两个向量都已标准化),则将索引保存在 pcl::PointIndices 中。

    pcl::ExtractIndices 然后可用于从cloudcloud_normals 中提取子云。

    pcl::PointIndicesPtr FilterByNormal(pcl::PointCloud<pcl::Normal>::ConstPtr cloud_normals, const Eigen::Vector3f requiredDirection, float maxAngleDeg)
    {
        float thresh = std::cos(maxAngleDeg * M_PI / 180.0);
        
        pcl::PointIndicesPtr indices = pcl::PointIndicesPtr(new pcl::PointIndices);
        for (auto i = 0; i < cloud_normals->size(); ++i)
        {
            const auto& normal = cloud_normals->points[i].getNormalVector3fMap();
            if (normal.dot(requiredDirection) >= thresh)
            {
                indices->indices.push_back(i);
            }
        }
    
        return indices;
    }
    

    或者,您可以在循环中构建所需的输出云,而无需中间 pcl::PointIndices

    【讨论】:

      猜你喜欢
      • 2022-06-10
      • 2014-06-01
      • 2014-08-31
      • 1970-01-01
      • 1970-01-01
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      • 2015-08-24
      相关资源
      最近更新 更多