之前接触过一次vs(virual studio),是因为自己想要学习.net开发,后来因为别的项目就搁置了。近期男友的研究方向需要做点云滤波,需要用到vs,这也重新拿起来这方面知识。下面,我将讲述一下如果在vs2019中配置pcl1.9.1,同时实现点云数据的可视化。
工具下载:
(1)visual studio的下载和安装:安装 visual studio 2019 Community版即可;链接:visual studio官网下载地址
(2)pcl 1.9.1的下载和安装:具体的安装可以参考百度教程,链接:github上的pcl下载资源
配置过程:
(1)电脑系统中配置环境变量,在安装pcl的时候因为选择了“Add PCL to the system PATH for all users”,所以在控制面板-系统-高级系统设置-环境变量中就会有一下四个环境变量的自动生成,如果没有,请自行添加:
(2)在Path中新建相关pcl的配置信息:
具体内容:
%PCL_ROOT%\bin;
%PCL_ROOT%\3rdParty\VTK\bin;
%PCL_ROOT%\3rdParty\FLANN\bin;
%PCL_ROOT%\3rdParty\Qhull\bin;
%OPENNI2_REDIST64%;
%PCL_ROOT%\3rdParty\OpenNI2\Tools;
%PCL_ROOT%\3rdParty\Boost\lib
!!!一定要注意配置完之后需要注销或者重启电脑才可以生效哦,要不在之后的配置项目中会因为无效而报错。
(3)在vs中新建c++控制台应用的项目:
(4)新建空项目完成之后,编译环境选择x64 Debug:
(5)配置Debug模式,打开项目-属性,进入VC++目录,点击“包含目录”,进行编辑:
新加入以下7项目录,具体pcl地址根据自己的安装位置进行调整:
具体内容:
D:\Download\PCL 1.9.1\3rdParty\Boost\include\boost-1_68
D:\Download\PCL 1.9.1\3rdParty\Eigen\eigen3
D:\Download\PCL 1.9.1\3rdParty\FLANN\include
D:\Download\PCL 1.9.1\3rdParty\Qhull\include
D:\Download\PCL 1.9.1\3rdParty\VTK\include\vtk-8.1
D:\Download\PCL 1.9.1\include\pcl-1.9
D:\Download\PCL 1.9.1\3rdParty\OpenNI2\Include
(6)进入VC++目录,点击“库目录”,进行编辑,添加以下内容:
具体内容:
D:\Download\PCL 1.9.1\3rdParty\OpenNI2\Lib
D:\Download\PCL 1.9.1\3rdParty\VTK\lib
D:\Download\PCL 1.9.1\3rdParty\Qhull\lib
D:\Download\PCL 1.9.1\3rdParty\FLANN\lib
D:\Download\PCL 1.9.1\3rdParty\Boost\lib
D:\Download\PCL 1.9.1\lib
(7)将C/C+±所有选项-SDL检查改为否:
(8)将C/C+±预处理器-预处理器定义,点击下拉框进行编辑,增加以下内容:
具体内容:
_SCL_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS
(9)打开项目-属性,进入链接器下的输入,点击附加依赖项进行编辑,新增对应的.lib文件(PCL的和VTK的):
具体内容:
pcl_common_debug.lib
pcl_features_debug.lib
pcl_filters_debug.lib
pcl_io_debug.lib
pcl_io_ply_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
vtkalglib-8.1-gd.lib
vtkChartsCore-8.1-gd.lib
vtkCommonColor-8.1-gd.lib
vtkCommonComputationalGeometry-8.1-gd.lib
vtkCommonCore-8.1-gd.lib
vtkCommonDataModel-8.1-gd.lib
vtkCommonExecutionModel-8.1-gd.lib
vtkCommonMath-8.1-gd.lib
vtkCommonMisc-8.1-gd.lib
vtkCommonSystem-8.1-gd.lib
vtkCommonTransforms-8.1-gd.lib
vtkDICOMParser-8.1-gd.lib
vtkDomainsChemistry-8.1-gd.lib
vtkexoIIc-8.1-gd.lib
vtkexpat-8.1-gd.lib
vtkFiltersAMR-8.1-gd.lib
vtkFiltersCore-8.1-gd.lib
vtkFiltersExtraction-8.1-gd.lib
vtkFiltersFlowPaths-8.1-gd.lib
vtkFiltersGeneral-8.1-gd.lib
vtkFiltersGeneric-8.1-gd.lib
vtkFiltersGeometry-8.1-gd.lib
vtkFiltersHybrid-8.1-gd.lib
vtkFiltersHyperTree-8.1-gd.lib
vtkFiltersImaging-8.1-gd.lib
vtkFiltersModeling-8.1-gd.lib
vtkFiltersParallel-8.1-gd.lib
vtkFiltersParallelImaging-8.1-gd.lib
vtkFiltersPoints-8.1-gd.lib
vtkFiltersProgrammable-8.1-gd.lib
vtkFiltersSelection-8.1-gd.lib
vtkFiltersSMP-8.1-gd.lib
vtkFiltersSources-8.1-gd.lib
vtkFiltersStatistics-8.1-gd.lib
vtkFiltersTexture-8.1-gd.lib
vtkFiltersTopology-8.1-gd.lib
vtkFiltersVerdict-8.1-gd.lib
vtkfreetype-8.1-gd.lib
vtkGeovisCore-8.1-gd.lib
vtkgl2ps-8.1-gd.lib
vtkhdf5-8.1-gd.lib
vtkhdf5_hl-8.1-gd.lib
vtkImagingColor-8.1-gd.lib
vtkImagingCore-8.1-gd.lib
vtkImagingFourier-8.1-gd.lib
vtkImagingGeneral-8.1-gd.lib
vtkImagingHybrid-8.1-gd.lib
vtkImagingMath-8.1-gd.lib
vtkImagingMorphological-8.1-gd.lib
vtkImagingSources-8.1-gd.lib
vtkImagingStatistics-8.1-gd.lib
vtkImagingStencil-8.1-gd.lib
vtkInfovisCore-8.1-gd.lib
vtkInfovisLayout-8.1-gd.lib
vtkInteractionImage-8.1-gd.lib
vtkInteractionStyle-8.1-gd.lib
vtkInteractionWidgets-8.1-gd.lib
vtkIOAMR-8.1-gd.lib
vtkIOCore-8.1-gd.lib
vtkIOEnSight-8.1-gd.lib
vtkIOExodus-8.1-gd.lib
vtkIOExport-8.1-gd.lib
vtkIOExportOpenGL-8.1-gd.lib
vtkIOGeometry-8.1-gd.lib
vtkIOImage-8.1-gd.lib
vtkIOImport-8.1-gd.lib
vtkIOInfovis-8.1-gd.lib
vtkIOLegacy-8.1-gd.lib
vtkIOLSDyna-8.1-gd.lib
vtkIOMINC-8.1-gd.lib
vtkIOMovie-8.1-gd.lib
vtkIONetCDF-8.1-gd.lib
vtkIOParallel-8.1-gd.lib
vtkIOParallelXML-8.1-gd.lib
vtkIOPLY-8.1-gd.lib
vtkIOSQL-8.1-gd.lib
vtkIOTecplotTable-8.1-gd.lib
vtkIOVideo-8.1-gd.lib
vtkIOXML-8.1-gd.lib
vtkIOXMLParser-8.1-gd.lib
vtkjpeg-8.1-gd.lib
vtkjsoncpp-8.1-gd.lib
vtklibharu-8.1-gd.lib
vtklibxml2-8.1-gd.lib
vtklz4-8.1-gd.lib
vtkmetaio-8.1-gd.lib
vtkNetCDF-8.1-gd.lib
vtknetcdfcpp-8.1-gd.lib
vtkoggtheora-8.1-gd.lib
vtkParallelCore-8.1-gd.lib
vtkpng-8.1-gd.lib
vtkproj4-8.1-gd.lib
vtkRenderingAnnotation-8.1-gd.lib
vtkRenderingContext2D-8.1-gd.lib
vtkRenderingContextOpenGL-8.1-gd.lib
vtkRenderingCore-8.1-gd.lib
vtkRenderingFreeType-8.1-gd.lib
vtkRenderingGL2PS-8.1-gd.lib
vtkRenderingImage-8.1-gd.lib
vtkRenderingLabel-8.1-gd.lib
vtkRenderingLIC-8.1-gd.lib
vtkRenderingLOD-8.1-gd.lib
vtkRenderingOpenGL-8.1-gd.lib
vtkRenderingVolume-8.1-gd.lib
vtkRenderingVolumeOpenGL-8.1-gd.lib
vtksqlite-8.1-gd.lib
vtksys-8.1-gd.lib
vtktiff-8.1-gd.lib
vtkverdict-8.1-gd.lib
vtkViewsContext2D-8.1-gd.lib
vtkViewsCore-8.1-gd.lib
vtkViewsInfovis-8.1-gd.lib
vtkzlib-8.1-gd.lib
(10)到此,点云开发环境就配置好啦,可以参考网上使用CloudViewer进行可视化的代码,如下:
具体代码:
// ConsoleApplication1.cpp : 此文件包含 “main” 函数。程序执行将在此处开始并结束。
#include “test1.h”
//程序中处理有关错误信息
#if (_MSC_VER >= 1915)
#define no_init_all deprecated
#endif
#pragma warning(disable: 4996)
#include<pcl/visualization/cloud_viewer.h> //类CloudViewer头文件声明
#include//标准C++库中的输入输出类相关头文件
#include<pcl/io/io.h>//io相关头文件声明
#include<pcl/io/pcd_io.h>//pcd 读写类相关的头文件
#include<pcl/io/ply_io.h>
#include<pcl/point_types.h> //PCL中支持的点类型头文件
int user_data;
using std::cout;
//回调函数:在主函数中注册后只执行一次,函数具体实现可视化对象功能
void viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
{
viewer.setBackgroundColor(1.0, 0.5, 1.0); //设置背景颜色
}
int main()
{
//创建点云对象
pcl::PointCloudpcl::PointXYZ::Ptr cloud(new pcl::PointCloudpcl::PointXYZ);
//加载点云文件
char strfilepath[256] = “rabbit.pcd”;
//判断输入的点云文件是否有效
if (-1 == pcl::io::loadPCDFile(strfilepath, *cloud)) {
cout << “error input!” << endl;
return -1;
}
//输出点的数量
cout << cloud->points.size() << endl;
//创建viewer对象
pcl::visualization::CloudViewer viewer(“Cloud Viewer”);
//调用库内的渲染函数,同步显示
viewer.showCloud(cloud);
//调用回调函数,注册一次,可视化对象
viewer.runOnVisualizationThreadOnce(viewerOneOff);
//保证操作系统暂停当前进程的执行,即冻结屏幕,留下展示
system(“pause”);
return 0;
}
点击运行,可以得到三维的兔子图像: