最近結合例子學習(PCL)點雲庫的技術文檔,今天開始把學習的過程記錄下來,稍後會把PCL環境搭建的過程也分享出來,與大家共同學習。
學習的資源基本來自於PCL官網技術文檔 。分爲下面幾個部分來學習PCL:
- io, image_range
- registration
- filters, features, keypoints
- segmentation
- surface
- kdtree, octree
- visualization
第一部分:io
PCD格式:
3D點雲存儲的一種格式。PCD(Point Cloud Data)格式原來就存在,PCL中改進了原有版本,使用的是0.7版本(PCD_V7)。其他3D格式還有PLY(polygon文件格式),STL (主要用於CAD)等。 PCD格式頭文件用ASCII編碼,其內容每點之間都用”\n”換行隔開。
PCD文件中重要的入口參量有FIELDS(定義每一點所具有的所有維度),WIDTH(每行多少點),HEIGHT(多少行)。FIELDS示例:
FIELDS x y z # XYZ data FIELDS x y z rgb # XYZ + colors FIELDS x y z normal_x normal_y normal_z # XYZ + surface normals FIELDS j1 j2 j3 # moment invariants |
寫入PCD格式示例
讀出PCD格式示例
本人試了一下在VS中運行寫入示例程序,加入包含文件和庫文件,動態鏈接庫之後,運行時還是出現了問題(PCDwrite.exe 中的 0x75b1969b 處有未經處理的異常: 0xC06D007E: Module not found),尚未解決。
連接兩個點雲
保證兩個點雲的點field類型和數量相等,即可連接。
連接點:直接相加。 cloud_c = cloud_a; cloud_c += cloud_b;
結果:
Cloud A:
0.352222 -0.151883 -0.106395
-0.397406 -0.473106 0.292602
-0.731898 0.667105 0.441304
-0.734766 0.854581 -0.0361733
-0.4607 -0.277468 -0.916762
Cloud B:
0.183749 0.968809 0.512055
-0.998983 -0.463871 0.691785
0.716053 0.525135 -0.523004
Cloud C:
0.352222 -0.151883 -0.106395
-0.397406 -0.473106 0.292602
-0.731898 0.667105 0.441304
-0.734766 0.854581 -0.0361733
-0.4607 -0.277468 -0.916762
0.183749 0.968809 0.512055
-0.998983 -0.463871 0.691785
0.716053 0.525135 -0.523004
連接field: pcl::concatenateFields (cloud_a, n_cloud_b, p_n_cloud_c);
結果:
Cloud A:
0.352222 -0.151883 -0.106395
-0.397406 -0.473106 0.292602
-0.731898 0.667105 0.441304
-0.734766 0.854581 -0.0361733
-0.4607 -0.277468 -0.916762
Cloud B:
0.183749 0.968809 0.512055
-0.998983 -0.463871 0.691785
0.716053 0.525135 -0.523004
0.439387 0.56706 0.905417
-0.579787 0.898706 -0.504929
Cloud C:
0.352222 -0.151883 -0.106395 0.183749 0.968809 0.512055
-0.397406 -0.473106 0.292602 -0.998983 -0.463871 0.691785
-0.731898 0.667105 0.441304 0.716053 0.525135 -0.523004
-0.734766 0.854581 -0.0361733 0.439387 0.56706 0.905417
-0.4607 -0.277468 -0.916762 -0.579787 0.898706 -0.504929
OpenNI Grabber接口
PCL提供了獲取3D點的硬件接口,其中就包括了能驅動Microsoft Kinect 和 Asus Xtion Pro的OpenNI Grabber。
#include <pcl/io/openni_grabber.h>
#include <pcl/visualization/cloud_viewer.h>
class SimpleOpenNIViewer
{
public:
SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}
void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
{
if (!viewer.wasStopped())
viewer.showCloud (cloud);
}
void run ()
{
pcl::Grabber* interface = new pcl::OpenNIGrabber();
// make callback function from member function
boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);
interface->registerCallback (f);
// start receiving point clouds
interface->start ();
// wait until user quits program with Ctrl-C, but no busy-waiting -> sleep (1);
while (!viewer.wasStopped())
{
boost::this_thread::sleep (boost::posix_time::seconds (1));
}
// stop the grabber
interface->stop ();
}
pcl::visualization::CloudViewer viewer;
};
int main ()
{
SimpleOpenNIViewer v;
v.run ();
return 0;
}
運行Tools and Demo下的pcl_openni_viewer項目的結果:
上面例子的拓展,把深度和色彩值結合,顯示在三維座標空間中
直接在環境裏面找到tutorial文件夾下的源代碼,在原路徑下Cmake生成解決方案,再編譯。 如,源代碼處選擇D:/PCL/trunk/doc/tutorials/content/sources/range_image_border_extraction,目標代碼處選擇D:/PCL/trunk/doc/tutorials/content/sources/range_image_border_extraction。單擊Configure,彈出對話框選擇VS10,Use default native compliers,完成後展開窗口內紅色分組確認每個安裝過的第三方include和lib都正確後,點擊Generate。
關閉Cmake Gui,打開生成的sln,加入如下動態鏈接庫。還是出現和之前一樣的問題。module not found.
XnCore.dll
XnDDK.dll
XnDeviceFile.dll
XnDeviceSensorV2KM.dll
XnFormats.dll