![6f5a871bdb62ff3f2a4bab71fff97575.png](https://i-blog.csdnimg.cn/blog_migrate/29e65b46143a99c1737d11f93996034e.png)
1.前言
PCL(point clouds library)点云库是吸收了前人点云相关研究基础上建立起来的大型跨平台开源C++编程库(注:目前官方也开发了基于python的pcl,此处只做C++库的配置),其集成了大量三维点云算法和数据结构,主要包括点云获取、滤波、分割、配准、检索、特征提取、识别、追踪、曲面重建、可视化等。话不多说,下面介绍基于C++的PCL点云库配置。
2. PCL1.8.0安装
安装PCL的顺序和visual studio2013(以下简称为vs2013)安装顺序无所谓先后。谁先安装都可以。在安装PCL一键安装包时,勾选上Add PCL to system PATH for all users。
(此步骤是为了将PCL的安装目录添加到主机中,不论是否更换用户,PCL安装目录都会添加到主机中,注意:为方便后续配置,此处PCL安装位置默认为C盘)
PCL安装过程中,会弹出OpenNI(OpenNI开源库,在PCL安装过程中弹出来)的安装程序,因为PCL本身已经有了OpenNI的目录,为了后续配置目录,在安装OpenNI的过程中,需要更改OpenNI的安装路径为当前PCL路径下的3rdParty文件夹下的OpenNI2文件夹中。OpenNI2安装的路径在此:C:Program FilesPCL 1.8.03rdParty。安装成功后显示如下界面。
![c4136d38dd1d4a1d89300d9676a72a89.png](https://i-blog.csdnimg.cn/blog_migrate/66759ff191f934aedb5c7f437de2a7df.png)
![116f9ae6591584b905152d171dfc4908.png](https://i-blog.csdnimg.cn/blog_migrate/462e7f3e4ca65d96c1231014f6d13abd.png)
![1bb898f404a09ae22590cfd8de1ca4ab.png](https://i-blog.csdnimg.cn/blog_migrate/6abfc1ff9eb43ba205eb9bf5c6a64b7c.png)
3. PCL环境变量配置
3.1 环境变量配置
环境变量即是PCL库所包含的一些exe子程序文件,在调用PCL点云库的时候,会用到PCL底层的exe程序,因此必须在本机上添加PCL安装路径中所有bin的目录,bin的目录下包含exe文件。即在exe上一级的目录中。
PCL安装完成后,主机中的环境变量会自动添加一个PCL的环境变量。桌面鼠标右击选择【我的电脑】→【属性】→【高级系统设置】→【环境变量】。选择【系统变量】→【Path】。双击打开。PCL安装好后会自动添加一个PCL的环境变量:C:Program FilesPCL 1.8.0bin。如下图所示。仅仅这一个环境变量不够还还需要进行其他环境配置
![149d4a037deb5c22a97f8dd23b506c9a.png](https://i-blog.csdnimg.cn/blog_migrate/5a0adb1010f893f2ea29f3d8f72a860d.png)
之后需要继续添加PCL的其他环境变量,逐一查找PCL的环境变量,为了方便处理,PCL按默认路径安装的环境变量都是一样的,具体的环境变量如下,这些环境路径下面都是包含exe可执行的文件,调用PCL库时会用到,将包含exe的路径包含进环境变量中,bin目录包含如下:
C:Program FilesPCL 1.8.03rdPartyOpenNI2Redist;
C:Program FilesPCL 1.8.03rdPartyOpenNI2SamplesBin;
C:Program FilesPCL 1.8.03rdPartyOpenNI2Tools;
C:Program FilesPCL 1.8.03rdPartyFLANNbin;
C:Program FilesPCL 1.8.03rdPartyVTKbin;
C:Program FilesPCL 1.8.03rdPartyQhullbin
![294b90f1341a2d6b0b4c877c66d94a02.png](https://i-blog.csdnimg.cn/blog_migrate/a84a34793b48312205728b675952ac12.jpeg)
待所有其他VS环境也配置完成后,需要将主机重启环境变量方能生效。
3.2 新建项目文件配置剩余环境变量
Virtual Studio 2013安装过程较为简单,此处不在赘述。打开Virtual Studio 2013软件,【文件】→【新建】→【项目】,选择建立一个C++项目,具体流程如下。
![84151e35ca095db18d5ac6cb52db3886.png](https://i-blog.csdnimg.cn/blog_migrate/dfc4083ea395814d4ee04fa91c3800b6.png)
本文选择的PCL基于64位操作系统,因此在编译项目时要将其更改为64位。在菜单栏上选择【Debug】→【配置管理器】→【活动解决方案】,将项目更改为64位操作系统。
![e8ae45650479fac8cbba733b974e70ea.png](https://i-blog.csdnimg.cn/blog_migrate/a520bc1d648b6ed8c8dd00a237288c60.png)
![27013dde2a4b5ae8b876be2a3e06bf5e.png](https://i-blog.csdnimg.cn/blog_migrate/45352b571eac734429d01ee8f64202cd.png)
![7793c02628c92ed94731d783ba0ebe88.png](https://i-blog.csdnimg.cn/blog_migrate/4f6445483033cc50316d3028fac4ec32.png)
在新建立的项目上选择右击添加一个【新建项】。此时建立的项目文件为PCL代码,后面环境配置成功后添加代码测试是否配置成功。
![71fe590c8e13c856ed5d1bb3882e6a01.png](https://i-blog.csdnimg.cn/blog_migrate/3c1941996a769a3560d26e040daf172f.png)
![82831b796a39a89db24bb04e5abc8cbd.png](https://i-blog.csdnimg.cn/blog_migrate/229b1fdc375c52bc01c603b2b335888e.png)
![438d3853df51476142fc5a99e40f7f3e.png](https://i-blog.csdnimg.cn/blog_migrate/56b05a2bdf4af15a53aa2afcdcfbf801.png)
新建完C++项目文件后,继续后面的文件配置。
3.3 各种目录配置
在上一步的基础上继续往下操作,在Virtual Studio菜单栏中选择【视图】→【其他窗口】→【属性管理器】。
![5eb670c80aa259c3ffdb2df04a5b7420.png](https://i-blog.csdnimg.cn/blog_migrate/3bf9b7d5c1c14c155d6e14104f90d3f0.png)
在打开的属性管理器中选择Debug64位版本,Debug为调试版本,Release为发行版本,PCL的所有配置都是在Debug版本下进行的。选择【Microsoft.Cpp.x64.user】,此处为用户,一旦在用户变量上配置完成后后续无需再进行各种目录库的配置,只能选择在用户变量上配置,不能选错。选择右击【属性】,打开配置目录。
![8a7fab5b6db7151ff603c0452403cc3c.png](https://i-blog.csdnimg.cn/blog_migrate/92d8cfd2980eb7e48463f8ad577691b8.png)
① 包含目录配置
包含目录即include的文件夹,这个文件夹下面包含了PCL的编译时用到的一堆头文件,即.h文件。在添加包含目录的时候必须将包含h文件的上一级目录都包含进去。
![5159ddc21963433758f08afed9108737.png](https://i-blog.csdnimg.cn/blog_migrate/b0ee9cbac1331d2423cd92e10e861597.png)
在打开的属性页中选择【VC++目录】→【包含目录】。添加PCL安装文件夹中所有包含.h文件,头文件是调用PCL库时必须用到的文件。的上一级目录,本文为了为了配置方便,按之前安装路径,将默认的包含目录放入下面之中:
C:Program FilesPCL 1.8.03rdPartyBoostincludeboost-1_59
C:Program FilesPCL 1.8.03rdPartyEigeneigen3
C:Program FilesPCL 1.8.0includepcl-1.8
C:Program FilesPCL 1.8.03rdPartyOpenNI2Include
C:Program FilesPCL 1.8.03rdPartyFLANNinclude
C:Program FilesPCL 1.8.03rdPartyQhullinclude
C:Program FilesPCL 1.8.03rdPartyVTKincludevtk-7.0
![a2ad8b3aba8c370d63711073793c8737.png](https://i-blog.csdnimg.cn/blog_migrate/cc905fbf970528f817ca9fbf280cab9a.png)
② 库目录配置
同样,返回刚才配置的【库目录】。将PCL所有包含的dll,即动态链接库的上一级目录全部添加进Virtual Studio中,PCL编译时需要调用动态链接库,需要将其全部添加进去,以防报错。
C:Program FilesPCL 1.8.0lib
C:Program FilesPCL 1.8.03rdPartyVTKlib
C:Program FilesPCL 1.8.03rdPartyQhulllib
C:Program FilesPCL 1.8.03rdPartyFLANNlib
C:Program FilesPCL 1.8.03rdPartyBoostlib
C:Program FilesPCL 1.8.03rdPartyOpenNI2Lib
![3f3f1dcce84abcc374f5cba724c8529f.png](https://i-blog.csdnimg.cn/blog_migrate/0509353f5456ba7cc1ff6cbaee9579bc.png)
③ 附加依赖项配置
依赖项是PCL编译时需要使用的静态链接库.lib文件,即静态链接库。而PCL中分为Debuglib和Releaselib,本文选择的是Debuglib,提取degublib,即包含gd.lib的文件名,将文件名复制进去。
选择【属性管理器】→【链接器】→【附加依赖项】
![948a0a0b74fb99fbe399b361e6e2c448.png](https://i-blog.csdnimg.cn/blog_migrate/390bcc8fc19889514f782fa6c19f1ec0.png)
附加依赖项文件如下:
flann-gd.lib
flann.lib
flann_cpp_s-gd.lib
flann_cpp_s.lib
flann_s-gd.lib
flann_s.lib
OpenNI2.lib
qhull-gd.lib
qhull.lib
qhullcpp-gd.lib
qhullcpp.lib
qhullstatic-gd.lib
qhullstatic.lib
qhullstatic_r-gd.lib
qhullstatic_r.lib
qhull_p-gd.lib
qhull_p.lib
qhull_r-gd.lib
qhull_r.lib
vtkalglib-7.0-gd.lib
vtkalglib-7.0.lib
vtkChartsCore-7.0-gd.lib
vtkChartsCore-7.0.lib
vtkCommonColor-7.0-gd.lib
vtkCommonColor-7.0.lib
vtkCommonComputationalGeometry-7.0-gd.lib
vtkCommonComputationalGeometry-7.0.lib
vtkCommonCore-7.0-gd.lib
vtkCommonCore-7.0.lib
vtkCommonDataModel-7.0-gd.lib
vtkCommonDataModel-7.0.lib
vtkCommonExecutionModel-7.0-gd.lib
vtkCommonExecutionModel-7.0.lib
vtkCommonMath-7.0-gd.lib
vtkCommonMath-7.0.lib
vtkCommonMisc-7.0-gd.lib
vtkCommonMisc-7.0.lib
vtkCommonSystem-7.0-gd.lib
vtkCommonSystem-7.0.lib
vtkCommonTransforms-7.0-gd.lib
vtkCommonTransforms-7.0.lib
vtkDICOMParser-7.0-gd.lib
vtkDICOMParser-7.0.lib
vtkDomainsChemistry-7.0-gd.lib
vtkDomainsChemistry-7.0.lib
vtkDomainsChemistryOpenGL2-7.0-gd.lib
vtkDomainsChemistryOpenGL2-7.0.lib
vtkexoIIc-7.0-gd.lib
vtkexoIIc-7.0.lib
vtkexpat-7.0-gd.lib
vtkexpat-7.0.lib
vtkFiltersAMR-7.0-gd.lib
vtkFiltersAMR-7.0.lib
vtkFiltersCore-7.0-gd.lib
vtkFiltersCore-7.0.lib
vtkFiltersExtraction-7.0-gd.lib
vtkFiltersExtraction-7.0.lib
vtkFiltersFlowPaths-7.0-gd.lib
vtkFiltersFlowPaths-7.0.lib
vtkFiltersGeneral-7.0-gd.lib
vtkFiltersGeneral-7.0.lib
vtkFiltersGeneric-7.0-gd.lib
vtkFiltersGeneric-7.0.lib
vtkFiltersGeometry-7.0-gd.lib
vtkFiltersGeometry-7.0.lib
vtkFiltersHybrid-7.0-gd.lib
vtkFiltersHybrid-7.0.lib
vtkFiltersHyperTree-7.0-gd.lib
vtkFiltersHyperTree-7.0.lib
vtkFiltersImaging-7.0-gd.lib
vtkFiltersImaging-7.0.lib
vtkFiltersModeling-7.0-gd.lib
vtkFiltersModeling-7.0.lib
vtkFiltersParallel-7.0-gd.lib
vtkFiltersParallel-7.0.lib
vtkFiltersParallelImaging-7.0-gd.lib
vtkFiltersParallelImaging-7.0.lib
vtkFiltersProgrammable-7.0-gd.lib
vtkFiltersProgrammable-7.0.lib
vtkFiltersSelection-7.0-gd.lib
vtkFiltersSelection-7.0.lib
vtkFiltersSMP-7.0-gd.lib
vtkFiltersSMP-7.0.lib
vtkFiltersSources-7.0-gd.lib
vtkFiltersSources-7.0.lib
vtkFiltersStatistics-7.0-gd.lib
vtkFiltersStatistics-7.0.lib
vtkFiltersTexture-7.0-gd.lib
vtkFiltersTexture-7.0.lib
vtkFiltersVerdict-7.0-gd.lib
vtkFiltersVerdict-7.0.lib
vtkfreetype-7.0-gd.lib
vtkfreetype-7.0.lib
vtkGeovisCore-7.0-gd.lib
vtkGeovisCore-7.0.lib
vtkglew-7.0-gd.lib
vtkglew-7.0.lib
vtkGUISupportQt-7.0-gd.lib
vtkGUISupportQt-7.0.lib
vtkGUISupportQtSQL-7.0-gd.lib
vtkGUISupportQtSQL-7.0.lib
vtkhdf5-7.0-gd.lib
vtkhdf5-7.0.lib
vtkhdf5_hl-7.0-gd.lib
vtkhdf5_hl-7.0.lib
vtkImagingColor-7.0-gd.lib
vtkImagingColor-7.0.lib
vtkImagingCore-7.0-gd.lib
vtkImagingCore-7.0.lib
vtkImagingFourier-7.0-gd.lib
vtkImagingFourier-7.0.lib
vtkImagingGeneral-7.0-gd.lib
vtkImagingGeneral-7.0.lib
vtkImagingHybrid-7.0-gd.lib
vtkImagingHybrid-7.0.lib
vtkImagingMath-7.0-gd.lib
vtkImagingMath-7.0.lib
vtkImagingMorphological-7.0-gd.lib
vtkImagingMorphological-7.0.lib
vtkImagingSources-7.0-gd.lib
vtkImagingSources-7.0.lib
vtkImagingStatistics-7.0-gd.lib
vtkImagingStatistics-7.0.lib
vtkImagingStencil-7.0-gd.lib
vtkImagingStencil-7.0.lib
vtkInfovisCore-7.0-gd.lib
vtkInfovisCore-7.0.lib
vtkInfovisLayout-7.0-gd.lib
vtkInfovisLayout-7.0.lib
vtkInteractionImage-7.0-gd.lib
vtkInteractionImage-7.0.lib
vtkInteractionStyle-7.0-gd.lib
vtkInteractionStyle-7.0.lib
vtkInteractionWidgets-7.0-gd.lib
vtkInteractionWidgets-7.0.lib
vtkIOAMR-7.0-gd.lib
vtkIOAMR-7.0.lib
vtkIOCore-7.0-gd.lib
vtkIOCore-7.0.lib
vtkIOEnSight-7.0-gd.lib
vtkIOEnSight-7.0.lib
vtkIOExodus-7.0-gd.lib
vtkIOExodus-7.0.lib
vtkIOExport-7.0-gd.lib
vtkIOExport-7.0.lib
vtkIOGeometry-7.0-gd.lib
vtkIOGeometry-7.0.lib
vtkIOImage-7.0-gd.lib
vtkIOImage-7.0.lib
vtkIOImport-7.0-gd.lib
vtkIOImport-7.0.lib
vtkIOInfovis-7.0-gd.lib
vtkIOInfovis-7.0.lib
vtkIOLegacy-7.0-gd.lib
vtkIOLegacy-7.0.lib
vtkIOLSDyna-7.0-gd.lib
vtkIOLSDyna-7.0.lib
vtkIOMINC-7.0-gd.lib
vtkIOMINC-7.0.lib
vtkIOMovie-7.0-gd.lib
vtkIOMovie-7.0.lib
vtkIONetCDF-7.0-gd.lib
vtkIONetCDF-7.0.lib
vtkIOParallel-7.0-gd.lib
vtkIOParallel-7.0.lib
vtkIOParallelXML-7.0-gd.lib
vtkIOParallelXML-7.0.lib
vtkIOPLY-7.0-gd.lib
vtkIOPLY-7.0.lib
vtkIOSQL-7.0-gd.lib
vtkIOSQL-7.0.lib
vtkIOVideo-7.0-gd.lib
vtkIOVideo-7.0.lib
vtkIOXML-7.0-gd.lib
vtkIOXML-7.0.lib
vtkIOXMLParser-7.0-gd.lib
vtkIOXMLParser-7.0.lib
vtkjpeg-7.0-gd.lib
vtkjpeg-7.0.lib
vtkjsoncpp-7.0-gd.lib
vtkjsoncpp-7.0.lib
vtklibxml2-7.0-gd.lib
vtklibxml2-7.0.lib
vtkmetaio-7.0-gd.lib
vtkmetaio-7.0.lib
vtkNetCDF-7.0-gd.lib
vtkNetCDF-7.0.lib
vtkNetCDF_cxx-7.0-gd.lib
vtkNetCDF_cxx-7.0.lib
vtkoggtheora-7.0-gd.lib
vtkoggtheora-7.0.lib
vtkParallelCore-7.0-gd.lib
vtkParallelCore-7.0.lib
vtkpng-7.0-gd.lib
vtkpng-7.0.lib
vtkproj4-7.0-gd.lib
vtkproj4-7.0.lib
vtkRenderingAnnotation-7.0-gd.lib
vtkRenderingAnnotation-7.0.lib
vtkRenderingContext2D-7.0-gd.lib
vtkRenderingContext2D-7.0.lib
vtkRenderingContextOpenGL2-7.0-gd.lib
vtkRenderingContextOpenGL2-7.0.lib
vtkRenderingCore-7.0-gd.lib
vtkRenderingCore-7.0.lib
vtkRenderingFreeType-7.0-gd.lib
vtkRenderingFreeType-7.0.lib
vtkRenderingImage-7.0-gd.lib
vtkRenderingImage-7.0.lib
vtkRenderingLabel-7.0-gd.lib
vtkRenderingLabel-7.0.lib
vtkRenderingLOD-7.0-gd.lib
vtkRenderingLOD-7.0.lib
vtkRenderingOpenGL2-7.0-gd.lib
vtkRenderingOpenGL2-7.0.lib
vtkRenderingQt-7.0-gd.lib
vtkRenderingQt-7.0.lib
vtkRenderingVolume-7.0-gd.lib
vtkRenderingVolume-7.0.lib
vtkRenderingVolumeOpenGL2-7.0-gd.lib
vtkRenderingVolumeOpenGL2-7.0.lib
vtksqlite-7.0-gd.lib
vtksqlite-7.0.lib
vtksys-7.0-gd.lib
vtksys-7.0.lib
vtktiff-7.0-gd.lib
vtktiff-7.0.lib
vtkverdict-7.0-gd.lib
vtkverdict-7.0.lib
vtkViewsContext2D-7.0-gd.lib
vtkViewsContext2D-7.0.lib
vtkViewsCore-7.0-gd.lib
vtkViewsCore-7.0.lib
vtkViewsInfovis-7.0-gd.lib
vtkViewsInfovis-7.0.lib
vtkViewsQt-7.0-gd.lib
vtkViewsQt-7.0.lib
vtkzlib-7.0-gd.lib
vtkzlib-7.0.lib
pcl_apps_debug.lib
pcl_apps_release.lib
pcl_common_debug.lib
pcl_common_release.lib
pcl_features_debug.lib
pcl_features_release.lib
pcl_filters_debug.lib
pcl_filters_release.lib
pcl_io_debug.lib
pcl_io_ply_debug.lib
pcl_io_ply_release.lib
pcl_io_release.lib
pcl_kdtree_debug.lib
pcl_kdtree_release.lib
pcl_keypoints_debug.lib
pcl_keypoints_release.lib
pcl_ml_debug.lib
pcl_ml_release.lib
pcl_octree_debug.lib
pcl_octree_release.lib
pcl_outofcore_debug.lib
pcl_outofcore_release.lib
pcl_people_debug.lib
pcl_people_release.lib
pcl_recognition_debug.lib
pcl_recognition_release.lib
pcl_registration_debug.lib
pcl_registration_release.lib
pcl_sample_consensus_debug.lib
pcl_sample_consensus_release.lib
pcl_search_debug.lib
pcl_search_release.lib
pcl_segmentation_debug.lib
pcl_segmentation_release.lib
pcl_simulation_debug.lib
pcl_simulation_release.lib
pcl_stereo_debug.lib
pcl_stereo_release.lib
pcl_surface_debug.lib
pcl_surface_release.lib
pcl_tracking_debug.lib
pcl_tracking_release.lib
pcl_visualization_debug.lib
![6c1913fc4cf0577a2909d42a7d85c733.png](https://i-blog.csdnimg.cn/blog_migrate/7ad2f504b820d9c2536f5e8e3e87cac5.png)
④ 警告声明配置
属性菜单栏中选择【属性】→ 【C/C++】 →【预处理器】→【预处理器】,添加警告声明:
_SCL_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS
![13ef6f5a215c35200563c7ec5cdf68e0.png](https://i-blog.csdnimg.cn/blog_migrate/392c4ba7068b6d248ddccd1fc30ac8d3.png)
![6fef4c8f8f314199a6515e6c288291c8.png](https://i-blog.csdnimg.cn/blog_migrate/188c10e627410f914019175bf7d5f23d.png)
完成后点击确定。
⑤ 测试是否配置成功
重启电脑让环境变量生效,拷贝PCL的io代码进项目的cpp文件中(注:此代码作用是随机生成一个点云文件,向点云文件中存入随机的xyz值,运行程序能在exe同级目录下生成test_pcd.pcd文件,说明pcl库安装完成),测试能否调用PCL库。io代码如下:
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
int main(int argc,char**argv)
{
pcl::PointCloud<pcl::PointXYZ> cloud; // 创建点云
cloud.width=5; // 设置点云width
cloud.height=1; // 设置点云height
cloud.is_dense=false; // 设置是否是密集点云
cloud.points.resize(cloud.width * cloud.height);
for(size_t i=0; i<cloud.points.size(); ++i)
{
cloud.points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
cloud.points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
cloud.points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
// rand()是随机产生一个从0到无限大的任意整数
// RAND_MAX是宏定义的一个字符常量
// 1.0f,f代表数字类型是浮点型
}
pcl::io::savePCDFileASCII("test_pcd.pcd", cloud); // 按ASCII码写入test_pcd.pcd
std::cout << "Saved " << cloud.points.size() << " data points to test_pcd.pcd." << std::endl;
for(size_t i=0; i<cloud.points.size(); ++i)
{
std::cout << " " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;
}
return(0);
}
拷贝完代码先在解决方案资源管理器中选择项目→【重新生成】,此处是为生成exe文件。
![99d04f8a740785415c51f80792686169.png](https://i-blog.csdnimg.cn/blog_migrate/a3266827875f9e627dc15518e65be8c3.jpeg)
![0e437a5281bb9a5a4185e9ce4ce656c3.png](https://i-blog.csdnimg.cn/blog_migrate/1d41424c1ae7bff7be3f25ee66dc4b6b.jpeg)
如果在下发输出菜单栏中显示成功,说明pcl库安装完成。后续可以直接调用即可。