如何计算云中每个点的法线

lot*_*ine 0 c++ normals point-clouds point-cloud-library

我的问题是:我有 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);
Run Code Online (Sandbox Code Playgroud)

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

Sat*_*tya 5

我假设你有这样的点云pcl::PointCloud<pcl::PointXYZRGB>,并且您希望将估计的表面法线分配给点云的每个点。

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

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

下面是代码片段:

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;
}
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助。