Win10 + Visual Studio 搭建 PCL 开发环境

该教程以 PCL 1.12.1 在 win10 环境下安装,最后使用 VS2019 创建 PCL 工程为例

重要的步骤会进行截图说明,其他的默认下一步就行

1 下载和安装 PCL 库

注意下载的文件名,里面有的 msvc2019 代表的就是要安装 VS2019,即文件名与 VS 版本号对应

  1. 首先去 Github 下载 PCL 安装文件,下载这两个即可(一个是 exe 可执行文件,另一个是 pcl 数据库文件)

image-20220804100437276

  1. 右键管理员运行下载的可执行文件 PCL-1.12.1-AllInOne-msvc2019-win64.exe ,点击下一步、我同意

  2. 出现如下界面,选择第一项,不添加环境变量(如果这里选择添加环境变量,很大概率会出错,后期我们手动添加),点击下一步

image-20220804102419429

  1. 选择自定义安装路径,不断点击下一步,等待安装完成(这里有概率出现 OPENNI2 的安装弹窗,若出现了,参考步骤 9 ;若未出现,根据教程往下走)

image-20220804102546304

  1. 安装完成后,点击确定关闭页面

image-20220804102857476

  1. 打开安装目录中的 /3rdParty/OPENNI2/ 文件夹,看看里面是否只有一个 msi 文件(如果除过该文件,还有许多文件夹,不用管,继续往下)

image-20220804104347161

  1. 双击运行这个文件,点击下一步,出现如下页面,点击 remove 进行移除,等待程序执行结束(OPENNI2 默认安装在了 C 盘,为了管理方便,这里我们安装到自定义路径下)

image-20220804104519986

  1. 移除完成后,点击 Finish 关闭界面,然后再次双击运行该程序

  2. 点击 change 选择自定义安装路径,这里建议选择 PCL 安装路径下的 /3rdParty/OPENNI2/ 文件夹下,然后点击 insatll 安装

image-20220804105455606

  1. 安装完成后,点击 finish 关闭界面,此时步骤 6 中提到的文件夹下,应该是如下内容

image-20220804105709329

  1. 解压缩桌面的 pcl-1.12.1-pdb-msvc2019-win64.zip 压缩包,将解压的文件全部复制粘贴到 PCL 安装路径中的 bin 文件夹下

image-20220804103920697

2 配置环境变量

  1. 直接使用 win10 的搜索功能,搜索“环境变量”,打开系统的环境变量设置页面

  2. 双击 path 条目,打开环境变量添加页面

image-20220804105814584

  1. 然后将如下共 9 个路径添加进去(根据我的 PCL 安装目录做参考)

image-20220804110248731

  1. 全部添加完成之后,点击“确定”,关闭环境变量页面

  2. 然后看看是不是有如下三个环境变量,一般在安装 OPENNI2 时会自动添加,如果没有,请添加

