【问题标题】:How can I compute a normal for each point in cloud如何计算云中每个点的法线
【发布时间】:2015-12-21 16:52:47
【问题描述】:

我的问题是:我有 3D 点云。我想将每个法线归因于每个点。来自 PCL 教程:

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

// 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);

我只能找到所有云的法线,我想根据每个点的确切法线分配它。

【问题讨论】:

    标签: c++ point-cloud-library point-clouds normals


    【解决方案1】:

    我假设您有 pcl::PointCloud&lt;pcl::PointXYZRGB&gt; 类型的点云,并且您希望将估计的表面法线分配给点云的每个点。

    为输入点云的每个点估计表面法线。所以表面法线点云的大小等于输入点云的大小。

    您可以创建另一个pcl::PointCloud&lt;pcl::PointXYZRGBNormal&gt; 类型的点云,它可以保存相应法线的信息以及点的位置和颜色。然后写一个for循环赋值。

    下面是sn-p的代码:

    pcl::PointCloud<pcl::PointXYZRGB>& src; // Already generated
    pcl::PointCloud<pcl::PointXYZRGBNormal> dst; // To be created
    
    // Initialization part
    dst.width = src.width;
    dst.height = src.height;
    dst.is_dense = true;
    dst.points.resize(dst.width * dst.height);
    
    // Assignment part
    for (int i = 0; i < cloud_normals->points.size(); i++)
    {
        dst.points[i].x = src.points[i].x;
        dst.points[i].y = src.points[i].y;
        dst.points[i].z = src.points[i].z;
    
        dst.points[i].r = src.points[i].r;
        dst.points[i].g = src.points[i].g;
        dst.points[i].b = src.points[i].b;
    
       // cloud_normals -> Which you have already have; generated using pcl example code 
    
        dst.points[i].curvature = cloud_normals->points[i].curvature;
    
        dst.points[i].normal_x = cloud_normals->points[i].normal_x;
        dst.points[i].normal_y = cloud_normals->points[i].normal_y;
        dst.points[i].normal_z = cloud_normals->points[i].normal_z;
    }
    

    我希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      您可以使用pcl::concatenateFields,而不是使用for 循环:

          pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
          pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals (new pcl::PointCloud<pcl::PointNormal>); 
          pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
          // Use all neighbors in a sphere of radius 3cm
          ne.setRadiusSearch (0.03);
          // Compute the features
          ne.compute (*normals);
          pcl::concatenateFields(*cloud, *normals, *cloud_with_normals); 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-06
        • 2013-09-02
        • 2013-05-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-25
        • 1970-01-01
        相关资源
        最近更新 更多