一直在做点云相关内容,虽然PCL库很方便,但配置起来太麻烦了,一开始尝试几次都没有成功,很搞心态。直到今天,还是在生日当天,终于配置成功了呜呜,流下了激动的泪水,这真的是最棒的礼物了,所以马不停蹄的记录一下。
其实其他博客对相关步骤说明的已经很清晰了,但跟着配置下来总会出现各种各样的问题,很大程度上是安装目录、版本等不同导致的,所以要真正明白每一步骤的作用并耐心一一解决出现的bug。
接下来就简要梳理下核心步骤,主要是对整个安装过程有个宏观了解。
链接:https://pan.baidu.com/s/1vWjaGcr7c1XBSdaSD3FsEg
提取码:o9st
在百度网盘里有PCL1.8.1的安装程序以及PDB文件
其他版本也可在此处下载:Releases · PointCloudLibrary/pcl · GitHub
win10系统下 VS2019点云库PCL1.12.0的安装与配置_苦瓜王子的博客-CSDN博客_pcl库下载
我安装的目录在D:\Program Files\PCL 1.8.1,安装步骤按照弹出的默认来即可,其中以下步骤要勾选第二项添加路径
安装过程中会弹出OpenNI的安装程序,要安装在D:\Program Files\PCL 1.8.1\3rdParty\OpenNI2目录下
全部安装完成后目录文件分布如下所示。
添加PDB文件,将PDB文件解压复制到D:\Program Files\PCL 1.8.1\bin目录下,最终为246个文件。
在计算机属性里的高级系统设置里的环境变量中进行设置。
添加以下内容(最好再和自己的目录对应下,看看这些文件是否都存在):
D:\Program Files\PCL 1.8.1\bin
D:\Program Files\PCL 1.8.1\3rdParty\FLANN\bin
D:\Program Files\PCL 1.8.1\3rdParty\Qhull\bin
D:\Program Files\PCL 1.8.1\3rdParty\VTK\bin
D:\Program Files\PCL 1.8.1\3rdParty\OpenNI2\Tools
添加完之后要重启!
在vs2017中添加属性表,在属性表的属性中进行设置。
将以下路径添加到VC++目录的包含目录:
D:\Program Files\PCL 1.8.1\include\pcl-1.8
D:\Program Files\PCL 1.8.1\3rdParty\Boost\include\boost-1_64
D:\Program Files\PCL 1.8.1\3rdParty\Eigen\eigen3
D:\Program Files\PCL 1.8.1\3rdParty\FLANN\include
D:\Program Files\PCL 1.8.1\3rdParty\Qhull\include
D:\Program Files\PCL 1.8.1\3rdParty\VTK\include\vtk-8.0
D:\Program Files\PCL 1.8.1\3rdParty\OpenNI2\Include
将以下路径添加到VC++目录的库目录:
D:\Program Files\PCL 1.8.1\lib
D:\Program Files\PCL 1.8.1\3rdParty\FLANN\lib
D:\Program Files\PCL 1.8.1\3rdParty\Boost\lib
D:\Program Files\PCL 1.8.1\3rdParty\Qhull\lib
D:\Program Files\PCL 1.8.1\3rdParty\VTK\lib
D:\Program Files\PCL 1.8.1\3rdParty\OpenNI2\Lib
在预处理器定义中输入以下命令:
_SCL_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS
如果安装在VS2019版本中,命令如下:
vs2019配置PCL1-8-1(windows)_zh小辣鸡的博客-CSDN博客_pcl vs2019配置
_CRT_SECURE_NO_WARNINGS
BOOST_ALL_NO_LIB
BOOST_USE_WINDOWS_H
NOMINMAX
_SCL_SECURE_NO_WARNINGS
_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING
在附加依赖项中添加以下命令,可以自己生成,也可以直接用下方整理好的
先把各个库的debug版和release版的lib分别复制到两个不同的文件夹,再通过cmd来生成文件名列表,生成文件名列表的方法如下:
win+r调出“运行”窗口并输出cmd
输入:cd /d D:\ debug_version 回车 (以放debug版的lib文件夹为例)
输出:dir /b *.lib>1.txt
在文件夹下可看见一个txt,打开即可复制。
lib文件所在位置如下,其中debug模式下共有185个文件,release模式下共有186个文件(多了OpenNI2里的OpenNI2.lib),最后需要分别再添加opengl32.lib,可以减少一些隐藏错误。
带-gd的和带d的为debug模式,不带的为release模式。
详细提取文件名步骤参考:PCL安装与配置 - 一杯明月 - 博客园
pcl_common_debug.lib
pcl_features_debug.lib
pcl_filters_debug.lib
pcl_io_ply_debug.lib
pcl_io_debug.lib
pcl_kdtree_debug.lib
pcl_keypoints_debug.lib
pcl_ml_debug.lib
pcl_octree_debug.lib
pcl_outofcore_debug.lib
pcl_people_debug.lib
pcl_recognition_debug.lib
pcl_registration_debug.lib
pcl_sample_consensus_debug.lib
pcl_search_debug.lib
pcl_segmentation_debug.lib
pcl_stereo_debug.lib
pcl_surface_debug.lib
pcl_tracking_debug.lib
pcl_visualization_debug.lib
libboost_atomic-vc141-mt-gd-1_64.lib
libboost_bzip2-vc141-mt-gd-1_64.lib
libboost_chrono-vc141-mt-gd-1_64.lib
libboost_container-vc141-mt-gd-1_64.lib
libboost_context-vc141-mt-gd-1_64.lib
libboost_coroutine-vc141-mt-gd-1_64.lib
libboost_date_time-vc141-mt-gd-1_64.lib
libboost_exception-vc141-mt-gd-1_64.lib
libboost_fiber-vc141-mt-gd-1_64.lib
libboost_filesystem-vc141-mt-gd-1_64.lib
libboost_graph-vc141-mt-gd-1_64.lib
libboost_graph_parallel-vc141-mt-gd-1_64.lib
libboost_iostreams-vc141-mt-gd-1_64.lib
libboost_locale-vc141-mt-gd-1_64.lib
libboost_log-vc141-mt-gd-1_64.lib
libboost_log_setup-vc141-mt-gd-1_64.lib
libboost_math_c99-vc141-mt-gd-1_64.lib
libboost_math_c99f-vc141-mt-gd-1_64.lib
libboost_math_c99l-vc141-mt-gd-1_64.lib
libboost_math_tr1-vc141-mt-gd-1_64.lib
libboost_math_tr1f-vc141-mt-gd-1_64.lib
libboost_math_tr1l-vc141-mt-gd-1_64.lib
libboost_mpi-vc141-mt-gd-1_64.lib
libboost_numpy3-vc141-mt-gd-1_64.lib
libboost_numpy-vc141-mt-gd-1_64.lib
libboost_prg_exec_monitor-vc141-mt-gd-1_64.lib
libboost_program_options-vc141-mt-gd-1_64.lib
libboost_python3-vc141-mt-gd-1_64.lib
libboost_python-vc141-mt-gd-1_64.lib
libboost_random-vc141-mt-gd-1_64.lib
libboost_regex-vc141-mt-gd-1_64.lib
libboost_serialization-vc141-mt-gd-1_64.lib
libboost_signals-vc141-mt-gd-1_64.lib
libboost_system-vc141-mt-gd-1_64.lib
libboost_test_exec_monitor-vc141-mt-gd-1_64.lib
libboost_thread-vc141-mt-gd-1_64.lib
libboost_timer-vc141-mt-gd-1_64.lib
libboost_type_erasure-vc141-mt-gd-1_64.lib
libboost_unit_test_framework-vc141-mt-gd-1_64.lib
libboost_wave-vc141-mt-gd-1_64.lib
libboost_wserialization-vc141-mt-gd-1_64.lib
libboost_zlib-vc141-mt-gd-1_64.lib
flann-gd.lib
flann_cpp-gd.lib
flann_cpp_s-gd.lib
flann_s-gd.lib
qhull_d.lib
qhullcpp_d.lib
qhullstatic_d.lib
qhullstatic_r_d.lib
qhull_p_d.lib
qhull_r_d.lib
vtkalglib-8.0-gd.lib
vtkChartsCore-8.0-gd.lib
vtkCommonColor-8.0-gd.lib
vtkCommonComputationalGeometry-8.0-gd.lib
vtkCommonCore-8.0-gd.lib
vtkCommonDataModel-8.0-gd.lib
vtkCommonExecutionModel-8.0-gd.lib
vtkCommonMath-8.0-gd.lib
vtkCommonMisc-8.0-gd.lib
vtkCommonSystem-8.0-gd.lib
vtkCommonTransforms-8.0-gd.lib
vtkDICOMParser-8.0-gd.lib
vtkDomainsChemistry-8.0-gd.lib
vtkexoIIc-8.0-gd.lib
vtkexpat-8.0-gd.lib
vtkFiltersAMR-8.0-gd.lib
vtkFiltersCore-8.0-gd.lib
vtkFiltersExtraction-8.0-gd.lib
vtkFiltersFlowPaths-8.0-gd.lib
vtkFiltersGeneral-8.0-gd.lib
vtkFiltersGeneric-8.0-gd.lib
vtkFiltersGeometry-8.0-gd.lib
vtkFiltersHybrid-8.0-gd.lib
vtkFiltersHyperTree-8.0-gd.lib
vtkFiltersImaging-8.0-gd.lib
vtkFiltersModeling-8.0-gd.lib
vtkFiltersParallel-8.0-gd.lib
vtkFiltersParallelImaging-8.0-gd.lib
vtkFiltersPoints-8.0-gd.lib
vtkFiltersProgrammable-8.0-gd.lib
vtkFiltersSelection-8.0-gd.lib
vtkFiltersSMP-8.0-gd.lib
vtkFiltersSources-8.0-gd.lib
vtkFiltersStatistics-8.0-gd.lib
vtkFiltersTexture-8.0-gd.lib
vtkFiltersTopology-8.0-gd.lib
vtkFiltersVerdict-8.0-gd.lib
vtkfreetype-8.0-gd.lib
vtkGeovisCore-8.0-gd.lib
vtkgl2ps-8.0-gd.lib
vtkhdf5-8.0-gd.lib
vtkhdf5_hl-8.0-gd.lib
vtkImagingColor-8.0-gd.lib
vtkImagingCore-8.0-gd.lib
vtkImagingFourier-8.0-gd.lib
vtkImagingGeneral-8.0-gd.lib
vtkImagingHybrid-8.0-gd.lib
vtkImagingMath-8.0-gd.lib
vtkImagingMorphological-8.0-gd.lib
vtkImagingSources-8.0-gd.lib
vtkImagingStatistics-8.0-gd.lib
vtkImagingStencil-8.0-gd.lib
vtkInfovisCore-8.0-gd.lib
vtkInfovisLayout-8.0-gd.lib
vtkInteractionImage-8.0-gd.lib
vtkInteractionStyle-8.0-gd.lib
vtkInteractionWidgets-8.0-gd.lib
vtkIOAMR-8.0-gd.lib
vtkIOCore-8.0-gd.lib
vtkIOEnSight-8.0-gd.lib
vtkIOExodus-8.0-gd.lib
vtkIOExport-8.0-gd.lib
vtkIOExportOpenGL-8.0-gd.lib
vtkIOGeometry-8.0-gd.lib
vtkIOImage-8.0-gd.lib
vtkIOImport-8.0-gd.lib
vtkIOInfovis-8.0-gd.lib
vtkIOLegacy-8.0-gd.lib
vtkIOLSDyna-8.0-gd.lib
vtkIOMINC-8.0-gd.lib
vtkIOMovie-8.0-gd.lib
vtkIONetCDF-8.0-gd.lib
vtkIOParallel-8.0-gd.lib
vtkIOParallelXML-8.0-gd.lib
vtkIOPLY-8.0-gd.lib
vtkIOSQL-8.0-gd.lib
vtkIOTecplotTable-8.0-gd.lib
vtkIOVideo-8.0-gd.lib
vtkIOXML-8.0-gd.lib
vtkIOXMLParser-8.0-gd.lib
vtkjpeg-8.0-gd.lib
vtkjsoncpp-8.0-gd.lib
vtklibharu-8.0-gd.lib
vtklibxml2-8.0-gd.lib
vtklz4-8.0-gd.lib
vtkmetaio-8.0-gd.lib
vtkNetCDF-8.0-gd.lib
vtkoggtheora-8.0-gd.lib
vtkParallelCore-8.0-gd.lib
vtkpng-8.0-gd.lib
vtkproj4-8.0-gd.lib
vtkRenderingAnnotation-8.0-gd.lib
vtkRenderingContext2D-8.0-gd.lib
vtkRenderingContextOpenGL-8.0-gd.lib
vtkRenderingCore-8.0-gd.lib
vtkRenderingFreeType-8.0-gd.lib
vtkRenderingGL2PS-8.0-gd.lib
vtkRenderingImage-8.0-gd.lib
vtkRenderingLabel-8.0-gd.lib
vtkRenderingLIC-8.0-gd.lib
vtkRenderingLOD-8.0-gd.lib
vtkRenderingOpenGL-8.0-gd.lib
vtkRenderingVolume-8.0-gd.lib
vtkRenderingVolumeOpenGL-8.0-gd.lib
vtksqlite-8.0-gd.lib
vtksys-8.0-gd.lib
vtktiff-8.0-gd.lib
vtkverdict-8.0-gd.lib
vtkViewsContext2D-8.0-gd.lib
vtkViewsCore-8.0-gd.lib
vtkViewsInfovis-8.0-gd.lib
vtkzlib-8.0-gd.lib
vtknetcdf_c++-gd.lib
opengl32.lib
flann.lib
flann_cpp.lib
flann_cpp_s.lib
flann_s.lib
libboost_atomic-vc141-mt-1_64.lib
libboost_bzip2-vc141-mt-1_64.lib
libboost_chrono-vc141-mt-1_64.lib
libboost_container-vc141-mt-1_64.lib
libboost_context-vc141-mt-1_64.lib
libboost_coroutine-vc141-mt-1_64.lib
libboost_date_time-vc141-mt-1_64.lib
libboost_exception-vc141-mt-1_64.lib
libboost_fiber-vc141-mt-1_64.lib
libboost_filesystem-vc141-mt-1_64.lib
libboost_graph-vc141-mt-1_64.lib
libboost_graph_parallel-vc141-mt-1_64.lib
libboost_iostreams-vc141-mt-1_64.lib
libboost_locale-vc141-mt-1_64.lib
libboost_log-vc141-mt-1_64.lib
libboost_log_setup-vc141-mt-1_64.lib
libboost_math_c99-vc141-mt-1_64.lib
libboost_math_c99f-vc141-mt-1_64.lib
libboost_math_c99l-vc141-mt-1_64.lib
libboost_math_tr1-vc141-mt-1_64.lib
libboost_math_tr1f-vc141-mt-1_64.lib
libboost_math_tr1l-vc141-mt-1_64.lib
libboost_mpi-vc141-mt-1_64.lib
libboost_numpy-vc141-mt-1_64.lib
libboost_numpy3-vc141-mt-1_64.lib
libboost_prg_exec_monitor-vc141-mt-1_64.lib
libboost_program_options-vc141-mt-1_64.lib
libboost_python-vc141-mt-1_64.lib
libboost_python3-vc141-mt-1_64.lib
libboost_random-vc141-mt-1_64.lib
libboost_regex-vc141-mt-1_64.lib
libboost_serialization-vc141-mt-1_64.lib
libboost_signals-vc141-mt-1_64.lib
libboost_system-vc141-mt-1_64.lib
libboost_test_exec_monitor-vc141-mt-1_64.lib
libboost_thread-vc141-mt-1_64.lib
libboost_timer-vc141-mt-1_64.lib
libboost_type_erasure-vc141-mt-1_64.lib
libboost_unit_test_framework-vc141-mt-1_64.lib
libboost_wave-vc141-mt-1_64.lib
libboost_wserialization-vc141-mt-1_64.lib
libboost_zlib-vc141-mt-1_64.lib
OpenNI2.lib
pcl_common_release.lib
pcl_features_release.lib
pcl_filters_release.lib
pcl_io_ply_release.lib
pcl_io_release.lib
pcl_kdtree_release.lib
pcl_keypoints_release.lib
pcl_ml_release.lib
pcl_octree_release.lib
pcl_outofcore_release.lib
pcl_people_release.lib
pcl_recognition_release.lib
pcl_registration_release.lib
pcl_sample_consensus_release.lib
pcl_search_release.lib
pcl_segmentation_release.lib
pcl_stereo_release.lib
pcl_surface_release.lib
pcl_tracking_release.lib
pcl_visualization_release.lib
qhull.lib
qhullcpp.lib
qhullstatic.lib
qhullstatic_r.lib
qhull_p.lib
qhull_r.lib
vtkalglib-8.0.lib
vtkChartsCore-8.0.lib
vtkCommonColor-8.0.lib
vtkCommonComputationalGeometry-8.0.lib
vtkCommonCore-8.0.lib
vtkCommonDataModel-8.0.lib
vtkCommonExecutionModel-8.0.lib
vtkCommonMath-8.0.lib
vtkCommonMisc-8.0.lib
vtkCommonSystem-8.0.lib
vtkCommonTransforms-8.0.lib
vtkDICOMParser-8.0.lib
vtkDomainsChemistry-8.0.lib
vtkexoIIc-8.0.lib
vtkexpat-8.0.lib
vtkFiltersAMR-8.0.lib
vtkFiltersCore-8.0.lib
vtkFiltersExtraction-8.0.lib
vtkFiltersFlowPaths-8.0.lib
vtkFiltersGeneral-8.0.lib
vtkFiltersGeneric-8.0.lib
vtkFiltersGeometry-8.0.lib
vtkFiltersHybrid-8.0.lib
vtkFiltersHyperTree-8.0.lib
vtkFiltersImaging-8.0.lib
vtkFiltersModeling-8.0.lib
vtkFiltersParallel-8.0.lib
vtkFiltersParallelImaging-8.0.lib
vtkFiltersPoints-8.0.lib
vtkFiltersProgrammable-8.0.lib
vtkFiltersSelection-8.0.lib
vtkFiltersSMP-8.0.lib
vtkFiltersSources-8.0.lib
vtkFiltersStatistics-8.0.lib
vtkFiltersTexture-8.0.lib
vtkFiltersTopology-8.0.lib
vtkFiltersVerdict-8.0.lib
vtkfreetype-8.0.lib
vtkGeovisCore-8.0.lib
vtkgl2ps-8.0.lib
vtkhdf5-8.0.lib
vtkhdf5_hl-8.0.lib
vtkImagingColor-8.0.lib
vtkImagingCore-8.0.lib
vtkImagingFourier-8.0.lib
vtkImagingGeneral-8.0.lib
vtkImagingHybrid-8.0.lib
vtkImagingMath-8.0.lib
vtkImagingMorphological-8.0.lib
vtkImagingSources-8.0.lib
vtkImagingStatistics-8.0.lib
vtkImagingStencil-8.0.lib
vtkInfovisCore-8.0.lib
vtkInfovisLayout-8.0.lib
vtkInteractionImage-8.0.lib
vtkInteractionStyle-8.0.lib
vtkInteractionWidgets-8.0.lib
vtkIOAMR-8.0.lib
vtkIOCore-8.0.lib
vtkIOEnSight-8.0.lib
vtkIOExodus-8.0.lib
vtkIOExport-8.0.lib
vtkIOExportOpenGL-8.0.lib
vtkIOGeometry-8.0.lib
vtkIOImage-8.0.lib
vtkIOImport-8.0.lib
vtkIOInfovis-8.0.lib
vtkIOLegacy-8.0.lib
vtkIOLSDyna-8.0.lib
vtkIOMINC-8.0.lib
vtkIOMovie-8.0.lib
vtkIONetCDF-8.0.lib
vtkIOParallel-8.0.lib
vtkIOParallelXML-8.0.lib
vtkIOPLY-8.0.lib
vtkIOSQL-8.0.lib
vtkIOTecplotTable-8.0.lib
vtkIOVideo-8.0.lib
vtkIOXML-8.0.lib
vtkIOXMLParser-8.0.lib
vtkjpeg-8.0.lib
vtkjsoncpp-8.0.lib
vtklibharu-8.0.lib
vtklibxml2-8.0.lib
vtklz4-8.0.lib
vtkmetaio-8.0.lib
vtkNetCDF-8.0.lib
vtknetcdf_c++.lib
vtkoggtheora-8.0.lib
vtkParallelCore-8.0.lib
vtkpng-8.0.lib
vtkproj4-8.0.lib
vtkRenderingAnnotation-8.0.lib
vtkRenderingContext2D-8.0.lib
vtkRenderingContextOpenGL-8.0.lib
vtkRenderingCore-8.0.lib
vtkRenderingFreeType-8.0.lib
vtkRenderingGL2PS-8.0.lib
vtkRenderingImage-8.0.lib
vtkRenderingLabel-8.0.lib
vtkRenderingLIC-8.0.lib
vtkRenderingLOD-8.0.lib
vtkRenderingOpenGL-8.0.lib
vtkRenderingVolume-8.0.lib
vtkRenderingVolumeOpenGL-8.0.lib
vtksqlite-8.0.lib
vtksys-8.0.lib
vtktiff-8.0.lib
vtkverdict-8.0.lib
vtkViewsContext2D-8.0.lib
vtkViewsCore-8.0.lib
vtkViewsInfovis-8.0.lib
vtkzlib-8.0.lib
opengl32.lib
gdi32.lib
User32.lib
在vs2022配置1.13版本
(30条消息) Win10 系统下VisualStudio2022 配置点云库 PCL 1.13.0_胖胖12138的博客-CSDN博客
win+vs2022+pcl 1.13.0 all in one 安装 - 赛博坦的bimer - 博客园 (cnblogs.com)
1.项目解决方案配置需设置为Debug X64
2.遇到“error C4996:pcl::SAC_SAMPLE_SIZE”的解决办法:SDL检查需设置为否
2.遇到“pop_t找不到标识符”的解决办法:打开dist.h文件,将503行的typedef unsigned long long pop_t;移到#if GNUC一行的前面。
3.遇到C2988:“不可识别的模板声明/定义”的解决办法:打开typeof_impl.hpp文件,将以下几行代码注释掉。
4.遇到错误 C4996 ‘std::fpos<_Mbstatet>::seekpos’: warning STL4019: The member std::fpos::seekpos() is non-Standard, and is preserved only for compatibility with workarounds for old versions of Visual C++.的解决办法:
预处理项中添加_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING
5.请确认Import中声明的路径是否正确
配置完属性表,在移植时又可能出现不对应的情况
(5条消息) vs未找到导入的项目,请确认
#include
#include
#include
#include
#include
int main(int argc, char**argv)
{
srand(time(NULL)); //用系统时间初始化随机种子
pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
//点云生成
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::KdTreeFLANNkdtree; //创建K-D Tree 对象
kdtree.setInputCloud(cloud); //设置搜索空间
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);
// k近邻搜索
int K = 10;
std::vectorpointIdxNKNSearch(K); //存储查询点近邻索引
std::vectorpointNKNSquaredDistance(K); //存储近邻点对应平方距离
std::cout << "K nearest neighbor search at ("
<< searchPoint.x
<< " " << searchPoint.y
<< " " << searchPoint.z
<< ") with K=" << K << std::endl;
if (kdtree.nearestKSearch(searchPoint, K, pointIdxNKNSearch, pointNKNSquaredDistance) > 0) //执行K近邻搜索
{
for (size_t i = 0; i < pointIdxNKNSearch.size(); ++i)
std::cout << " " << cloud->points[pointIdxNKNSearch[i]].x
<< " " << cloud->points[pointIdxNKNSearch[i]].y
<< " " << cloud->points[pointIdxNKNSearch[i]].z
<< " (squared distance: " << pointNKNSquaredDistance[i] << ")" << std::endl;
}
// 在半径r内搜索近邻
std::vector pointIdxRadiusSearch;
std::vector pointRadiusSquaredDistance;
float radius = 156;
std::cout << "Neighbors within radius search at (" << searchPoint.x
<< " " << searchPoint.y
<< " " << searchPoint.z
<< ") with radius=" << radius << std::endl;
if (kdtree.radiusSearch(searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance) > 0)
{
for (size_t i = 0; i < pointIdxRadiusSearch.size(); ++i)
std::cout << " " << cloud->points[pointIdxRadiusSearch[i]].x
<< " " << cloud->points[pointIdxRadiusSearch[i]].y
<< " " << cloud->points[pointIdxRadiusSearch[i]].z
<< " (squared distance: " << pointRadiusSquaredDistance[i] << ")" << std::endl;
}
pcl::io::savePCDFileASCII("1.pcd", *cloud); //保存点云
std::cerr << "Saved " << cloud->points.size() << " data points to 1.pcd." << std::endl; //输出保存点的个数
//输出保存点的坐标
for (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;
//可视化生成点云
pcl::visualization::CloudViewer viewer("Cloud Viewer");
viewer.showCloud(cloud);
while (!viewer.wasStopped())
{
}
return 0;
}