PCL筆記

PCL中常用數據結構

pcl::PointCloud

PointCloud類包含以下成員變量:
注意PointCloud模板類是點雲類,其是由很多個點組成的。

width——點雲寬度
height——點雲高度

用點雲數據集中的點數初始化width,width其實有兩個含義:
(1)對於無組織或者說無結構的點雲來說,width就是指點雲中點的個數。
(2) 對於有結構的點雲來說,width是指點雲數據集一行上點的個數。有結構的點雲可以理解成這個點雲像image(或者說是一個矩陣)一樣進行組織,數據被分爲行和列,如立體相機或者TOF相機獲得的點雲數據就屬於這一類。對於有結構點雲的一大好處就是能知道點雲中點的相鄰關係,最近鄰操作效率就非常高,可以大大提高PCL中相應算法的效率。

用點雲數據集中點的高度(就是行數)初始化height,height同樣有兩個函數:
(1)對於有結構點雲來說,height代表點雲的總行數
(2)對於無結構的點雲來說,height值爲1,因此這也經常用來判斷點雲是或者不是一個有結構的點雲。

pcl::PointCloud<pcl::PointXYZ> cloud;
std::vector<pcl::PointXYZ> data = cloud.points;

存儲了數據類型爲PointT的一個動態數組,例如,對於一個包含了XYZ數據的點雲,points是包含了元素爲pcl::PointXYZ一個vector。

is_dense (bool) 

判斷points中的數據是否是有限的(有限爲true)或者說是判斷點雲中的點是否包含 Inf/NaN這種值(包含爲false)。

sensor_origin_ (Eigen::Vector4f) 

代表了相應傳感器的位置座標(可能是經過平移的),這個數據成員是可選,在大多數的PCL算法中不會使用。

sensor_orientation_ (Eigen::Quaternionf) 

代表了相應傳感器的朝向,這個數據成員是可選,在大多數的PCL算法中不會使用。


pcl::PointXYZ

  pcl::PointXYZ::PointXYZ ( float_x,
                      float_y,
                      float_z
                        ) 

pcl::PointXYZI

union {
   struct {
      float   intensity
   } 	
   float   data_c [4]
}; 

pcl::PointXYZRGB

Eigen::Vector3i 	getRGBVector3i ()
const Eigen::Vector3i 	getRGBVector3i () const
Eigen::Vector4i 	getRGBVector4i ()
const Eigen::Vector4i 	getRGBVector4i () const
 	PointXYZRGB (const _PointXYZRGB &p)
 	PointXYZRGB ()
 	PointXYZRGB (uint8_t _r, uint8_t _g, uint8_t _b)
//其中PointXYZRGB	爲
pcl::PointXYZRGB::PointXYZRGB	(	uint8_t 	_r,
uint8_t 	_g,
uint8_t 	_b 
)		[inline]


pcl::PCLPointCloud2

struct PCLPointCloud2
         {
          PCLPointCloud2 () : header (), height (0), width (0), fields (),
         is_bigendian (false), point_step (0), row_step (0),
          data (), is_dense (false)
          {
         #if defined(BOOST_BIG_ENDIAN)
          is_bigendian = true;
         #elif defined(BOOST_LITTLE_ENDIAN)
          is_bigendian = false;
         #else
         #error "unable to determine system endianness"
         #endif
          } 
      ::pcl::PCLHeader header;
     
      pcl::uint32_t height;
      pcl::uint32_t width;
     
      std::vector< ::pcl::PCLPointField> fields;
     
      pcl::uint8_t is_bigendian;
      pcl::uint32_t point_step;
      pcl::uint32_t row_step; 
      std::vector<pcl::uint8_t> data; 
      pcl::uint8_t is_dense; 
      public:
      typedef boost::shared_ptr< ::pcl::PCLPointCloud2> Ptr;
      typedef boost::shared_ptr< ::pcl::PCLPointCloud2 const> ConstPtr;
      }; // struct PCLPointCloud2 

相互裝換

 PointCloud<PointXYZ>和PointCloud<PointXYZRGB> 
PointCloud<PointXYZ> cloud_xyz;
// [...]
PointCloud<PointXYZRGB> cloud_xyzrgb;
copyPointCloud(cloud_xyz, cloud_xyzrgb);

cloud_filtered_blob 聲明的數據格式爲pcl::PCLPointCloud2::Ptr  cloud_filtered_blob (new pcl::PCLPointCloud2);
cloud_filtered 申明的數據格式  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>) 
pcl::fromPCLPointCloud2 (*cloud_filtered_blob, *cloud_filtered);

void pcl::fromPCLPointCloud(const pcl:PCLPointCloud2 & msg  pcl::PointCloud<PointT>  & cloud const MsgFieldMap & filed_map)
void pcl::fromPCLPointCloud2(const pcl::PCLPointCloud & msg pcl::PointCloud<pointT> &cloud )
void pcl::fromROSMsg(const pcl:PCLPointCloud2 & msg pcl::PointCloud<PointT>  & cloud  )

參考:http://docs.ros.org/hydro/api/pcl/html/namespacepcl.html

濾波 filter

PassThrough

  1. 空間切割

只保留設定範圍內的點,超出邊界的就過濾掉了。

pcl::PassThrough<pcl::PointXYZ> pass;
pass.setInputCloud (cloud);
pass.setFilterFieldName ("z");
pass.setFilterLimits (0.0, 1.0);
//pass.setFilterLimitsNegative (true);
pass.filter (*cloud_filtered);

代表了是否顯示被過濾掉的點,如果設置爲true則將被過濾的以紅色表示,沒過濾的用綠色表示。默認是false.
cloud就是需要過濾的點雲,cloud_filtered就是過濾後的點雲,使用setFilterFieldName來設置過濾Z軸,用setFilterLimits來設置範圍,也就是隻保留z座標在0-1之間的點,其他的全部不要了。

  1. 圓形濾波

遍歷圖像中每一個點,如果他周圍給定半徑內點的數量小於自己設置的一個閾值,那麼這一個點將被忽略。

pcl::PassThrough<pcl::PointXYZ> pass;
pass.setInputCloud (cloud);
pass.setRadiusSearch (0.2);
pass.setMinNeighborsInRadius (20);
pass.filter (*cloud_filtered);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章