PCL程式設計-法向量計算

查志強發表於2016-08-26

【原文: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。適用於實時性高的場合。



相關文章