Visual Studio 2022配置PCL1.12.1版本点云库

说明:这个配置步骤是当时自己参考2019配置的,当时网上还没有VS2022的配置步骤,我在自己电脑上是配置成功了,所以我将配置过程记录了下来,仅供参考!!!

1、软件下载

  • Microsoft Visual Studio 2022 Pro: https://visualstudio.microsoft.com/zh-hans/downloads/
  • PCL安装程序及pdb文件包:https://github.com/PointCloudLibrary/pcl/releases
    Visual Studio 2022配置PCL1.12.1版本点云库_第1张图片

2、配置系统环境变量

  • 系统属性->高级->环境变量->系统变量
C.\Program Files\PCL 1.12.1\bin
C:\Program Files\PCL 1.12.1\3rdParty\VTK\bin
C:\Program Files\PCL 1.12.1\3rdPartylQhull\bin
C:\Program Files\PCL 1.12.1\3rdParty\FLANNVbin
C\Program Files\OpenNI2\Tools

Visual Studio 2022配置PCL1.12.1版本点云库_第2张图片

  • OpenIN2也要加入系统变量
OPENNI2 INCLUDE64 C:\Program Files\OpenNl2\Include\
OPENNI2_LIB64 C:\Program Files\OpenNI2\Lib\
OPENNI2_REDIST64 C:\Program Files\OpenNl2\Redist\

Visual Studio 2022配置PCL1.12.1版本点云库_第3张图片

3、配置PDB文件

将下载得到的压缩包解压缩后将文件复制到PCL安装目录下bin文件夹:
Visual Studio 2022配置PCL1.12.1版本点云库_第4张图片

Visual Studio 2022配置PCL1.12.1版本点云库_第5张图片

4、配置PCL1.12.1

  1. 新建一个控制台应用,找到属性管理器,新建立一个项目属性表(目的:以后新建一个PCL项目文件直接调用配置好的属性表,一劳永逸)
    Visual Studio 2022配置PCL1.12.1版本点云库_第6张图片

  2. 打开属性表,配置VC++目录中的包含目录库目录

Visual Studio 2022配置PCL1.12.1版本点云库_第7张图片

包含目录:
C:\Program Files\PCL 1.12.1\3rdParty\Boost\include\boost-1_78
C:\Program Files\PCL 1.12.1\3rdParty\Eigen\eigen3
C:\Program Files\OpenNI2\Include
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.1
C:\Program Files\PCL 1.12.1\include\pcl-1.12

库目录:
C:\Program Files\OpenNI2\Lib
C:\Program Files\PCL 1.12.1\3rdParty\VTK\lib
C:\Program Files\PCL 1.12.1\3rdParty\Qhull\lib
C:\Program Files\PCL 1.12.1\3rdParty\FLANN\lib
C:\Program Files\PCL 1.12.1\3rdParty\Boost\lib
C:\Program Files\PCL 1.12.1\lib

  1. C/C++->常规预处理器配置:
    Visual Studio 2022配置PCL1.12.1版本点云库_第8张图片

常规:
C:\Program Files\PCL 1.12.1\3rdParty\Boost\include\boost-1_78\boost
预处理器:
_CRT_SECURE_NO_WARNINGS
_SCL_SECURE_NO_WARNINGS
_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING

  1. 链接器->输入->附加依赖项配置:在每个库目录中找到所需要的.lib文件,根据不同库目录下的.lib文件名,可以区分出debug模式和release模式各自的.lib文件,Debug版本含“gd”,可以区分出两个版本的库文件。
    Visual Studio 2022配置PCL1.12.1版本点云库_第9张图片

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
liblas.lib

5、测试

  • 数据: https://www.aliyundrive.com/s/3TRibmFSTtQ
#include
#include 
#include
#include
#include
#include
#include 
#include
#include 
using namespace std; //use  namespace "std"
using namespace pcl;  //use namesapce "pcl",引入这个命名空间后可以简化代码

