PCL study: point cloud features - the normal estimate (1)

Calculated surface normal, two solutions:
(1) surface reconstruction techniques, to obtain concentrated samples corresponding surface point cloud data acquired from the surface normal then calculated from the model surface;
(2) data directly from the point cloud inferred approximate surface normal concentration.
This section will be described for the latter case, a point cloud data set is known at each point where the surface normal is approximately calculated directly.

1. Theoretical basis

(1) Estimation of normal

Identify problems that surface normal of the approximate estimation of the surface normal of a tangent plane, and therefore after conversion becomes over a least squares estimation fitting plane; it is estimated that the surface normal of the solution becomes Analysis eigenvalues ​​and eigenvectors (or a principal component analysis PCA) a covariance matrix, the covariance matrix created from near-neighbor of the query point. More specifically, for each point Pi, corresponding to the covariance matrix C as follows:

(2) normal orientation: same direction toward the viewpoint

2. Select the appropriate scale

In estimating the surface normal of a point, we need support from neighboring points around this point to proceed <h also called neighborhood>. Nearest neighbor estimation of the specific content and raises another question "appropriate scale": a known sample point cloud data set, h is the number of correct values ​​ω by pcl:: Feature:: setKSearch given> or determine a r r is the radius point used for nearest neighbor set within a radius of the circle should be what values ​​(r by pcl:: Feature:: given setRadiusSearch>:

It can be roughly assumed to desired application needs the reference details, choose OK neighborhood point scale used. Briefly, the curvature of the edge between the cup and the cylindrical portion if the handle is important, it needs to be small enough scale to capture the details, and select a large-scale application of other unwanted details.

 3. normals estimation example

Data input to cloud point set point estimate a set of surface normals. Operation is performed, the corresponding point in each point cloud P p:

P points to obtain surface nearest neighbors to calculate the normal N p points, to check whether the N direction pointing viewpoint if it is not turned over.

#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/features/integral_image_normal.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>

int
main ()
 {
//加载点云
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile ("..\\..\\source\\table_scene_lms400.pcd", *cloud);
//估计法线
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud (cloud);
//创建一个空的kdtree对象,并把它传递给法线估计对象
//基于给出的输入数据集,kdtree将被建立
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>);
//使用半径在查询点周围3厘米范围内的所有邻元素
ne.setRadiusSearch (0.03);
//计算特征值
ne.compute (*cloud_normals);
// cloud_normals->points.size ()应该与input cloud_downsampled->points.size ()有相同尺寸
//法线可视化
pcl::visualization::PCLVisualizer viewer("PCL Viewer");
viewer.setBackgroundColor (0.0, 0.0, 0.0);
viewer.addPointCloudNormals<pcl::PointXYZ,pcl::Normal>(cloud, cloud_normals);

while (!viewer.wasStopped ())
{
     viewer.spinOnce ();
}

return 0;
}

.\normal_estimation.exe 

Description:

1,视点默认坐标是(0,0,0)可使用如下函数替换:

setViewPoint (float vpx, float vpy, float vpz);

2,如果要计算单个点的法线,使用

computePointNormal (const pcl::PointCloud<PointInT> &cloud, const std::vector<int> &indices, Eigen::Vector4f &plane_parameters, float &curvature);

此处, cloud 是包含点的输入点云, indices 是点的 k-最近邻元素集索引, plane_parameters 和 curvature 是法线估计的输出, plane _ parameters 前 三个 坐标中,以( nx, ny, nz )来表示法线,第四个坐标 D = nc . p_ plane (centroid here) + p . 输出表面曲率 curvature 通过协方差矩阵的特征值之间的运算估计得到,如下:

\sigma = \frac{\lambda_0}{\lambda_0 + \lambda_1 + \lambda_2}

3,使用 OpenMP 加速法线估计

对于对运算速度有要求的用户,PCL 点云库提供了一个表面法线的附加实现程序,它使用多核/多线程开发规范利用 OpenMP 来提高计算速度。它的类命名为pcl: : NormaleEstimationOMP,并且它的应用程序接口 CAPD lOO%兼容单线程 pcl: :
NormalEstimation ,这使它适合作为一个可选提速方法。在 8 核系统中可以轻松提6-8倍。

Guess you like

Origin blog.csdn.net/zfjBIT/article/details/93620439