点云pc库的下载与安装参考另外一篇文章,链接:
https://blog.csdn.net/weixin_47869094/article/details/131270772?spm=1001.2014.3001.5501
各种教程里面这都很好,就不赘述了,当然,这里也给出一个个人认为不错的安装文章提供参考。
Visual Studio 2022 配置 PCL 1.12.1 的经验总结分享
win10系统VS2019配置点云库PCL1.12.1的教程与经验总结
如果已经下载好了,直接进行环境变量配置。
一般建议pcl安装c盘,环境变量添加以下路径:
C:\PCL 1.12.1\bin
C:\PCL 1.12.1\3rdParty\VTK\bin
C:\PCL 1.12.1\3rdParty\FLANN\bin
C:\PCL 1.12.1\3rdParty\Qhull\bin
C:\PCL 1.12.1\3rdParty\Boost\lib
C:\PCL 1.12.1\3rdParty\OpenNI2\Tools
C:\PCL 1.12.1\3rdParty\OpenNI2\Redist
安装完pcl会有这几个
在path里面进行环境编辑,可能有多的有少的,尽量全部添加,后期避免出错:
%PCL_ROOT%\bin
%PCL_ROOT%\3rdParty\VTK\bin
%PCL_ROOT%\3rdParty\FLANN\bin
%PCL_ROOT%\3rdParty\Qhull\bin
%PCL_ROOT%\3rdParty\OpenNI2\Tools
%OPENNI2_REDIST64%
%OPENNI2_LIB64%
%OPENNI2_INCLUDE64%
到这里环境配置差不多,接下啦进行vscode配置对应。
VS2019配置
(1)创建新项目
这里选择debug和x64模式
(2)新建源文件
点击添加
(3)打开属性表
4)配置属性:调试-》环境-》编辑
PATH=E:\awork\Package\PCL 1.13.0-rc1\\bin;E:\awork\Package\PCL 1.13.0-rc1\\3rdParty\FLANN\bin;E:\awork\Package\PCL 1.13.0-rc1\\3rdParty\VTK\bin;E:\awork\Package\PCL 1.13.0-rc1\\3rdParty\OpenNI2\Tools
5)C/C+±》语言-》符合模式:否
6)C/C+±》所有选项-》SDL检查:否
配置PCL 1.12.1
(1)打开属性管理器:视图-》其他窗口-》属性管理器
2)Debug|x64-》添加新项目属性表
(3)项目属性命名
4)双击新建属性-》VC++目录-》包含目录
添加以下7个include路径:
C:\Program Files\PCL 1.12.1\include\pcl-1.13
C:\Program Files\PCL 1.12.1\3rdParty\Boost\include\boost-1_80
C:\Program Files\PCL 1.12.1\3rdParty\Eigen\eigen3
C:\Program Files\PCL 1.12.1\3rdParty\FLANN\include
C:\Program Files\PCL 1.12.1\3rdParty\Qhull\include
C:\Program Files\PCL 1.12.1\3rdParty\VTK\include\vtk-9.2
C:\Program Files\PCL 1.12.1\3rdParty\OpenNI2\Include
(5)VC++目录-》库目录
C:\Program Files\PCL 1.12.1\lib
C:\Program Files\PCL 1.12.1\3rdParty\Boost\lib
C:\Program Files\PCL 1.12.1\3rdParty\FLANN\lib
C:\Program Files\PCL 1.12.1\3rdParty\Qhull\lib
C:\Program Files\PCL 1.12.1\3rdParty\OpenNI2\Lib
C:\Program Files\PCL 1.12.1\3rdParty\VTK\lib
(6)C/C+±》预处理器-》预处理定义,增加如下定义
BOOST_USE_WINDOWS_H
NOMINMAX
_CRT_SECURE_NO_DEPRECATE
7)链接器-》输入-》附加依赖项-》编辑,添加lib文件
首先是PCL中的lib文件C:\Program Files\PCL 1.12.1\lib
和VTK中的lib文件C:\Program Files\PCL 1.12.1\3rdParty\VTK\lib这两个位置的lib文件。
每个文件都有对应release和debug两个模式的文件。我的是debug模式,选择d结尾的lib文件。VTK中的lib文件gd结尾的是debug模式。
如果不是1.12.1,那么lib文件可能有一点不一样,pcl前面部分的lib文件大多数是一样的,只有和VTK中的lib文件C:\Program Files\PCL 1.12.1\3rdParty\VTK\lib里面的文件相差较大可以用以下命令取出来。
首先新建文本文档,输入以下代码并且保存到\PCL 1.12.1\3rdParty\VTK\lib文件夹下面。同时在该文件夹下面新建三个文本文档。分别为all.txt adebug.txt arelease.txt
for %%I in (*.lib) do echo %%I>>all.txt
for %%I in (*d.lib) do echo %%I>>adebug.txt
for %%I in (*9.1.lib) do echo %%I>>arelease.txt
pause
修改文件名字扩展名字为bat格式,同时双击bat。
那么文件名字在相对的文件,debug以及release的lib文件。
pcl 1.12.1的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
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
(8)保存属性表
测试代码
#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);
}
结果
滚轮可以滚动方块。