Alexander
Alexander

Reputation: 1329

Consistant normal orientation with PCL

Estimating normals of points in a point cloud using PCL works well, but I get strange normal orientation flip at particular piece of the cloud (see screenshot, normals are yellow lines). Ofcourse I can iterate through the array of normals and correct it, but maybe there is a better way to do it directly with PCL, on the fly? Using viewpoint-oriented normals is not an option because the surface is cylinder-like, so the normals are expected to point in all directions around that axis in the end.

Here is the code for the normal estimation. Basically the snippet from official tutorial:

pcl::NormalEstimationOMP<pcl::PointXYZ, pcl::Normal> n;
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
tree->setInputCloud(cloud_);
n.setInputCloud(cloud_);
n.setSearchMethod(tree);
n.setKSearch(10);
n.compute(*normals);

Point cloud triangulation with normals

Upvotes: 2

Views: 2613

Answers (1)

Matt
Matt

Reputation: 57

I think the code you are looking for can be found in the Difference of Normals Tutorial. Specifically, the lines

pcl::NormalEstimationOMP<PointXYZRGB, PointNormal> ne;
...
ne.setViewPoint (std::numeric_limits<float>::max (), 
                 std::numeric_limits<float>::max (), 
                 std::numeric_limits<float>::max ());
...
ne.compute (*normals_large_scale);

Where the setViewPoint function will flip the normals of the whole point cloud (rather than just an individual point) as long as it is called before the compute function.

For example, in this image the cloud on the left was computed before calling setViewPoint, and the cloud on the right was computed afterwards.

normals_orientation_vs_not

(You might need to open that image in a new tab to get the larger version so you can see the normal directions more clearly)

Upvotes: 1

Related Questions