image-20220804110609514

  1. 以上均确认无误之后,点击两次“确认”按钮,退出环境变量页面(每个确定都要点,否则等于没添加!!

3 VS2019 链接 PCL 库

下面的所有文件如果手动粘贴复制,无疑非常麻烦,而且如果换了 PCL 版本或者移动了 PCL 安装目录,那么所有的项目都要重新复制粘贴设置一次

所以我写了一个脚本,自动生成文件,只需要将对应文件的内容粘贴复制即可

脚本请移步我的 Github 仓库 中的 pcl_setting_file 项目

请先查看 README 文件,里面有脚本的使用方法,该脚本介绍 项目二:pcl_setting_file

  1. VS2019 的安装教程请问度娘

  2. 建立一个 C++ 空项目,随意新建一个源文件(不创建文件的话,后续的设置有个地方不显示),然后右键项目,点击【属性】,打开项目属性设置面板

  3. 首先最上边选择 Debugx64

image-20220804141714575

  1. 然后分别添加包含目录和库目录

包含目录:

E:\PROGRAM_PATH\PCL 1.12.1\3rdParty\Eigen\eigen3
E:\PROGRAM_PATH\PCL 1.12.1\3rdParty\FLANN\include
E:\PROGRAM_PATH\PCL 1.12.1\3rdParty\VTK\include\vtk-9.1
E:\PROGRAM_PATH\PCL 1.12.1\3rdParty\Qhull\include
E:\PROGRAM_PATH\PCL 1.12.1\include\pcl-1.12
E:\PROGRAM_PATH\PCL 1.12.1\3rdParty\Boost\include\boost-1_78
E:\PROGRAM_PATH\PCL 1.12.1\3rdParty\OpenNI2\Include

库目录:

E:\PROGRAM_PATH\PCL 1.12.1\3rdParty\Boost\lib
E:\PROGRAM_PATH\PCL 1.12.1\3rdParty\FLANN\lib
E:\PROGRAM_PATH\PCL 1.12.1\3rdParty\OpenNI2\Lib
E:\PROGRAM_PATH\PCL 1.12.1\3rdParty\Qhull\lib
E:\PROGRAM_PATH\PCL 1.12.1\3rdParty\VTK\lib
E:\PROGRAM_PATH\PCL 1.12.1\lib

image-20220804143513351

  1. 再设置附加依赖项
pcl_commond.lib
pcl_featuresd.lib
pcl_filtersd.lib
pcl_iod.lib
pcl_io_plyd.lib
pcl_kdtreed.lib
pcl_keypointsd.lib
pcl_mld.lib
pcl_octreed.lib
pcl_outofcored.lib
pcl_peopled.lib
pcl_recognitiond.lib
pcl_registrationd.lib
pcl_sample_consensusd.lib
pcl_searchd.lib
pcl_segmentationd.lib
pcl_stereod.lib
pcl_surfaced.lib
pcl_trackingd.lib
pcl_visualizationd.lib
libboost_atomic-vc142-mt-gd-x64-1_78.lib
libboost_bzip2-vc142-mt-gd-x64-1_78.lib
libboost_chrono-vc142-mt-gd-x64-1_78.lib
libboost_container-vc142-mt-gd-x64-1_78.lib
libboost_context-vc142-mt-gd-x64-1_78.lib
libboost_contract-vc142-mt-gd-x64-1_78.lib
libboost_coroutine-vc142-mt-gd-x64-1_78.lib
libboost_date_time-vc142-mt-gd-x64-1_78.lib
libboost_exception-vc142-mt-gd-x64-1_78.lib
libboost_filesystem-vc142-mt-gd-x64-1_78.lib
libboost_graph-vc142-mt-gd-x64-1_78.lib
libboost_graph_parallel-vc142-mt-gd-x64-1_78.lib
libboost_iostreams-vc142-mt-gd-x64-1_78.lib
libboost_json-vc142-mt-gd-x64-1_78.lib
libboost_locale-vc142-mt-gd-x64-1_78.lib
libboost_log-vc142-mt-gd-x64-1_78.lib
libboost_log_setup-vc142-mt-gd-x64-1_78.lib
libboost_math_c99-vc142-mt-gd-x64-1_78.lib
libboost_math_c99f-vc142-mt-gd-x64-1_78.lib
libboost_math_c99l-vc142-mt-gd-x64-1_78.lib
libboost_math_tr1-vc142-mt-gd-x64-1_78.lib
libboost_math_tr1f-vc142-mt-gd-x64-1_78.lib
libboost_math_tr1l-vc142-mt-gd-x64-1_78.lib
libboost_mpi-vc142-mt-gd-x64-1_78.lib
libboost_nowide-vc142-mt-gd-x64-1_78.lib
libboost_numpy38-vc142-mt-gd-x64-1_78.lib
libboost_prg_exec_monitor-vc142-mt-gd-x64-1_78.lib
libboost_program_options-vc142-mt-gd-x64-1_78.lib
libboost_python38-vc142-mt-gd-x64-1_78.lib
libboost_random-vc142-mt-gd-x64-1_78.lib
libboost_regex-vc142-mt-gd-x64-1_78.lib
libboost_serialization-vc142-mt-gd-x64-1_78.lib
libboost_system-vc142-mt-gd-x64-1_78.lib
libboost_test_exec_monitor-vc142-mt-gd-x64-1_78.lib
libboost_thread-vc142-mt-gd-x64-1_78.lib
libboost_timer-vc142-mt-gd-x64-1_78.lib
libboost_type_erasure-vc142-mt-gd-x64-1_78.lib
libboost_unit_test_framework-vc142-mt-gd-x64-1_78.lib
libboost_wave-vc142-mt-gd-x64-1_78.lib
libboost_wserialization-vc142-mt-gd-x64-1_78.lib
libboost_zlib-vc142-mt-gd-x64-1_78.lib
flann-gd.lib
flann_cpp-gd.lib
flann_cpp_s-gd.lib
flann_s-gd.lib
OpenNI2.lib
qhullcpp_d.lib
qhullstatic_d.lib
qhullstatic_rd.lib
qhull_rd.lib
vtkcgns-9.1d.lib
vtkChartsCore-9.1d.lib
vtkCommonColor-9.1d.lib
vtkCommonComputationalGeometry-9.1d.lib
vtkCommonCore-9.1d.lib
vtkCommonDataModel-9.1d.lib
vtkCommonExecutionModel-9.1d.lib
vtkCommonMath-9.1d.lib
vtkCommonMisc-9.1d.lib
vtkCommonSystem-9.1d.lib
vtkCommonTransforms-9.1d.lib
vtkDICOMParser-9.1d.lib
vtkDomainsChemistry-9.1d.lib
vtkDomainsChemistryOpenGL2-9.1d.lib
vtkdoubleconversion-9.1d.lib
vtkexodusII-9.1d.lib
vtkexpat-9.1d.lib
vtkFiltersAMR-9.1d.lib
vtkFiltersCore-9.1d.lib
vtkFiltersExtraction-9.1d.lib
vtkFiltersFlowPaths-9.1d.lib
vtkFiltersGeneral-9.1d.lib
vtkFiltersGeneric-9.1d.lib
vtkFiltersGeometry-9.1d.lib
vtkFiltersHybrid-9.1d.lib
vtkFiltersHyperTree-9.1d.lib
vtkFiltersImaging-9.1d.lib
vtkFiltersModeling-9.1d.lib
vtkFiltersParallel-9.1d.lib
vtkFiltersParallelImaging-9.1d.lib
vtkFiltersPoints-9.1d.lib
vtkFiltersProgrammable-9.1d.lib
vtkFiltersSelection-9.1d.lib
vtkFiltersSMP-9.1d.lib
vtkFiltersSources-9.1d.lib
vtkFiltersStatistics-9.1d.lib
vtkFiltersTexture-9.1d.lib
vtkFiltersTopology-9.1d.lib
vtkFiltersVerdict-9.1d.lib
vtkfmt-9.1d.lib
vtkfreetype-9.1d.lib
vtkGeovisCore-9.1d.lib
vtkgl2ps-9.1d.lib
vtkglew-9.1d.lib
vtkhdf5-9.1d.lib
vtkhdf5_hl-9.1d.lib
vtkImagingColor-9.1d.lib
vtkImagingCore-9.1d.lib
vtkImagingFourier-9.1d.lib
vtkImagingGeneral-9.1d.lib
vtkImagingHybrid-9.1d.lib
vtkImagingMath-9.1d.lib
vtkImagingMorphological-9.1d.lib
vtkImagingSources-9.1d.lib
vtkImagingStatistics-9.1d.lib
vtkImagingStencil-9.1d.lib
vtkInfovisCore-9.1d.lib
vtkInfovisLayout-9.1d.lib
vtkInteractionImage-9.1d.lib
vtkInteractionStyle-9.1d.lib
vtkInteractionWidgets-9.1d.lib
vtkIOAMR-9.1d.lib
vtkIOAsynchronous-9.1d.lib
vtkIOCGNSReader-9.1d.lib
vtkIOChemistry-9.1d.lib
vtkIOCityGML-9.1d.lib
vtkIOCONVERGECFD-9.1d.lib
vtkIOCore-9.1d.lib
vtkIOEnSight-9.1d.lib
vtkIOExodus-9.1d.lib
vtkIOExport-9.1d.lib
vtkIOExportGL2PS-9.1d.lib
vtkIOExportPDF-9.1d.lib
vtkIOGeometry-9.1d.lib
vtkIOHDF-9.1d.lib
vtkIOImage-9.1d.lib
vtkIOImport-9.1d.lib
vtkIOInfovis-9.1d.lib
vtkIOIOSS-9.1d.lib
vtkIOLegacy-9.1d.lib
vtkIOLSDyna-9.1d.lib
vtkIOMINC-9.1d.lib
vtkIOMotionFX-9.1d.lib
vtkIOMovie-9.1d.lib
vtkIONetCDF-9.1d.lib
vtkIOOggTheora-9.1d.lib
vtkIOParallel-9.1d.lib
vtkIOParallelXML-9.1d.lib
vtkIOPLY-9.1d.lib
vtkIOSegY-9.1d.lib
vtkIOSQL-9.1d.lib
vtkioss-9.1d.lib
vtkIOTecplotTable-9.1d.lib
vtkIOVeraOut-9.1d.lib
vtkIOVideo-9.1d.lib
vtkIOXML-9.1d.lib
vtkIOXMLParser-9.1d.lib
vtkjpeg-9.1d.lib
vtkjsoncpp-9.1d.lib
vtkkissfft-9.1d.lib
vtklibharu-9.1d.lib
vtklibproj-9.1d.lib
vtklibxml2-9.1d.lib
vtkloguru-9.1d.lib
vtklz4-9.1d.lib
vtklzma-9.1d.lib
vtkmetaio-9.1d.lib
vtknetcdf-9.1d.lib
vtkogg-9.1d.lib
vtkParallelCore-9.1d.lib
vtkParallelDIY-9.1d.lib
vtkpng-9.1d.lib
vtkpugixml-9.1d.lib
vtkRenderingAnnotation-9.1d.lib
vtkRenderingContext2D-9.1d.lib
vtkRenderingContextOpenGL2-9.1d.lib
vtkRenderingCore-9.1d.lib
vtkRenderingFreeType-9.1d.lib
vtkRenderingGL2PSOpenGL2-9.1d.lib
vtkRenderingImage-9.1d.lib
vtkRenderingLabel-9.1d.lib
vtkRenderingLOD-9.1d.lib
vtkRenderingOpenGL2-9.1d.lib
vtkRenderingSceneGraph-9.1d.lib
vtkRenderingUI-9.1d.lib
vtkRenderingVolume-9.1d.lib
vtkRenderingVolumeOpenGL2-9.1d.lib
vtkRenderingVtkJS-9.1d.lib
vtksqlite-9.1d.lib
vtksys-9.1d.lib
vtkTestingRendering-9.1d.lib
vtktheora-9.1d.lib
vtktiff-9.1d.lib
vtkverdict-9.1d.lib
vtkViewsContext2D-9.1d.lib
vtkViewsCore-9.1d.lib
vtkViewsInfovis-9.1d.lib
vtkWrappingTools-9.1d.lib
vtkzlib-9.1d.lib

image-20220804143635939

  1. 设置预编译命令
_CRT_SECURE_NO_WARNINGS

image-20220804143854647

  1. 设置环境
PATH=$(PCL_ROOT)\bin;$(PCL_ROOT)\3rdParty\FLANN\bin;$(PCL_ROOT)\3rdParty\VTK\bin;$(PCL_ROOT)\Qhull\bin;$(PCL_ROOT)\3rdParty\OpenNI2\Tools;$(PATH)

image-20220804150339962

  1. 全部设置好之后,先点击“应用”,再点击“确定”

  2. 执行下方的 cpp 文件,注意上方的 Debugx64 选对image-20220804150859981

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
int  main(int argc, char** argv){
    pcl::PointCloud<pcl::PointXYZ> cloud;   // Fill in the cloud data  
    cloud.width = 5;
    cloud.height = 1;
    cloud.is_dense = false;
    cloud.points.resize(cloud.width * cloud.height);
    for (std::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);
    }
    pcl::io::savePCDFileASCII("test_pcd.pcd", cloud);
    std::cerr << "Saved " << cloud.points.size() << " data points to test_pcd.pcd." << std::endl;
    for (std::size_t i = 0; i < cloud.points.size(); ++i)
        std::cerr << "    " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;
    return (0);
}
  1. 出现如下界面,表示 PCL 环境搭建全部完成

image-20220804151000073

posted @ 2022-08-04 21:17  悟道九霄  阅读(1111)  评论(0编辑  收藏  举报