PCL编程-法向量计算

来源:互联网 发布:使命召唤13优化怎么样 编辑:程序博客网 时间:2024/05/22 04:23

【原文:http://blog.csdn.net/q597967420/article/details/12220865】

NormalEstimationPCL中计算法向量的类。原理是通过对邻域点集求PCA来得到法向量。对领域点的三维坐标进行中心化,求得协方差矩阵并对角化,求得三个特征值,最小特征值对应的特征向量就是法向量。

包含的库:

[cpp] view plain copy
  1. #include <pcl/features/normal_3d.h>   
使用方法:

[cpp] view plain copy
  1. NormalEstimation<PointXYZRGBA, Normal> normObj;  //创建法向量计算对象  
  2.     normObj.setInputCloud (cloud);                  //设置输入点云  
  3.     //search::OrganizedNeighbor<PointXYZRGBA>::Ptr tree(new search::OrganizedNeighbor<PointXYZRGBA>());  
  4.     search::KdTree<PointXYZRGBA>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZRGBA> ());     
  5.     normObj.setSearchMethod (tree); //设置搜索方法  
  6.     normObj.setRadiusSearch (0.05); //设置半径邻域搜索  
  7.     //normObj.setKSearch(30);       //设置K邻域搜索  
  8.     PointCloud<Normal>::Ptr normals (new PointCloud<Normal>); //创建法向量点云  
  9.     normObj.compute (*normals); //计算法向量  
对于无序点云,采用的是KD树搜索,如果是organized点云,可以直接索引到邻域。用OrganizedNeighbor搜索邻域将会更快速。


Organized点云(有序点云)是由深度图转换过来的,一个像素格对应一个点,类似于二维的图像,由Kinect采集到的点云就是有序点云。对于有序点云,可以用IntegralImageNormalEstimation更快速的计算法向量。

算法原理参考:Dirk Holz. Real-Time Plane Segmentation Using RGB-D Cameras

包含库:

[cpp] view plain copy
  1. #include <pcl/features/integral_image_normal.h>   

使用方法:

[cpp] view plain copy
  1. PointCloud<Normal>::Ptr normals (new pcl::PointCloud<Normal>);  
  2. normals->width = cloud->width;normals->height=cloud->height;normals->resize(normals->width*normals->height);  
  3. IntegralImageNormalEstimation<PointXYZRGBA, Normal> ne;  
  4. ne.setNormalEstimationMethod (ne.AVERAGE_3D_GRADIENT);  
  5. /*COVARIANCE_MATRIX - creates 9 integral images to compute the normal for a specific point from the covariance matrix of its local neighborhood.  
  6. AVERAGE_3D_GRADIENT - creates 6 integral images to compute smoothed versions of horizontal and vertical 3D gradients and computes the normals using the cross-product between these two gradients.  
  7. AVERAGE_DEPTH_CHANGE - creates only a single integral image and computes the normals from the average depth changes.*/  
  8. ne.setMaxDepthChangeFactor(0.01f);  
  9. ne.setNormalSmoothingSize(10.0f);  
  10. ne.setInputCloud(cloud);  
  11. ne.compute(*normals);  




对比:

PCA计算得到的法向量,精度高,但是耗时太大,对于640*480的点云,耗时近10S,就算改用有序邻域搜素,仍然要5S。无法满足实时性要求。

积分图计算法向量,实际上就是二个切向量叉乘,精度很差,就算通过平滑,效果仍然比不上PCA,但时间快速,640*480的点云,耗时不超过200ms。适用于实时性高的场合。



0 0
原创粉丝点击