PCL简介
PCL(Point Cloud Library)是在吸收了前人点云相关研究基础上建立起来的大型跨平台开源C++编程库,它实现了大量点云相关的通用算法和高效数据结构,涉及到点云获取、滤波、分割、配准、检索、特征提取、识别、追踪、曲面重建、可视化等。支持多种操作系统平台,可在Windows、Linux、Android、Mac OS X、部分嵌入式实时系统上运行。如果说OpenCV是2D信息获取与处理的结晶,那么PCL就在3D信息获取与处理上具有同等地位,PCL是BSD授权方式,可以免费进行商业和学术应用。
最近刚接触PCL,发现用到PCL的人还是比较少,可供学习的资料也不多,所以,我想从头开始学习,并记录下学习的过程。如果有兴趣一起学习的同学可以加我微信号zcs9602,我们一起交流学习。
学习资源:
PCL 1.8.0 比较全的安装包及安装步骤:http://unanancyowen.com/en/pcl18/
PCL 相关资料汇总:https://github.com/neilgu00365/Survey-for-SfMMission
PCL 中国点云库:http://www.pclcn.org/
环境:windows+vs2010
如果你没有vs2010我给你分享一个安装包链接:http://pan.baidu.com/s/1pL3I0dH 密码:a53o
一、下载
我用的是PCL 1.6.0 All-In-One Installer,Windows MSVC 2010 (32bit),所以,下面是以这个版本为主。其实,只要下载PCL-1.6.0-AllInOne-msvc2010-win32.exe、OpenNI 1.5.4 (patched)和Sensor 5.1.0 (patched)三个文件就可以了,PCL-1.6.0-AllInOne-msvc2010-win32.exe内部已经包含了全部的依赖库,安装的过程中,OpenNI会安装不上,所以要单独下载,其它的依赖库都可以不用下载。
二、安装
分别安装
1、PCL-1.6.0-AllInOne-msvc2010-win32.exe
2、OpenNI-Win32-1.5.4-Dev.msi
3、Sensor-Win-OpenSource32-5.1.0.msi
注意:你要编译的是Win32和Win64的版本要区别开,PCL和依赖库都统一用同一个版本的,否则运行的时候会报错。
三、配置
1、配置包含路径
将PCL安装路径下的3rdParty目录下的include添加进去,另外OpenNI单独安装的路径也添加进去,还有PCL安装路径下的Includepcl-1.6也添加进去。
2、配置库路径
将PCL安装路径下的3rdParty目录下的lib添加进去,另外OpenNI单独安装的路径也添加进去,还有PCL安装路径下的lib也添加进去。
3、配置输入库文件
添加下列文件名
opengl32.lib pcl_apps_debug.lib pcl_common_debug.lib pcl_features_debug.lib pcl_filters_debug.lib pcl_io_debug.lib pcl_io_ply_debug.lib pcl_kdtree_debug.lib pcl_keypoints_debug.lib pcl_octree_debug.lib pcl_registration_debug.lib pcl_sample_consensus_debug.lib pcl_search_debug.lib pcl_segmentation_debug.lib pcl_surface_debug.lib pcl_tracking_debug.lib pcl_visualization_debug.lib flann_cpp_s-gd.lib boost_chrono-vc100-mt-gd-1_49.lib boost_date_time-vc100-mt-gd-1_47.lib boost_date_time-vc100-mt-gd-1_49.lib boost_filesystem-vc100-mt-gd-1_47.lib boost_filesystem-vc100-mt-gd-1_49.lib boost_graph-vc100-mt-gd-1_49.lib boost_graph_parallel-vc100-mt-gd-1_49.lib boost_iostreams-vc100-mt-gd-1_47.lib boost_iostreams-vc100-mt-gd-1_49.lib boost_locale-vc100-mt-gd-1_49.lib boost_math_c99-vc100-mt-gd-1_49.lib boost_math_c99f-vc100-mt-gd-1_49.lib boost_math_tr1-vc100-mt-gd-1_49.lib boost_math_tr1f-vc100-mt-gd-1_49.lib boost_mpi-vc100-mt-gd-1_49.lib boost_prg_exec_monitor-vc100-mt-gd-1_49.lib boost_program_options-vc100-mt-gd-1_49.lib boost_random-vc100-mt-gd-1_49.lib boost_regex-vc100-mt-gd-1_49.lib boost_serialization-vc100-mt-gd-1_49.lib boost_signals-vc100-mt-gd-1_49.lib boost_system-vc100-mt-gd-1_47.lib boost_system-vc100-mt-gd-1_49.lib boost_thread-vc100-mt-gd-1_47.lib boost_thread-vc100-mt-gd-1_49.lib boost_timer-vc100-mt-gd-1_49.lib boost_unit_test_framework-vc100-mt-gd-1_49.lib boost_wave-vc100-mt-gd-1_49.lib boost_wserialization-vc100-mt-gd-1_49.lib libboost_chrono-vc100-mt-gd-1_49.lib libboost_date_time-vc100-mt-gd-1_47.lib libboost_date_time-vc100-mt-gd-1_49.lib libboost_filesystem-vc100-mt-gd-1_47.lib libboost_filesystem-vc100-mt-gd-1_49.lib libboost_graph_parallel-vc100-mt-gd-1_49.lib libboost_iostreams-vc100-mt-gd-1_47.lib libboost_iostreams-vc100-mt-gd-1_49.lib libboost_locale-vc100-mt-gd-1_49.lib libboost_math_c99-vc100-mt-gd-1_49.lib libboost_math_c99f-vc100-mt-gd-1_49.lib libboost_math_tr1-vc100-mt-gd-1_49.lib libboost_math_tr1f-vc100-mt-gd-1_49.lib libboost_mpi-vc100-mt-gd-1_49.lib libboost_prg_exec_monitor-vc100-mt-gd-1_49.lib libboost_program_options-vc100-mt-gd-1_49.lib libboost_random-vc100-mt-gd-1_49.lib libboost_regex-vc100-mt-gd-1_49.lib libboost_serialization-vc100-mt-gd-1_49.lib libboost_signals-vc100-mt-gd-1_49.lib libboost_system-vc100-mt-gd-1_47.lib libboost_system-vc100-mt-gd-1_49.lib libboost_test_exec_monitor-vc100-mt-gd-1_49.lib libboost_thread-vc100-mt-gd-1_47.lib libboost_thread-vc100-mt-gd-1_49.lib libboost_timer-vc100-mt-gd-1_49.lib libboost_unit_test_framework-vc100-mt-gd-1_49.lib libboost_wave-vc100-mt-gd-1_49.lib libboost_wserialization-vc100-mt-gd-1_49.lib vtkalglib-gd.lib vtkCharts-gd.lib vtkCommon-gd.lib vtkDICOMParser-gd.lib vtkexoIIc-gd.lib vtkexpat-gd.lib vtkFiltering-gd.lib vtkfreetype-gd.lib vtkftgl-gd.lib vtkGenericFiltering-gd.lib vtkGeovis-gd.lib vtkGraphics-gd.lib vtkhdf5-gd.lib vtkHybrid-gd.lib vtkImaging-gd.lib vtkInfovis-gd.lib vtkIO-gd.lib vtkjpeg-gd.lib vtklibxml2-gd.lib vtkmetaio-gd.lib vtkNetCDF-gd.lib vtkNetCDF_cxx-gd.lib vtkpng-gd.lib vtkproj4-gd.lib vtkRendering-gd.lib vtksqlite-gd.lib vtksys-gd.lib vtktiff-gd.lib vtkverdict-gd.lib vtkViews-gd.lib vtkVolumeRendering-gd.lib vtkWidgets-gd.lib vtkzlib-gd.lib
文件有点多,这里可以有个比较快的方法:这里以vtk为例,
打开CMD->进入PCL的安装目录->进入3rdPartyVTKlibvtk-5.8目录->输入命令:dir /b *gd.lib -> list.txt
命令的意思是找出gd.lib结尾的文件并保存到list.txt文档里面。然后当前目录就会生成list.txt
四、Demo
例程:
#include <pcl/visualization/cloud_viewer.h> #include <iostream> #include <pcl/io/io.h> #include <pcl/io/pcd_io.h> int user_data; void viewerOneOff (pcl::visualization::PCLVisualizer& viewer) { viewer.setBackgroundColor (0, 0, 0); pcl::PointXYZ o; o.x = 1.0; o.y = 0; o.z = 0; viewer.addSphere (o, 0.25, "sphere", 0); std::cout << "i only run once" << std::endl; } void viewerPsycho (pcl::visualization::PCLVisualizer& viewer) { static unsigned count = 0; std::stringstream ss; ss << "Once per viewer loop: " << count++; viewer.removeShape ("text", 0); viewer.addText (ss.str(), 200, 300, "text", 0); //FIXME: possible race condition here: user_data++; } int main () { pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>); pcl::io::loadPCDFile ("my_point_cloud.pcd", *cloud); pcl::visualization::CloudViewer viewer("Cloud Viewer"); //blocks until the cloud is actually rendered viewer.showCloud(cloud); //use the following functions to get access to the underlying more advanced/powerful //PCLVisualizer //This will only get called once viewer.runOnVisualizationThreadOnce (viewerOneOff); //This will get called once per visualization iteration viewer.runOnVisualizationThread (viewerPsycho); while (!viewer.wasStopped ()) { //you can also do cool processing here //FIXME: Note that this is running in a separate thread from viewerPsycho //and you should guard against race conditions yourself... user_data++; } return 0; }
以上效果图是用realsense的SR300获取到我桌面的点云。
my_point_cloud.pcd 文件 链接:http://pan.baidu.com/s/1gfD2lF1 密码:cexi
五、总结分享
1、pcd读取有点慢,据说pcd数据以有序点云的方式保存会好一点,但是没我试了没看出来能快多少,这个有待研究。
2、SR300直接获取的深度图像和RGB图像坐标上有偏差,这个考虑下怎么做对齐。
3、如果工程配置上SR300的SDK和opencv,我们就不需要在另一个工程先保存pcd文件再读取,中间就可以省了很多步骤。
4、PCL的学习资料还是很少,目前听说比较好也就只有《点云库PCL学习教程》,我也买了一本,慢慢学吧。
公众号奉上~欢迎来搞!