1、PCL安装配置
下载pcl-1.11.1-pdb-msvc2019-win64与PCL-1.11.1-AllInOne-msvc2019-win64.exe文件。以管理员身份运行PCL-1.11.1-AllInOne-msvc2019-win64.exe程序,截图如下:
安装过程中没有弹出OpenNI2的安装,但是要安装在3rdParty下,但是安装时默认自动安装在C盘Program Files目录下。
解决办法:3rdParty\OpenNI2下有一个msi文件,双击,卸载,然后再重新安装到指定目录下就可以。在指定安装目录下安装结果如下:
安装结束后,将pcl-1.11.1-pdb-msvc2019-win64中pdb文件拷贝复制到C:\Program Files\PCL 1.11.1\bin路径下面即可。安装后系统变量会自动添加路径。
安装完毕后,将系统环境中添加路径,如下图:
此时PCL安装结束。切记,在配置完环境变量后,一定要重启电脑才有效!!
2、VS2019配置PCL
使用VS创建任意工程,命名为PCLStudy11的空项目,如下图所示
在属性管理器中新建属性表,命名为PCL11_1_X64_Release.props。(debug.props类似,后面不再详细介绍)
双击props文件后进行相应设置。
(1)包含目录与库目录设置如下:
包含目录设置如下:
库目录设置如下:
(2)在C/C++—>预处理器—>预处理器定下添加如下命令:
BOOST_USE_WINDOWS_H
NOMINMAX
_CRT_SECURE_NO_DEPRECATE
(3)C/C++ ->所有选项->SDL检查 改为否。在项目属性里,最好也在项目属性里,也将“SDL检查“改为”否“,不加这一步有时候会报错。
(3)添加附加依赖项
在链接器—>输入—>附加的依赖项中添加lib文件,需要注意的是release与debug不同,其中release下添加的lib文件如下:
pcl_common.lib
pcl_features.lib
pcl_filters.lib
pcl_io.lib
pcl_io_ply.lib
pcl_kdtree.lib
pcl_keypoints.lib
pcl_ml.lib
pcl_octree.lib
pcl_outofcore.lib
pcl_people.lib
pcl_recognition.lib
pcl_registration.lib
pcl_sample_consensus.lib
pcl_search.lib
pcl_segmentation.lib
pcl_stereo.lib
pcl_surface.lib
pcl_tracking.lib
pcl_visualization.lib
vtkChartsCore-8.2.lib
vtkCommonColor-8.2.lib
vtkCommonComputationalGeometry-8.2.lib
vtkCommonCore-8.2.lib
vtkCommonDataModel-8.2.lib
vtkCommonExecutionModel-8.2.lib
vtkCommonMath-8.2.lib
vtkCommonMisc-8.2.lib
vtkCommonSystem-8.2.lib
vtkCommonTransforms-8.2.lib
vtkDICOMParser-8.2.lib
vtkDomainsChemistry-8.2.lib
vtkDomainsChemistryOpenGL2-8.2.lib
vtkdoubleconversion-8.2.lib
vtkexodusII-8.2.lib
vtkexpat-8.2.lib
vtkFiltersAMR-8.2.lib
vtkFiltersCore-8.2.lib
vtkFiltersExtraction-8.2.lib
vtkFiltersFlowPaths-8.2.lib
vtkFiltersGeneral-8.2.lib
vtkFiltersGeneric-8.2.lib
vtkFiltersGeometry-8.2.lib
vtkFiltersHybrid-8.2.lib
vtkFiltersHyperTree-8.2.lib
vtkFiltersImaging-8.2.lib
vtkFiltersModeling-8.2.lib
vtkFiltersParallel-8.2.lib
vtkFiltersParallelImaging-8.2.lib
vtkFiltersPoints-8.2.lib
vtkFiltersProgrammable-8.2.lib
vtkFiltersSelection-8.2.lib
vtkFiltersSMP-8.2.lib
vtkFiltersSources-8.2.lib
vtkFiltersStatistics-8.2.lib
vtkFiltersTexture-8.2.lib
vtkFiltersTopology-8.2.lib
vtkFiltersVerdict-8.2.lib
vtkfreetype-8.2.lib
vtkGeovisCore-8.2.lib
vtkgl2ps-8.2.lib
vtkglew-8.2.lib
vtkGUISupportMFC-8.2.lib
vtkhdf5-8.2.lib
vtkhdf5_hl-8.2.lib
vtkImagingColor-8.2.lib
vtkImagingCore-8.2.lib
vtkImagingFourier-8.2.lib
vtkImagingGeneral-8.2.lib
vtkImagingHybrid-8.2.lib
vtkImagingMath-8.2.lib
vtkImagingMorphological-8.2.lib
vtkImagingSources-8.2.lib
vtkImagingStatistics-8.2.lib
vtkImagingStencil-8.2.lib
vtkInfovisCore-8.2.lib
vtkInfovisLayout-8.2.lib
vtkInteractionImage-8.2.lib
vtkInteractionStyle-8.2.lib
vtkInteractionWidgets-8.2.lib
vtkIOAMR-8.2.lib
vtkIOAsynchronous-8.2.lib
vtkIOCityGML-8.2.lib
vtkIOCore-8.2.lib
vtkIOEnSight-8.2.lib
vtkIOExodus-8.2.lib
vtkIOExport-8.2.lib
vtkIOExportOpenGL2-8.2.lib
vtkIOExportPDF-8.2.lib
vtkIOGeometry-8.2.lib
vtkIOImage-8.2.lib
vtkIOImport-8.2.lib
vtkIOInfovis-8.2.lib
vtkIOLegacy-8.2.lib
vtkIOLSDyna-8.2.lib
vtkIOMINC-8.2.lib
vtkIOMovie-8.2.lib
vtkIONetCDF-8.2.lib
vtkIOParallel-8.2.lib
vtkIOParallelXML-8.2.lib
vtkIOPLY-8.2.lib
vtkIOSegY-8.2.lib
vtkIOSQL-8.2.lib
vtkIOTecplotTable-8.2.lib
vtkIOVeraOut-8.2.lib
vtkIOVideo-8.2.lib
vtkIOXML-8.2.lib
vtkIOXMLParser-8.2.lib
vtkjpeg-8.2.lib
vtkjsoncpp-8.2.lib
vtklibharu-8.2.lib
vtklibxml2-8.2.lib
vtklz4-8.2.lib
vtklzma-8.2.lib
vtkmetaio-8.2.lib
vtkNetCDF-8.2.lib
vtkogg-8.2.lib
vtkParallelCore-8.2.lib
vtkpng-8.2.lib
vtkproj-8.2.lib
vtkpugixml-8.2.lib
vtkRenderingAnnotation-8.2.lib
vtkRenderingContext2D-8.2.lib
vtkRenderingContextOpenGL2-8.2.lib
vtkRenderingCore-8.2.lib
vtkRenderingExternal-8.2.lib
vtkRenderingFreeType-8.2.lib
vtkRenderingGL2PSOpenGL2-8.2.lib
vtkRenderingImage-8.2.lib
vtkRenderingLabel-8.2.lib
vtkRenderingLOD-8.2.lib
vtkRenderingOpenGL2-8.2.lib
vtkRenderingVolume-8.2.lib
vtkRenderingVolumeOpenGL2-8.2.lib
vtksqlite-8.2.lib
vtksys-8.2.lib
vtktheora-8.2.lib
vtktiff-8.2.lib
vtkverdict-8.2.lib
vtkViewsContext2D-8.2.lib
vtkViewsCore-8.2.lib
vtkViewsInfovis-8.2.lib
vtkzlib-8.2.lib
debug下添加的lib文件如下:
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
vtkChartsCore-8.2-gd.lib
vtkCommonColor-8.2-gd.lib
vtkCommonComputationalGeometry-8.2-gd.lib
vtkCommonCore-8.2-gd.lib
vtkCommonDataModel-8.2-gd.lib
vtkCommonExecutionModel-8.2-gd.lib
vtkCommonMath-8.2-gd.lib
vtkCommonMisc-8.2-gd.lib
vtkCommonSystem-8.2-gd.lib
vtkCommonTransforms-8.2-gd.lib
vtkDICOMParser-8.2-gd.lib
vtkDomainsChemistry-8.2-gd.lib
vtkDomainsChemistryOpenGL2-8.2-gd.lib
vtkdoubleconversion-8.2-gd.lib
vtkexodusII-8.2-gd.lib
vtkexpat-8.2-gd.lib
vtkFiltersAMR-8.2-gd.lib
vtkFiltersCore-8.2-gd.lib
vtkFiltersExtraction-8.2-gd.lib
vtkFiltersFlowPaths-8.2-gd.lib
vtkFiltersGeneral-8.2-gd.lib
vtkFiltersGeneric-8.2-gd.lib
vtkFiltersGeometry-8.2-gd.lib
vtkFiltersHybrid-8.2-gd.lib
vtkFiltersHyperTree-8.2-gd.lib
vtkFiltersImaging-8.2-gd.lib
vtkFiltersModeling-8.2-gd.lib
vtkFiltersParallel-8.2-gd.lib
vtkFiltersParallelImaging-8.2-gd.lib
vtkFiltersPoints-8.2-gd.lib
vtkFiltersProgrammable-8.2-gd.lib
vtkFiltersSelection-8.2-gd.lib
vtkFiltersSMP-8.2-gd.lib
vtkFiltersSources-8.2-gd.lib
vtkFiltersStatistics-8.2-gd.lib
vtkFiltersTexture-8.2-gd.lib
vtkFiltersTopology-8.2-gd.lib
vtkFiltersVerdict-8.2-gd.lib
vtkfreetype-8.2-gd.lib
vtkGeovisCore-8.2-gd.lib
vtkgl2ps-8.2-gd.lib
vtkglew-8.2-gd.lib
vtkGUISupportMFC-8.2-gd.lib
vtkhdf5-8.2-gd.lib
vtkhdf5_hl-8.2-gd.lib
vtkImagingColor-8.2-gd.lib
vtkImagingCore-8.2-gd.lib
vtkImagingFourier-8.2-gd.lib
vtkImagingGeneral-8.2-gd.lib
vtkImagingHybrid-8.2-gd.lib
vtkImagingMath-8.2-gd.lib
vtkImagingMorphological-8.2-gd.lib
vtkImagingSources-8.2-gd.lib
vtkImagingStatistics-8.2-gd.lib
vtkImagingStencil-8.2-gd.lib
vtkInfovisCore-8.2-gd.lib
vtkInfovisLayout-8.2-gd.lib
vtkInteractionImage-8.2-gd.lib
vtkInteractionStyle-8.2-gd.lib
vtkInteractionWidgets-8.2-gd.lib
vtkIOAMR-8.2-gd.lib
vtkIOAsynchronous-8.2-gd.lib
vtkIOCityGML-8.2-gd.lib
vtkIOCore-8.2-gd.lib
vtkIOEnSight-8.2-gd.lib
vtkIOExodus-8.2-gd.lib
vtkIOExport-8.2-gd.lib
vtkIOExportOpenGL2-8.2-gd.lib
vtkIOExportPDF-8.2-gd.lib
vtkIOGeometry-8.2-gd.lib
vtkIOImage-8.2-gd.lib
vtkIOImport-8.2-gd.lib
vtkIOInfovis-8.2-gd.lib
vtkIOLegacy-8.2-gd.lib
vtkIOLSDyna-8.2-gd.lib
vtkIOMINC-8.2-gd.lib
vtkIOMovie-8.2-gd.lib
vtkIONetCDF-8.2-gd.lib
vtkIOParallel-8.2-gd.lib
vtkIOParallelXML-8.2-gd.lib
vtkIOPLY-8.2-gd.lib
vtkIOSegY-8.2-gd.lib
vtkIOSQL-8.2-gd.lib
vtkIOTecplotTable-8.2-gd.lib
vtkIOVeraOut-8.2-gd.lib
vtkIOVideo-8.2-gd.lib
vtkIOXML-8.2-gd.lib
vtkIOXMLParser-8.2-gd.lib
vtkjpeg-8.2-gd.lib
vtkjsoncpp-8.2-gd.lib
vtklibharu-8.2-gd.lib
vtklibxml2-8.2-gd.lib
vtklz4-8.2-gd.lib
vtklzma-8.2-gd.lib
vtkmetaio-8.2-gd.lib
vtkNetCDF-8.2-gd.lib
vtkogg-8.2-gd.lib
vtkParallelCore-8.2-gd.lib
vtkpng-8.2-gd.lib
vtkproj-8.2-gd.lib
vtkpugixml-8.2-gd.lib
vtkRenderingAnnotation-8.2-gd.lib
vtkRenderingContext2D-8.2-gd.lib
vtkRenderingContextOpenGL2-8.2-gd.lib
vtkRenderingCore-8.2-gd.lib
vtkRenderingExternal-8.2-gd.lib
vtkRenderingFreeType-8.2-gd.lib
vtkRenderingGL2PSOpenGL2-8.2-gd.lib
vtkRenderingImage-8.2-gd.lib
vtkRenderingLabel-8.2-gd.lib
vtkRenderingLOD-8.2-gd.lib
vtkRenderingOpenGL2-8.2-gd.lib
vtkRenderingVolume-8.2-gd.lib
vtkRenderingVolumeOpenGL2-8.2-gd.lib
vtksqlite-8.2-gd.lib
vtksys-8.2-gd.lib
vtktheora-8.2-gd.lib
vtktiff-8.2-gd.lib
vtkverdict-8.2-gd.lib
vtkViewsContext2D-8.2-gd.lib
vtkViewsCore-8.2-gd.lib
vtkViewsInfovis-8.2-gd.lib
vtkzlib-8.2-gd.lib
3、错误小结
(1)在vs2013中char *在vs2019中会出错,因此需要进行如下设置:
右键项目 -> 属性 -> C/C++ -> 语言 -> 符合模式:否
4、其他工程引用
在其他工程下,不需要再重新配置,只需要在属性管理器窗口中添加刚才创建的props属性(debug与release)文件即可,不会出现错误。同时需要进行如下设置:
(1)右键项目 -> 属性 -> C/C++ -> 语言 -> 符合模式:否
(2)将项目属性->C/C++->所有选项->SDL检查 设置成否
5、测试代码
运行下面代码,程序正常运行,显示如下点云,表明配置成功。
#include <iostream>
#include <vector>
#include <ctime>
#include <pcl/point_cloud.h>
#include <pcl/octree/octree.h>
#include <boost/thread/thread.hpp>
#include <pcl/visualization/pcl_visualizer.h>
using namespace std;
int
main(int argc, char** argv)
{
srand((unsigned int)time(NULL));
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// 创建点云数据
cloud->width = 1000;
cloud->height = 1;
cloud->points.resize(cloud->width * cloud->height);
for (size_t i = 0; i < cloud->points.size(); ++i)
{
cloud->points[i].x = 1024.0f * rand() / (RAND_MAX + 1.0f);
cloud->points[i].y = 1024.0f * rand() / (RAND_MAX + 1.0f);
cloud->points[i].z = 1024.0f * rand() / (RAND_MAX + 1.0f);
}
pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(0.1);
octree.setInputCloud(cloud);
octree.addPointsFromInputCloud();
pcl::PointXYZ searchPoint;
searchPoint.x = 1024.0f * rand() / (RAND_MAX + 1.0f);
searchPoint.y = 1024.0f * rand() / (RAND_MAX + 1.0f);
searchPoint.z = 1024.0f * rand() / (RAND_MAX + 1.0f);
//半径内近邻搜索
vector<int>pointIdxRadiusSearch;
vector<float>pointRadiusSquaredDistance;
float radius = 256.0f * rand() / (RAND_MAX + 1.0f);
cout << "Neighbors within radius search at (" << searchPoint.x
<< " " << searchPoint.y
<< " " << searchPoint.z
<< ") with radius=" << radius << endl;
if (octree.radiusSearch(searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance) > 0)
{
for (size_t i = 0; i < pointIdxRadiusSearch.size(); ++i)
cout << " " << cloud->points[pointIdxRadiusSearch[i]].x
<< " " << cloud->points[pointIdxRadiusSearch[i]].y
<< " " << cloud->points[pointIdxRadiusSearch[i]].z
<< " (squared distance: " << pointRadiusSquaredDistance[i] << ")" << endl;
}
// 初始化点云可视化对象
boost::shared_ptr<pcl::visualization::PCLVisualizer>viewer(new pcl::visualization::PCLVisualizer("显示点云"));
viewer->setBackgroundColor(0, 0, 0); //设置背景颜色为黑色
// 对点云着色可视化 (red).
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>target_color(cloud, 255, 0, 0);
viewer->addPointCloud<pcl::PointXYZ>(cloud, target_color, "target cloud");
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "target cloud");
// 等待直到可视化窗口关闭
while (!viewer->wasStopped())
{
viewer->spinOnce(100);
boost::this_thread::sleep(boost::posix_time::microseconds(1000));
}
return (0);
}