pcl_common庫包含大多數PCL庫使用的公共數據結構和方法。核心數據結構包括PointCloud類和許多用於表示點、表面法線、RGB顏色值、特征描述符等的點類型。它還包含許多用於計算距離/范數、均值和協方差、角度轉換、幾何變換,等等。這個模塊是不依賴其他模塊的,所以是可以單獨編譯成功,單獨編譯出來可利用其中的數據結構自行開發,當然想單獨提取出來編譯時需要自行修改cmakeLists的,這里就不再贅述。
那么我們就按順序來解釋其中每個函數的作用,有必要的話,我會解釋其理論並結合代碼實踐。
PCL_common的類:
(1) class pcl::BivariatePolynomialT< real >
這表示一個二元多項式,並為它提供了一些功能接口。
(2)class pcl::CentroidPoint< PointT >
一個泛型類,它計算給輸入點雲的質心。
這里我們用“重心”不僅表示3D點坐標的平均值,而且表示其他數據字段中的值的平均值。通用的computeNDCentroid()函數也實現了這種功能,但它是以“不智能”的方式實現的,也就是說,不管字段內數據的語義如何,它都只是對值進行平均。在某些情況下(例如,對於x,y,z,強度場),這種行為是合理的,但是在其他情況下(例如,rgb,rgba,rgbl(label帶標簽的)),這並不會導致有意義的結果。
這個類能夠以一種“智能”的方式計算質心,即考慮字段內數據的含義。目前支持以下字段:
* XYZ (x, y, z) 計算每個字段的平均值
* Normal (normal_x, normal_y, normal_z) 對每個字段平均值,並將得到的歸一化的向量。
* Curvature (curvature) 曲率的平均值
* RGB/RGBA (rgb or rgba) rgba每個通道的平均值
* Intensity (intensity) 強度平均值
* Label (label) 標簽字段的平均值
舉例子
CentroidPoint<pcl::PointXYZ> centroid; centroid.add (pcl::PointXYZ (1, 2, 3); centroid.add (pcl::PointXYZ (5, 6, 7); //這里是在centroid點集中加兩個點 pcl::PointXYZ c1; centroid.get (c1); //直接使用get函數獲取該點集的在每個字段的均值 // 得到的結果是: c1.x == 3, c1.y == 4, c1.z == 5 // 我們也可以申明一個不一樣字段的點雲來存儲結果 pcl::PointXYZRGB c2; centroid.get (c2); // 其中x,y,z字段的結果還是: c2.x == 3, c2.y == 4, c2.z == 5, // 但是 c2.rgb 是不被觸及的
(3)struct pcl::NdConcatenateFunctor< PointInT, PointOutT >
點雲點集相加的輔助函數
在這里要特別申明一下點雲庫中點雲的相加有兩種方式:
-
比如:cloud_c = cloud_a;
cloud_c += cloud_b;//把cloud_a和cloud_b連接一起創建cloud_c 后輸出
輸出如下圖:
-
字段相加就會使用到該輔助函數,那么輸出結果如下:
(4)class pcl::FeatureHistogram
用於計算一些浮點數均值和方差的直方圖類型。
GlobalDescriptorsPtr global_descriptor; global_descriptor = computeGlobalDescriptor (cloud, normals); pcl::visualization::PCLHistogramVisualizer hist_vis; hist_vis.addFeatureHistogram (*global_descriptor, 308, "Global descriptor");
(5)class pcl::GaussianKernel
高斯核類集合了所有使用高斯核計算、卷積、平滑、梯度計算圖像的方法。
float* kernel_ptr_host; int kernel_size = 5; float sigma = 1.0; kernel_ptr_host = probability_processor_->CreateGaussianKernel(sigma, kernel_size);
(6)class pcl::PCA< PointT >
主成分分析(PCA)類。
通過對輸入點雲集中心點的協方差矩陣進行奇異值分解,提取主成分。pca計算后的可用數據有輸入數據的平均值、特征值(降序)和相應的特征向量。
其他方法允許在特征空間中進行投影、從特征空間重構以及用新的數據更新特征空間(根據Matej Artec, Matjaz Jogan and Ales Leonardis: "Incremental PCA for On-line Visual Learning and Recognition”)。
pcl::PCA<pcl::PointXYZ> pca; pcl::PointXYZ projected, reconstructed; for(size_t i = 0; i < cloud.size(); i++) { pca.project (cloud[i], projected); pca.reconstruct (projected, reconstructed); }
(7)class pcl::PiecewiseLinearFunction
提供了返回有效分段線性函數的值的功能。
inline float PiecewiseLinearFunction::getValue(float point) const { float vector_pos = factor_*point + offset_; float floored_vector_pos = floor(vector_pos); float interpolation_size = vector_pos-floored_vector_pos; int data_point_before = (std::max)(0, (std::min)(int(data_points_.size())-2, int(lrint(floored_vector_pos)))); //cout << "Interpolating between "<<data_point_before<<" and "<<data_point_before+1<<" with value " //<< interpolation_size<<" (vector size is "<<data_points_.size()<<").\n"; return data_points_[data_point_before]+interpolation_size*(data_points_[data_point_before+1]-data_points_[data_point_before]); }
(8)class pcl::PolynomialCalculationsT< real >
為多項式提供了一些功能,如尋找根或逼近二元多項式。
PolynomialCalculationsT<RealForPolynomial> polynomial_calculations; BivariatePolynomialT<RealForPolynomial> polynomial (2); float interest_value2 = interest_image_[index2]; sample_points.push_back (Eigen::Vector3d (x2-keypoint_x_int, y2-keypoint_y_int, interest_value2)); polynomial_calculations.bivariatePolynomialApproximation (sample_points, 2, polynomial)
(9)class pcl::PosesFromMatches
基於點對應的關系計算他們之間的三維空間變換
(10)class pcl::StopWatch
一個用於計時的秒表。
// Time measurements pcl::StopWatch sw; pcl::StopWatch sw_total; double t_select = 0.; double t_build = 0.; double t_nn_search = 0.; double t_calc_trafo = 0.; .... sw.reset (); ... t_select = sw.getTime (); sw.reset (); kd_tree_->setInputCloud (cloud_model_selected); t_build = sw.getTime (); ... t_nn_search += sw.getTime ();
(11)class pcl::ScopeTime
測量作用在作用域中的時間。
要使用這個類,例如測量函數中所花費的時間,只需在函數的開頭創建一個實例。例子
{ pcl::ScopeTime t1 ("calculation"); // ... perform calculation here }
(12)class pcl::EventFrequency
一個輔助類來測量某個事件的頻率。
(13)class pcl::TimeTrigger
定時調用回調函數的計時器類。
(14)class pcl::TransformationFromCorrespondences
基於對應的3D點計算變換。
pcl::TransformationFromCorrespondences transformation_from_correspondeces; transformation_from_correspondeces.reset (); transformation_from_correspondeces.add (corr1, point1); transformation_from_correspondeces.add (corr2, point2); transformation_from_correspondeces.add (corr3, point3); transformation_from_correspondeces.add (corr4, point4); transformation_from_correspondeces.add (corr5, point5); transformation_from_correspondeces.add (corr6, point6); transformation_from_correspondeces.add (corr7, point7); transformation_from_correspondeces.add (corr8, point8); ++counter_for_added_pose_estimates; PoseEstimate pose_estimate; pose_estimate.transformation = transformation_from_correspondeces.getTransformation (); pose_estimate.score = 0.5f * (correspondence1.distance + correspondence2.distance); // TODO: base on the measured distance_errors? pose_estimate.correspondence_indices.push_back (correspondence1_idx); pose_estimate.correspondence_indices.push_back (correspondence2_idx); pose_estimates.push_back (pose_estimate);
(15)class pcl::VectorAverage< real, dimension >
計算給定權重的一組向量的加權平均和協方差矩陣的類
VectorAverage3f vector_average; float max_dist_squared=max_dist*max_dist, max_dist_reciprocal=1.0f/max_dist; bool still_in_range = true; for (int radius=1; still_in_range; ++radius) { int x2=x-radius-1, y2=y-radius; // Top left - 1 still_in_range = false; for (int i=0; i<8*radius; ++i) { if (i<=2*radius) ++x2; else if (i<=4*radius) ++y2; else if (i<=6*radius) --x2; else --y2; if (!isValid (x2, y2)) { continue; } getPoint (x2, y2, neighbor); float distance_squared = (neighbor-point).squaredNorm (); if (distance_squared > max_dist_squared) { continue; } still_in_range = true; float distance = std::sqrt (distance_squared), weight = distance*max_dist_reciprocal; vector_average.add (neighbor, weight); } }
(16)struct pcl::Correspondence
對應表示兩個實體(例如,點、描述子等)之間的匹配。通過源點雲與目標點雲之間的距離來表示。
// Find Model-Scene Correspondences with KdTree // pcl::CorrespondencesPtr model_scene_corrs (new pcl::Correspondences ()); pcl::KdTreeFLANN<DescriptorType> match_search; match_search.setInputCloud (model_descriptors); // For each scene keypoint descriptor, find nearest neighbor into the model keypoints descriptor cloud and add it to the correspondences vector. for (size_t i = 0; i < scene_descriptors->size (); ++i) { std::vector<int> neigh_indices (1); std::vector<float> neigh_sqr_dists (1); if (!pcl_isfinite (scene_descriptors->at (i).descriptor[0])) //skipping NaNs { continue; } int found_neighs = match_search.nearestKSearch (scene_descriptors->at (i), 1, neigh_indices, neigh_sqr_dists); if(found_neighs == 1 && neigh_sqr_dists[0] < 0.25f) // add match only if the squared descriptor distance is less than 0.25 (SHOT descriptor distances are between 0 and 1 by design) { pcl::Correspondence corr (neigh_indices[0], static_cast<int> (i), neigh_sqr_dists[0]); model_scene_corrs->push_back (corr); } } std::cout << "Correspondences found: " << model_scene_corrs->size () << std::endl;
(17)struct pcl::PointCorrespondence3D
表示兩個不同坐標系中的兩個3D點之間的(可能的)對應關系(例如,來自特征匹配)
(18)struct pcl::PointCorrespondence6D
表示兩個點之間的(可能的)對應關系(例如來自特征匹配),是一個6DOF變換。
這三個類是繼承的關系。


(19)以下是點雲庫中已經定義好的點雲的形式
struct pcl::PointXYZ
表示Euclidean xyz坐標的點集結構類型
struct pcl::Intensity
表示單通道圖像灰度強度的點集結構類型
struct pcl::Intensity8u
一種表示單通道圖像灰度強度的點集結構類型
struct pcl::Intensity32u
表示單通道圖像灰度強度的點集結構類型
struct pcl::_PointXYZI
表示歐氏XYZ坐標的點集結構和強度值
struct pcl::PointXYZRGBA
表示歐氏XYZ坐標和RGBA顏色的點集結構類型
struct pcl::PointXYZRGB
表示歐氏XYZ坐標和RGB顏色的點集結構類型struct
pcl::PointXY
表示Euclidean xy坐標的二維點集結構類型
struct pcl::PointUV
表示像素圖像坐標的2D點集結構類型
struct pcl::InterestPoint
表示具有歐幾里德xyz坐標和興趣值的點集結構類型
給個例子關於這個特殊的類型:
pcl::visualization::RangeImageVisualizer* pcl::visualization::RangeImageVisualizer::getInterestPointsWidget ( const pcl::RangeImage& range_image, const float* interest_image, float min_value, float max_value, const pcl::PointCloud<pcl::InterestPoint>& interest_points, const std::string& name) { RangeImageVisualizer* widget = new RangeImageVisualizer; widget->showFloatImage (interest_image, range_image.width, range_image.height, min_value, max_value); widget->setWindowTitle (name); for (unsigned int i=0; i<interest_points.points.size(); ++i) { const pcl::InterestPoint& interest_point = interest_points.points[i]; float image_x, image_y; range_image.getImagePoint (interest_point.x, interest_point.y, interest_point.z, image_x, image_y); widget->markPoint (static_cast<size_t> (image_x), static_cast<size_t> (image_y), green_color, red_color); } return widget; }
struct pcl::Normal
表示法向量坐標和曲面曲率估計的點集結構類型
struct pcl::Axis
用法向量坐標表示軸的點集結構
struct pcl::PointNormal
表示歐幾里德xyz坐標的點集結構,連同法線坐標和表面曲率估計值
struct pcl::PointXYZRGBNormal
表示歐幾里德xyz坐標和RGB顏色的點集結構,以及法線坐標和表面曲率估計.
struct pcl::PointXYZINormal
表示歐幾里德xyz坐標,強度,連同法線坐標和表面曲率估計的點集結構類型。
struct pcl::PointXYZLNormal
表示歐幾里得xyz坐標,一個標簽,法線坐標和表面曲率估計的點集結構類型
struct pcl::PointWithRange
表示歐幾里德XYZ坐標的點集結構,並連同的浮點數的深度信息
struct pcl::PointWithViewpoint
表示歐幾里得xyz坐標的點集結構以及的視點的點集結構
struct pcl::MomentInvariants
表示三個矩是不變量的點集結構類型
struct pcl::PrincipalRadiiRSD
表示使用RSD計算的最小和最大表面半徑(以米為單位)的點集結構類型
struct pcl::Boundary
表示點是否位於表面邊界的點集結構
struct pcl::PrincipalCurvatures
表示主曲率及其幅值的點集結構
(20)以下是一些三維特征點描述子的點集結構,其中每個描述子都是一篇論文,希望有興趣的小伙伴加入我們,每個人分析解釋一種描述子的由來以及理論研究。
struct pcl::PFHSignature125
表示點雲的特征直方圖(PFH)的點集結構類型
struct pcl::PFHRGBSignature250
表示顏色特征點特征直方圖的點結構(PFHGB)
struct pcl::PPFSignature
用於存儲點對特征(PPF)值的點集結構
struct pcl::CPPFSignature
用於存儲點對特征(CPPP)值的點集結構
struct pcl::PPFRGBSignature
用於存儲點對顏色特征(PPFRGB)值的點集結構
struct pcl::NormalBasedSignature12
表示4-By3的特征矩陣的基於正常的簽名的點結構
struct pcl::ShapeContext1980
表示形狀上下文的點結構
struct pcl::UniqueShapeContext1960
表示唯一形狀上下文的點結構
struct pcl::SHOT352
表示OrienTations直方圖(SHOT)的通用標簽形狀的點集結構
struct pcl::SHOT1344
一種點結構,表示OrienTations直方圖(SHOT)的通用簽名-形狀+顏色。
struct pcl::_ReferenceFrame
表示點的局部參照系的結構
struct pcl::FPFHSignature33
表示快速點特征直方圖(FPFH)的點結構
struct pcl::VFHSignature308
表示視點特征直方圖(VFH)的點結構
struct pcl::GRSDSignature21
表示全局半徑的表面描述符(GRSD)的點結構。
struct pcl::BRISKSignature512
表示二進制魯棒不變可縮放關鍵點(BRISK)的點結構。
struct pcl::ESFSignature640
表示形狀函數集合的點結構(ESF)
struct pcl::GASDSignature512
表示全局對准的空間分布(GASD)形狀描述符的點結構
struct pcl::GASDSignature984
表示全局對齊空間分布(GASD)形狀和顏色描述符的點結構
struct pcl::GASDSignature7992
表示全局對齊空間分布(GASD)形狀和顏色描述符的點結構
struct pcl::GFPFHSignature16
表示具有16個容器的GFPFH描述符的點結構。
struct pcl::Narf36
表示NARF描述符的點結構
struct pcl::BorderDescription
用於存儲距離圖像中的點位於障礙物和背景之間的邊界上的結構
struct pcl::IntensityGradient
表示Xyz點雲強度梯度的點結構
struct pcl::Histogram< N >
表示N-D直方圖的點結構
struct pcl::PointWithScale
表示三維位置和尺度的點結構
struct pcl::PointSurfel
曲面,即表示歐幾里德xyz坐標的點結構,連同法向坐標、RGBA顏色、半徑、置信值和表面曲率估計。
struct pcl::PointDEM
表示數字高程圖的點結構 Digital Elevation Map. ..
class pcl::PCLBase< PointT >
PCL的基類
struct pcl::GradientXY
表示歐氏XYZ坐標的點結構和強度值
對於以上描述子的具體解讀,我們已經組織群友們,一起閱讀,並寫出自己的理解,希望大家一起能加入我們學習分享。
有興趣的小伙伴可以關注微信公眾號,加入QQ或者微信群,和大家一起交流分享吧