PCL(Point Cloud Library)是一个开源的点云库,是点云算法集成度最高的库。本文将以Windows 10和Visual Studio 2022开发环境为例,讲解如何配置点云库。
教程中使用的是 Visual Studio 2022 版本,具体的安装方式可从其他网站中搜索到,在此不做赘述。
首先去 https://github.com/PointCloudLibrary/pcl/releases 下载点云库的安装包,我们需要的是AllInOne和pdb两个包。我下载的是1.12.0版本,如下图所示。
在这里需要根据自己机器的情况下载相应的版本(操作系统的位数,以及Visual Studio的版本)。我这里选择PCL-1.12.0-AllInOne-msvc2019-win64.exe
和pcl-1.12.0-pdb-msvc2019-win64.zip
两个文件。
下载结束之后,运行我们下载得到的PCL-1.12.0-AllInOne-msvc2019-win64.exe
文件进行安装。下面几幅图显示出了几个必要的步骤,未做说明的步骤直接下一步或者根据自己的喜好配置即可。
接下来点击安装
便可以开始漫长的安装过程。
一段时间之后,会弹出来一个OpenNI2
的安装窗口,此时直接一路下一步就好,但是一定要记住自己设置的安装路径。由于点云在安装的过程中会把所有的第三方库全部安装在点云安装目录下的3rdparty
文件夹里。因此,为了保持文件夹的整洁,我这里也把OpenNI2
放在3rdparty
文件夹里,即E:\PCL 1.12.0\3rdParty\OpenNI2
。
OpenNI2安装结束之后就完成了点云库的完整安装,安装目录下的样子和3rdparty
文件夹下的样子如下图:
可以看到,我把所有的第三方库全部安装到了3rdparty
文件夹中。
解压pcl-1.12.0-pdb-msvc2019-win64.zip
,将得到的pdb文件全部复制到:E:\PCL 1.12.0\bin
中。
环境变量配置
点云库安装完成之后,还有一个比较重要的步骤,就是配置Windows的环境变量。
右键点击此电脑(我的电脑,计算机,这台电脑等名字),选择属性,接着点击左侧的高级系统设置,然后选择高级选项卡,点击下面的环境变量…按钮,此时便打开了环境变量的配置窗口。
此时,我们可以看到PCL的根目录以及OpenNI2的目录已经添加到了系统变量中。
注意,由于我们在安装完毕后把OpenNI2
放在3rdparty
文件夹里,因此我们需要将OPENNI2_REDIST64的系统路径修改为E:\PCL 1.12.0\3rdParty\OpenNI2
,我这里已经修改过来了。改之前的路径是在C盘
。
然后,我们双击系统变量中的Path,再将以下的目录添加到Path中(注意最后一个OpenNI2的路径,要和自己刚刚安装的路径一样才行):
%PCL_ROOT%\bin
%PCL_ROOT%\3rdParty\VTK\bin
%PCL_ROOT%\3rdParty\FLANN\bin
%OPENNI2_REDIST64%
%PCL_ROOT%\3rdParty\Qhull\bin
%PCL_ROOT%\3rdParty\OpenNI2\Tools
以上步骤搞定之后,重启电脑来应用环境变量。这一步我没有做,也可以生效。
Visual Studio提供了两种编译模式:Debug和Release。Debug模式下,生成的应用程序中会插入许多的调试指令,因此调试起来及其方便,但是大幅度降低了程序的运行速度;Release模式便会提高程序的速度,但是调试相对较困难一些。本教程将对两种模式分别进行配置,适应不同的需求。
首先打开Visual Studio,然后新建一个C++工程。具体创建过程在此不做赘述。
接下来,配置工程的属性管理器。
我们先来配置Debug模式。点击该窗口左侧的VC++ 目录
,然后点击右侧的包含目录
右侧的下拉菜单,选择编辑…,将以下目录填入窗口中:
1_76
9.0
1.12
注意:这里的E:\PCL 1.12.0
是刚刚安装点云库的路径,根据刚刚安装点云的路径进行修改。同时还要注意高亮字体的版本问题。配置好之后点击确定即可。
然后点击右侧的库目录
右侧的下拉菜单,选择编辑…,将以下目录填入窗口中:
同样需要注意路径问题,配置好之后点击确定即可。
然后点击属性页中的C/C++
下的预处理器
,点击右侧的预处理器定义右侧的下拉菜单,选择编辑…,添加如下两条定义:
_SCL_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS
然后再点击预编译头
,将右侧的预编译头设置为不使用预编译头
。这个设置可以依据自己的习惯决定,可以省略。
接着点击属性页中的链接器
下的输入
,点击右侧的附加依赖项
右侧的下拉菜单,选择编辑…,将pcl和3rdParty相关lib文件
填写到窗口中:
pcl_common.lib
pcl_commond.lib
pcl_features.lib
pcl_featuresd.lib
pcl_filters.lib
pcl_filtersd.lib
pcl_io.lib
pcl_iod.lib
pcl_io_ply.lib
pcl_io_plyd.lib
pcl_kdtree.lib
pcl_kdtreed.lib
pcl_keypoints.lib
pcl_keypointsd.lib
pcl_ml.lib
pcl_mld.lib
pcl_octree.lib
pcl_octreed.lib
pcl_outofcore.lib
pcl_outofcored.lib
pcl_people.lib
pcl_peopled.lib
pcl_recognition.lib
pcl_recognitiond.lib
pcl_registration.lib
pcl_registrationd.lib
pcl_sample_consensus.lib
pcl_sample_consensusd.lib
pcl_search.lib
pcl_searchd.lib
pcl_segmentation.lib
pcl_segmentationd.lib
pcl_stereo.lib
pcl_stereod.lib
pcl_surface.lib
pcl_surfaced.lib
pcl_tracking.lib
pcl_trackingd.lib
pcl_visualization.lib
pcl_visualizationd.lib
libboost_atomic-vc142-mt-gd-x64-1_76.lib
libboost_atomic-vc142-mt-x64-1_76.lib
libboost_bzip2-vc142-mt-gd-x64-1_76.lib
libboost_bzip2-vc142-mt-x64-1_76.lib
libboost_chrono-vc142-mt-gd-x64-1_76.lib
libboost_chrono-vc142-mt-x64-1_76.lib
libboost_container-vc142-mt-gd-x64-1_76.lib
libboost_container-vc142-mt-x64-1_76.lib
libboost_context-vc142-mt-gd-x64-1_76.lib
libboost_context-vc142-mt-x64-1_76.lib
libboost_contract-vc142-mt-gd-x64-1_76.lib
libboost_contract-vc142-mt-x64-1_76.lib
libboost_coroutine-vc142-mt-gd-x64-1_76.lib
libboost_coroutine-vc142-mt-x64-1_76.lib
libboost_date_time-vc142-mt-gd-x64-1_76.lib
libboost_date_time-vc142-mt-x64-1_76.lib
libboost_exception-vc142-mt-gd-x64-1_76.lib
libboost_exception-vc142-mt-x64-1_76.lib
libboost_fiber-vc142-mt-gd-x64-1_76.lib
libboost_fiber-vc142-mt-x64-1_76.lib
libboost_filesystem-vc142-mt-gd-x64-1_76.lib
libboost_filesystem-vc142-mt-x64-1_76.lib
libboost_graph-vc142-mt-gd-x64-1_76.lib
libboost_graph-vc142-mt-x64-1_76.lib
libboost_graph_parallel-vc142-mt-gd-x64-1_76.lib
libboost_graph_parallel-vc142-mt-x64-1_76.lib
libboost_iostreams-vc142-mt-gd-x64-1_76.lib
libboost_iostreams-vc142-mt-x64-1_76.lib
libboost_json-vc142-mt-gd-x64-1_76.lib
libboost_json-vc142-mt-x64-1_76.lib
libboost_locale-vc142-mt-gd-x64-1_76.lib
libboost_locale-vc142-mt-x64-1_76.lib
libboost_log-vc142-mt-gd-x64-1_76.lib
libboost_log-vc142-mt-x64-1_76.lib
libboost_log_setup-vc142-mt-gd-x64-1_76.lib
libboost_log_setup-vc142-mt-x64-1_76.lib
libboost_math_c99-vc142-mt-gd-x64-1_76.lib
libboost_math_c99-vc142-mt-x64-1_76.lib
libboost_math_c99f-vc142-mt-gd-x64-1_76.lib
libboost_math_c99f-vc142-mt-x64-1_76.lib
libboost_math_c99l-vc142-mt-gd-x64-1_76.lib
libboost_math_c99l-vc142-mt-x64-1_76.lib
libboost_math_tr1-vc142-mt-gd-x64-1_76.lib
libboost_math_tr1-vc142-mt-x64-1_76.lib
libboost_math_tr1f-vc142-mt-gd-x64-1_76.lib
libboost_math_tr1f-vc142-mt-x64-1_76.lib
libboost_math_tr1l-vc142-mt-gd-x64-1_76.lib
libboost_math_tr1l-vc142-mt-x64-1_76.lib
libboost_mpi-vc142-mt-gd-x64-1_76.lib
libboost_mpi-vc142-mt-x64-1_76.lib
libboost_nowide-vc142-mt-gd-x64-1_76.lib
libboost_nowide-vc142-mt-x64-1_76.lib
libboost_numpy38-vc142-mt-gd-x64-1_76.lib
libboost_numpy38-vc142-mt-x64-1_76.lib
libboost_prg_exec_monitor-vc142-mt-gd-x64-1_76.lib
libboost_prg_exec_monitor-vc142-mt-x64-1_76.lib
libboost_program_options-vc142-mt-gd-x64-1_76.lib
libboost_program_options-vc142-mt-x64-1_76.lib
libboost_python38-vc142-mt-gd-x64-1_76.lib
libboost_python38-vc142-mt-x64-1_76.lib
libboost_random-vc142-mt-gd-x64-1_76.lib
libboost_random-vc142-mt-x64-1_76.lib
libboost_regex-vc142-mt-gd-x64-1_76.lib
libboost_regex-vc142-mt-x64-1_76.lib
libboost_serialization-vc142-mt-gd-x64-1_76.lib
libboost_serialization-vc142-mt-x64-1_76.lib
libboost_stacktrace_noop-vc142-mt-gd-x64-1_76.lib
libboost_stacktrace_noop-vc142-mt-x64-1_76.lib
libboost_stacktrace_windbg-vc142-mt-gd-x64-1_76.lib
libboost_stacktrace_windbg-vc142-mt-x64-1_76.lib
libboost_stacktrace_windbg_cached-vc142-mt-gd-x64-1_76.lib
libboost_stacktrace_windbg_cached-vc142-mt-x64-1_76.lib
libboost_system-vc142-mt-gd-x64-1_76.lib
libboost_system-vc142-mt-x64-1_76.lib
libboost_test_exec_monitor-vc142-mt-gd-x64-1_76.lib
libboost_test_exec_monitor-vc142-mt-x64-1_76.lib
libboost_thread-vc142-mt-gd-x64-1_76.lib
libboost_thread-vc142-mt-x64-1_76.lib
libboost_timer-vc142-mt-gd-x64-1_76.lib
libboost_timer-vc142-mt-x64-1_76.lib
libboost_type_erasure-vc142-mt-gd-x64-1_76.lib
libboost_type_erasure-vc142-mt-x64-1_76.lib
libboost_unit_test_framework-vc142-mt-gd-x64-1_76.lib
libboost_unit_test_framework-vc142-mt-x64-1_76.lib
libboost_wave-vc142-mt-gd-x64-1_76.lib
libboost_wave-vc142-mt-x64-1_76.lib
libboost_wserialization-vc142-mt-gd-x64-1_76.lib
libboost_wserialization-vc142-mt-x64-1_76.lib
libboost_zlib-vc142-mt-gd-x64-1_76.lib
libboost_zlib-vc142-mt-x64-1_76.lib
flann-gd.lib
flann.lib
flann_cpp-gd.lib
flann_cpp.lib
flann_cpp_s-gd.lib
flann_cpp_s.lib
flann_s-gd.lib
flann_s.lib
OpenNI2.lib
qhullcpp.lib
qhullcpp_d.lib
qhullstatic.lib
qhullstatic_d.lib
qhullstatic_r.lib
qhullstatic_rd.lib
qhull_r.lib
qhull_rd.lib
vtkChartsCore-9.0.lib
vtkChartsCore-9.0d.lib
vtkCommonColor-9.0.lib
vtkCommonColor-9.0d.lib
vtkCommonComputationalGeometry-9.0.lib
vtkCommonComputationalGeometry-9.0d.lib
vtkCommonCore-9.0.lib
vtkCommonCore-9.0d.lib
vtkCommonDataModel-9.0.lib
vtkCommonDataModel-9.0d.lib
vtkCommonExecutionModel-9.0.lib
vtkCommonExecutionModel-9.0d.lib
vtkCommonMath-9.0.lib
vtkCommonMath-9.0d.lib
vtkCommonMisc-9.0.lib
vtkCommonMisc-9.0d.lib
vtkCommonSystem-9.0.lib
vtkCommonSystem-9.0d.lib
vtkCommonTransforms-9.0.lib
vtkCommonTransforms-9.0d.lib
vtkDICOMParser-9.0.lib
vtkDICOMParser-9.0d.lib
vtkDomainsChemistry-9.0.lib
vtkDomainsChemistry-9.0d.lib
vtkDomainsChemistryOpenGL2-9.0.lib
vtkDomainsChemistryOpenGL2-9.0d.lib
vtkdoubleconversion-9.0.lib
vtkdoubleconversion-9.0d.lib
vtkexodusII-9.0.lib
vtkexodusII-9.0d.lib
vtkexpat-9.0.lib
vtkexpat-9.0d.lib
vtkFiltersAMR-9.0.lib
vtkFiltersAMR-9.0d.lib
vtkFiltersCore-9.0.lib
vtkFiltersCore-9.0d.lib
vtkFiltersExtraction-9.0.lib
vtkFiltersExtraction-9.0d.lib
vtkFiltersFlowPaths-9.0.lib
vtkFiltersFlowPaths-9.0d.lib
vtkFiltersGeneral-9.0.lib
vtkFiltersGeneral-9.0d.lib
vtkFiltersGeneric-9.0.lib
vtkFiltersGeneric-9.0d.lib
vtkFiltersGeometry-9.0.lib
vtkFiltersGeometry-9.0d.lib
vtkFiltersHybrid-9.0.lib
vtkFiltersHybrid-9.0d.lib
vtkFiltersHyperTree-9.0.lib
vtkFiltersHyperTree-9.0d.lib
vtkFiltersImaging-9.0.lib
vtkFiltersImaging-9.0d.lib
vtkFiltersModeling-9.0.lib
vtkFiltersModeling-9.0d.lib
vtkFiltersParallel-9.0.lib
vtkFiltersParallel-9.0d.lib
vtkFiltersParallelImaging-9.0.lib
vtkFiltersParallelImaging-9.0d.lib
vtkFiltersPoints-9.0.lib
vtkFiltersPoints-9.0d.lib
vtkFiltersProgrammable-9.0.lib
vtkFiltersProgrammable-9.0d.lib
vtkFiltersSelection-9.0.lib
vtkFiltersSelection-9.0d.lib
vtkFiltersSMP-9.0.lib
vtkFiltersSMP-9.0d.lib
vtkFiltersSources-9.0.lib
vtkFiltersSources-9.0d.lib
vtkFiltersStatistics-9.0.lib
vtkFiltersStatistics-9.0d.lib
vtkFiltersTexture-9.0.lib
vtkFiltersTexture-9.0d.lib
vtkFiltersTopology-9.0.lib
vtkFiltersTopology-9.0d.lib
vtkFiltersVerdict-9.0.lib
vtkFiltersVerdict-9.0d.lib
vtkfreetype-9.0.lib
vtkfreetype-9.0d.lib
vtkGeovisCore-9.0.lib
vtkGeovisCore-9.0d.lib
vtkgl2ps-9.0.lib
vtkgl2ps-9.0d.lib
vtkglew-9.0.lib
vtkglew-9.0d.lib
vtkhdf5-9.0.lib
vtkhdf5-9.0d.lib
vtkhdf5_hl-9.0.lib
vtkhdf5_hl-9.0d.lib
vtkImagingColor-9.0.lib
vtkImagingColor-9.0d.lib
vtkImagingCore-9.0.lib
vtkImagingCore-9.0d.lib
vtkImagingFourier-9.0.lib
vtkImagingFourier-9.0d.lib
vtkImagingGeneral-9.0.lib
vtkImagingGeneral-9.0d.lib
vtkImagingHybrid-9.0.lib
vtkImagingHybrid-9.0d.lib
vtkImagingMath-9.0.lib
vtkImagingMath-9.0d.lib
vtkImagingMorphological-9.0.lib
vtkImagingMorphological-9.0d.lib
vtkImagingSources-9.0.lib
vtkImagingSources-9.0d.lib
vtkImagingStatistics-9.0.lib
vtkImagingStatistics-9.0d.lib
vtkImagingStencil-9.0.lib
vtkImagingStencil-9.0d.lib
vtkInfovisCore-9.0.lib
vtkInfovisCore-9.0d.lib
vtkInfovisLayout-9.0.lib
vtkInfovisLayout-9.0d.lib
vtkInteractionImage-9.0.lib
vtkInteractionImage-9.0d.lib
vtkInteractionStyle-9.0.lib
vtkInteractionStyle-9.0d.lib
vtkInteractionWidgets-9.0.lib
vtkInteractionWidgets-9.0d.lib
vtkIOAMR-9.0.lib
vtkIOAMR-9.0d.lib
vtkIOAsynchronous-9.0.lib
vtkIOAsynchronous-9.0d.lib
vtkIOCityGML-9.0.lib
vtkIOCityGML-9.0d.lib
vtkIOCore-9.0.lib
vtkIOCore-9.0d.lib
vtkIOEnSight-9.0.lib
vtkIOEnSight-9.0d.lib
vtkIOExodus-9.0.lib
vtkIOExodus-9.0d.lib
vtkIOExport-9.0.lib
vtkIOExport-9.0d.lib
vtkIOExportGL2PS-9.0.lib
vtkIOExportGL2PS-9.0d.lib
vtkIOExportPDF-9.0.lib
vtkIOExportPDF-9.0d.lib
vtkIOGeometry-9.0.lib
vtkIOGeometry-9.0d.lib
vtkIOImage-9.0.lib
vtkIOImage-9.0d.lib
vtkIOImport-9.0.lib
vtkIOImport-9.0d.lib
vtkIOInfovis-9.0.lib
vtkIOInfovis-9.0d.lib
vtkIOLegacy-9.0.lib
vtkIOLegacy-9.0d.lib
vtkIOLSDyna-9.0.lib
vtkIOLSDyna-9.0d.lib
vtkIOMINC-9.0.lib
vtkIOMINC-9.0d.lib
vtkIOMotionFX-9.0.lib
vtkIOMotionFX-9.0d.lib
vtkIOMovie-9.0.lib
vtkIOMovie-9.0d.lib
vtkIONetCDF-9.0.lib
vtkIONetCDF-9.0d.lib
vtkIOOggTheora-9.0.lib
vtkIOOggTheora-9.0d.lib
vtkIOParallel-9.0.lib
vtkIOParallel-9.0d.lib
vtkIOParallelXML-9.0.lib
vtkIOParallelXML-9.0d.lib
vtkIOPLY-9.0.lib
vtkIOPLY-9.0d.lib
vtkIOSegY-9.0.lib
vtkIOSegY-9.0d.lib
vtkIOSQL-9.0.lib
vtkIOSQL-9.0d.lib
vtkIOTecplotTable-9.0.lib
vtkIOTecplotTable-9.0d.lib
vtkIOVeraOut-9.0.lib
vtkIOVeraOut-9.0d.lib
vtkIOVideo-9.0.lib
vtkIOVideo-9.0d.lib
vtkIOXML-9.0.lib
vtkIOXML-9.0d.lib
vtkIOXMLParser-9.0.lib
vtkIOXMLParser-9.0d.lib
vtkjpeg-9.0.lib
vtkjpeg-9.0d.lib
vtkjsoncpp-9.0.lib
vtkjsoncpp-9.0d.lib
vtklibharu-9.0.lib
vtklibharu-9.0d.lib
vtklibproj-9.0.lib
vtklibproj-9.0d.lib
vtklibxml2-9.0.lib
vtklibxml2-9.0d.lib
vtkloguru-9.0.lib
vtkloguru-9.0d.lib
vtklz4-9.0.lib
vtklz4-9.0d.lib
vtklzma-9.0.lib
vtklzma-9.0d.lib
vtkmetaio-9.0.lib
vtkmetaio-9.0d.lib
vtknetcdf-9.0.lib
vtknetcdf-9.0d.lib
vtkogg-9.0.lib
vtkogg-9.0d.lib
vtkParallelCore-9.0.lib
vtkParallelCore-9.0d.lib
vtkParallelDIY-9.0.lib
vtkParallelDIY-9.0d.lib
vtkpng-9.0.lib
vtkpng-9.0d.lib
vtkpugixml-9.0.lib
vtkpugixml-9.0d.lib
vtkRenderingAnnotation-9.0.lib
vtkRenderingAnnotation-9.0d.lib
vtkRenderingContext2D-9.0.lib
vtkRenderingContext2D-9.0d.lib
vtkRenderingContextOpenGL2-9.0.lib
vtkRenderingContextOpenGL2-9.0d.lib
vtkRenderingCore-9.0.lib
vtkRenderingCore-9.0d.lib
vtkRenderingFreeType-9.0.lib
vtkRenderingFreeType-9.0d.lib
vtkRenderingGL2PSOpenGL2-9.0.lib
vtkRenderingGL2PSOpenGL2-9.0d.lib
vtkRenderingImage-9.0.lib
vtkRenderingImage-9.0d.lib
vtkRenderingLabel-9.0.lib
vtkRenderingLabel-9.0d.lib
vtkRenderingLOD-9.0.lib
vtkRenderingLOD-9.0d.lib
vtkRenderingOpenGL2-9.0.lib
vtkRenderingOpenGL2-9.0d.lib
vtkRenderingSceneGraph-9.0.lib
vtkRenderingSceneGraph-9.0d.lib
vtkRenderingUI-9.0.lib
vtkRenderingUI-9.0d.lib
vtkRenderingVolume-9.0.lib
vtkRenderingVolume-9.0d.lib
vtkRenderingVolumeOpenGL2-9.0.lib
vtkRenderingVolumeOpenGL2-9.0d.lib
vtkRenderingVtkJS-9.0.lib
vtkRenderingVtkJS-9.0d.lib
vtksqlite-9.0.lib
vtksqlite-9.0d.lib
vtksys-9.0.lib
vtksys-9.0d.lib
vtkTestingRendering-9.0.lib
vtkTestingRendering-9.0d.lib
vtktheora-9.0.lib
vtktheora-9.0d.lib
vtktiff-9.0.lib
vtktiff-9.0d.lib
vtkverdict-9.0.lib
vtkverdict-9.0d.lib
vtkViewsContext2D-9.0.lib
vtkViewsContext2D-9.0d.lib
vtkViewsCore-9.0.lib
vtkViewsCore-9.0d.lib
vtkViewsInfovis-9.0.lib
vtkViewsInfovis-9.0d.lib
vtkWrappingTools-9.0.lib
vtkWrappingTools-9.0d.lib
vtkzlib-9.0.lib
vtkzlib-9.0d.lib
以上内容可以自动生成,首先在这些lib文件所在目录下新建一个文件:get.txt
,并写入如下内容:
DIR *.lib /B >liblist.txt
然后修改改文件名为:get.bat
,这是一个可执行文件。
接着我们在所在目录下再新建一个文件:liblist.txt
,然后双击get.bat
,就可以将所有的.lib文件写入到liblist.txt
中。
这时,点击确定,我们在Debug模式下的点云开发环境就配置完成了。去网上找个实例代码粘贴,如果成功编译运行就代表配置成功了。
接下来说一下Release模式的配置。Release模式的配置和Debug模式一模一样。
这样,我们的Debug模式和Release模式就全部配置完成了,根据自己的需要选择即可。为了减少其他工程配置的负担,可以将这些配置保存为属性表,方法可以自行搜索,在此就不做赘述了。