简体   繁体   中英

PCL Cloud Normals Non-Deterministic in Simple Test Case

I am trying to figure out if the unorganized surface normal estimation should be deterministic based on a given point cloud; I presumed it should based on this explanation: http://pointclouds.org/documentation/tutorials/normal_estimation.php#normal-estimation

However, when generating a uniform 3x3 surface cuboid (ie 26 points in total), and do an 8 nearest neighbor normal estimate over the entire cloud, the 6 points which lie at the center of the 6 cube surfaces do not line up with the co-ordinate axes, and seem rather chaotic. This is surprising, as I understood that this choice of '8' nearest neighbors should constrain the normal estimates for these 6 central surface points to be based only on the other points on the same planar surface. Here is a snippet of the code:.

    // compute normals
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud (cloud_ptr);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());
ne.setSearchMethod (tree);
pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
ne.setKSearch(8);
ne.compute (*cloud_normals);

for (int i =0; i<cloud_ptr->size(); i++)
{
    cout << "x: " << cloud_ptr->points.at(i).x << "  y: " << cloud_ptr->points.at(i).y << "  z: " << cloud_ptr->points.at(i).z << endl;
}

for (int i =0; i<cloud_normals->size(); i++)
{
    cout << "x: " << cloud_normals->points.at(i).normal_x << "  y: " << cloud_normals->points.at(i).normal_y << "  z: " << cloud_normals->points.at(i).normal_z << endl;
}

cout << cloud_ptr->size() << endl;
cout << cloud_normals->size() << endl;

And the Output:

x: -1  y: -1  z: 1
x: -1  y: 0  z: 1
x: -1  y: 1  z: 1
x: 0  y: -1  z: 1
x: 0  y: 0  z: 1
x: 0  y: 1  z: 1
x: 1  y: -1  z: 1
x: 1  y: 0  z: 1
x: 1  y: 1  z: 1
x: -1  y: -1  z: -1
x: -1  y: 0  z: -1
x: -1  y: 1  z: -1
x: 0  y: -1  z: -1
x: 0  y: 0  z: -1
x: 0  y: 1  z: -1
x: 1  y: -1  z: -1
x: 1  y: 0  z: -1
x: 1  y: 1  z: -1
x: -1  y: -1  z: 0
x: -1  y: 0  z: 0
x: -1  y: 1  z: 0
x: 1  y: -1  z: 0
x: 1  y: 0  z: 0
x: 1  y: 1  z: 0
x: 0  y: -1  z: 0
x: 0  y: 1  z: 0
x: 0.642542  y: 0.417468  z: -0.642542
x: 0.81252  y: 0.0985752  z: -0.574538
x: 0.642542  y: -0.417468  z: -0.642542
x: -0.0985752  y: 0.574539  z: -0.81252
x: -0.196116  y: 0  z: -0.980581
x: -0.0985752  y: -0.574539  z: -0.81252
x: -0.642542  y: 0.642542  z: -0.417468
x: -0.81252  y: -0.0985752  z: -0.574538
x: -0.642542  y: -0.642542  z: -0.417468
x: 0.642542  y: 0.642542  z: 0.417468
x: 0.81252  y: 0.0985752  z: 0.574538
x: 0.642542  y: -0.642542  z: 0.417468
x: -0.0985752  y: 0.81252  z: 0.574539
x: -0.196116  y: 0  z: 0.980581
x: -0.0985752  y: -0.81252  z: 0.574539
x: -0.642542  y: 0.417468  z: 0.642542
x: -0.81252  y: -0.0985752  z: 0.574538
x: -0.642542  y: -0.417468  z: 0.642542
x: 0.81252  y: 0.574538  z: -0.0985752
x: 1  y: -0  z: -0
x: 0.81252  y: -0.574538  z: 0.0985752
x: -0.81252  y: 0.574538  z: -0.0985752
x: -0.987623  y: 0.153347  z: -0.0329405
x: -0.574539  y: -0.81252  z: 0.0985752
x: 0.153347  y: 0.987623  z: -0.0329405
x: 0.153347  y: -0.987623  z: -0.0329405
26
26

I'm sure I haven't made any mistakes with the cube co-ordinates, which show up perfectly as expected in the cloud viewer.

Any help greatly appreciated!

It is deterministic when the 8 nearest neighbors are deterministic... In your test case (a 3x3 cube shell, the 8 nearest neighbors of any face center point is actually non deterministic) ie: it first will grab the 4 nearest points vertical and horizontal edge points, but the next 4 points is not so clear, it could grab the 4 corner vertices you want, or it could grab the centers of the 4 connected faces (which are all equidistant).

I tested this in pcl and it is indeed the case. If you increase the number of points on each face to 5, then you indeed will have the perfect central face normals that you are after.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM