这段时间自己配置了下环境以熟悉3D点云相关内容,配置过程及测试代码如下:
1. 安装vs2017 comminity版本
2. 下载PCL-1.8.1-AllInOne-msvc2017-win64.exe及pcl-1.8.1-pdb-msvc2017-win64.zip,如下是我上传的百度网盘路径:
链接:https://pan.baidu.com/s/1R6DZZ_DwmAoBNVdHvBIzHQ
提取码:lsyo
3. 下载完毕后先安装包PCL-1.8.1-AllInOne-msvc2017-win64.exe
4. C:\Program Files\PCL 1.8.1是我的安装目录,安装完毕后,打开C:\Program Files\PCL 1.8.1\3rdParty\OpenNI2文件夹:
安装此msi文件到C:\Program Files\PCL 1.8.1\3rdParty目录下,安装完毕后,文件夹内容如下:
5.查看系统变量,会发现多四个变量,如果有少的,可以自己手动配置下,按自己的实际路径来
OPENNI2_INCLUDE64、OPENNI2_LIB64、OPENNI2_REDIST64、PCL_ROOT
完毕后编辑环境变量,添加如下绿色框环境变量:
6. 解压pcl-1.8.1-pdb-msvc2017-win64.zip文件夹,将里面的pdb后缀文件拷贝至C:\Program Files\PCL 1.8.1\bin路径下
7. 新建一个C++控制台应用程序
切换到属性管理器,如下只配置debug,因为方便自己调程序,release版本依样画芦就是
如下新建一个名为PLC的属性表,好处是后面重新新建项目时不需要再手动添加引用路径了
打开PLC属性页,在VC++目录 包含目录下添加如下头文件:
C/C++ 常规项 SDL检查改为否(/sdl-)
预处理器添加如下:
_DEBUG
_CONSOLE
_CRT_SECURE_NO_WARNINGS
_CRT_SECURE_NO_DEPRECATE
链接器常规 附加库目录
链接器 输入 附件依赖项添加对应lib(Debug版本)
vtknetcdf_c++-gd.lib
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
opengl32.lib
OpenNI2.lib
8. 添加完毕后回到解决防范资源管理器
再次配置下该工程的属性,选择调试,在环境里添加如下路径:
path=C:\Program Files\PCL 1.8.1\bin;C:\Users\76764\Documents\opencv\build\x64\vc14\bin;C:\Program Files\PCL 1.8.1\3rdParty\Tools;C:\Program Files\PCL 1.8.1\3rdParty\VTK\bin
9. 运行如下代码,验证pcl是否配置成功
// test_vtk63.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <boost/thread/thread.hpp>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>//pcd 读写类相关的头文件。
#include <pcl/PCLPointCloud2.h>
#include <pcl/visualization/range_image_visualizer.h>
#include <pcl/visualization/pcl_visualizer.h>
using namespace pcl;
using namespace pcl::io;
using namespace std;
int testpointcloudToPcd()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
char strfilepath[256] = "D:\\rabbit.pcd";
//第一种读入方法较多场合如此
if (-1 == pcl::io::loadPCDFile(strfilepath, *cloud)) {
cout << "error input!" << endl;
return -1;
}
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("PointsCloud Recognition"));
viewer->addPointCloud(cloud, "model_cloud");
viewer->addCoordinateSystem(1.0);
viewer->initCameraParameters();
while (!viewer->wasStopped())
{
viewer->spinOnce(100);
boost::this_thread::sleep(boost::posix_time::microseconds(100000));
}
}
int _tmain(int argc, _TCHAR* argv[])
{
testpointcloudToPcd();
return 0;
}
结果如下,所用测试pcd点云文件见链接:
链接:https://pan.baidu.com/s/15NWqp60oju7irBR85Kl_Bg
提取码:0p5t
10. 由于pcl的第三方库包含了vtk,所以也验证下单独调用vtk来显示数据是否可行,由于如上的过程中已经把vtk的环境也都一起配置了(include、lib文件都有),运行如下代码:
// test_vtk63.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <map>
#include "vtkConeSource.h"
#include "vtkConeSource.h"
#include "vtkCommand.h"
#include "vtkCamera.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTransform.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include <vtkSmartPointer.h>
#include <vtkDoubleArray.h>
#include <vtkCellArray.h>
#include <vtkPolyData.h>
#include <vtkDataSet.h>
#include <vtkLookupTable.h>
#include <vtkPointData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkArcSource.h>
#include <vtkAppendPolyData.h>
#include <vtkScalarBarActor.h>
#include <vtkKdTree.h>
#include <vtkLODActor.h>
#include <vtkMath.h>
#include <vtkWindowToImageFilter.h>
#include <vtkBMPWriter.h>
#include <vtkAutoInit.h>
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <windef.h>
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkInteractionStyle);
void testvtk2()
{
//创建数据源:创建一个圆锥,并设置其参数:高度、底面半径和分辨率
vtkConeSource* cone = vtkConeSource::New();
cone->SetHeight(3.0);
cone->SetRadius(1.0);
cone->SetResolution(100);
//映射器:创建一个多边形映射器,用于把多边形数据映射为可以被计算机渲染的图元
vtkPolyDataMapper* coneMapper = vtkPolyDataMapper::New();
coneMapper->SetInputConnection(cone->GetOutputPort());
//创建一个Actor,并关联一个映射器,从而确定Actor的形状
vtkActor* coneActor = vtkActor::New();
coneActor->SetMapper(coneMapper);
//方法1:设置演员颜色
coneActor->GetProperty()->SetColor(1.0, 0.0, 0.0);//设置对象颜色为红色
//方法2:设置演员颜色
//vtkProperty* coneProperty = vtkProperty::New();//设置一个Property对象
//coneProperty->SetColor(1.0, 0.0, 0.0);
//coneActor->SetProperty(coneProperty);
//渲染器:创建一个渲染器,添加要渲染的演员
vtkRenderer* ren1 = vtkRenderer::New();
ren1->AddActor(coneActor);
ren1->SetBackground(0.1, 0.2, 0.4);
//渲染窗口:添加一个渲染窗口,供渲染器使用
vtkRenderWindow* renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
renWin->SetSize(300, 300);
//实例化一个交互对象
vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::New();//交互对象加入renWin窗口中
interactor->SetRenderWindow(renWin);
renWin->Render();//绘制舞台上的东西
interactor->Initialize();//交互对象初始化
interactor->Start();//开始交互事件
//释放内存
cone->Delete();
coneActor->Delete();
coneMapper->Delete();
ren1->Delete();
renWin->Delete();
interactor->Delete();
}
int _tmain(int argc, _TCHAR* argv[])
{
testvtk2();
return 0;
}
显示如下:
配置成功,接下来第二篇看如何在MFC及QT界面上显示点云