#define  PI 3.141592653
//点云去噪
void pclMyFilter( string path)
{
	//点云指针类型对象,访问方式:cloud->point[i].x
	pcl::PCLPointCloud2::Ptr cloud(new pcl::PCLPointCloud2);//原始点云文件
	pcl::PCLPointCloud2::Ptr cloud_filtered(new pcl::PCLPointCloud2);//去噪后所生成的新的点云文件

	//输入点云数据
	pcl::PCDReader reader;
	reader.read(path, *cloud);
	//去噪之前点云数量统计
	cout << "pointcloud before filtering :" << cloud->width * cloud->height << "data points(" << pcl::getFieldsList(*cloud) << ")." << endl;

	//创建去噪 实例化一个对象  方法采用VoxelGrid
	pcl::VoxelGrid<pcl::PCLPointCloud2> vgd;
	//输入要处理的原始点云数据
	vgd.setInputCloud(cloud);
	//设置叶子大小
	vgd.setLeafSize(2.0f, 2.0f, 2.0f);
	vgd.filter(*cloud_filtered);
	//去噪后的点云数量统计
	cout << "pointcloud after filtering:" << cloud_filtered->width * cloud_filtered->height << "data points(" << pcl::getFieldsList(*cloud_filtered) << ")." << endl;


	//将去噪后的点云写入新的pcd文件中
	pcl::PCDWriter writer;
	writer.write("./data/samp12_quzao.pcd", *cloud_filtered, Eigen::Vector4f::Zero(), Eigen::Quaternionf::Identity(), false);
}

//可视化点云
int pclMyShow(string path)
{
	/*---------------------------加载点云-----------------------------
	* 1、创建点云对象
	* 2、判断并读取点云文件
	* 3、输出点云数量
	*/
	pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);  //使用PointXYZRGB类实例化一个对象cloud
	// PointCloud::Ptr cloud(new PointCloud);  //简化后的代码
	pcl::PCDReader pcdread;
	if (pcdread.read(path, *cloud) < 0)
	{
		PCL_ERROR("\a->点云文件不存在!\n");
		system("pause");
		return 1;
	}
	cout << "->加载了" << cloud->points.size() << "个数据点" << endl;


	//-------------------------Visualizer 可视化------------------------------
	pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Point Cloud Viewer"));  //创建视图对象,定义标题栏名称“3D Viewer”
	viewer->addPointCloud<pcl::PointXYZRGB>(cloud, "samp12_cloud"); //将点云添加到视图对象中,并定义一个唯一的ID

	pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZRGB> fildcolor(cloud, "z");//按照z字段进行渲染
	/****************注意此处ID不能与视图对象的ID值相同,否则会报错****************************/
	viewer->addPointCloud<pcl::PointXYZRGB>(cloud, fildcolor, "samp12cloud");


	/*下面的ID值应该与上面两个ID其中一个相同,即与dataset or fildcolor的ID相同,不能重新定义ID
	否则会报错"Could not find any PointCloud datasets with id !"*/

	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 4.5, "samp12cloud");//设置点云大小
	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 1, 0.5, 0.9, "samp12_cloud");//设置点云显示颜色,rgb颜色范围在0~1之间
	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_OPACITY, 0.8, "samp12cloud");//设置点云透明度
	viewer->setBackgroundColor(0, 0, 0);//窗口背景色,黑色
	viewer->addText("samp12", 20, 20, "text_1");//在指定位置添加文字

	//必选
	while (!viewer->wasStopped())
	{
		viewer->spinOnce(100);
		//boost::this_thread::sleep(boost::posix_time::microseconds(100000));
	}
}
int main()
{
	//pclMyFilter("./data/samp12.pcd");
	pclMyShow("./data/samp12.pcd");
	return 0;

}

Visual Studio 2022配置PCL1.12.1版本点云库_第10张图片

你可能感兴趣的:(点云PCL,visual,studio,c++,pcl)