本文系转载,如侵权请告知删除。原博文链接:https://blog.csdn.net/jepco1/article/details/80752954
0 编译环境
所需软件包及其版本
Qt5.9.6 msvc2015_64
VS2015
VTK 8.0.0 https://gitlab.kitware.com/vtk/vtk/tree/v8.0.0
PCL1.8.1 https://github.com/PointCloudLibrary/pcl/releases/tag/pcl-1.8.1
PCL-1.8.1-AllInOne-msvc2015-win64
cmake3.11.3 https://cmake.org/download/
1 前期准备
下载上述软件。
安装vs2015。
安装Qt5.9.6。
在VS2015扩展和更新中安装 Qt Visual Studio Tools。
2 在VS中安装PCL 1.8.1
需要下载AllinOne和pdb两个包,我选择的是2015-win64版本。
自动在环境变量中添加PCL路径
PCL安装路径,网上说路径不能有空格。
将OpenNI2安装到PCL1.8.1\3rdParty\OpenNI2\目录,这是为了便于管理,可以选择自己喜欢的目录。修改也很方便,OpenNI2可以单独卸载安装。安装包就在PCL1.8.1\3rdParty\OpenNI2\目录。
2.2 编译tutorials
tutorials的路径在C:\PCL1.8.1\share\doc\pcl-1.8\tutorials\sources下。
所以首先用cmake进行配置,配置完成后,DAVID和PKG都提示找不到,如果不用就不管。我用到了RSSDK,所以加上了。
选择Generate,我选择的是Visual Studio 14 2015 Win64。
选择open project后,vs2015就会打开工程。直接生成,结束后会有一些错误,比如:
无法打开 源 文件 “pcl/io/openni_grabber.h”
2.3 运行PCL VS2015 demo
将pcl_visualizer_demo设为启动项。
设置命行参数为-c,
启动后看到如图效果。说明PCL库+VS已经OK。
3 在Qt中安装PCL 1.8.1
在Qt中安装PCL1.8.1必须先做到本文第2部分。
PCL1.8.1中集成了VTK8.0.0,但是和VTK官网的8.0.0在个别文件上有差异,这就导致了在QT工程中集成PCL会出一些问题,比如找不到函数,debug和release版本冲突等问题。一些常用的解决办法,如
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
并不能解决这些问题,所以解决思路是用VTK官方提供的8.0.0替换掉PCL_AllinOne中的VTK。
3.1 下载并编译VTK8.0.0
点击下载已经编译好的VTK8.0.0库,可跳过3.1。https://download.csdn.net/download/jepco1/10489293
具体方法参考博客中另一篇帖子VTK8.1.1的编译方法。
同样需要编译debug和release版本。
编译的结果被放在install目录和build目录。
build目录在这里被指定。
install目录在这里被指定。
3.2 安装及配置
生成的编译结果和路径如表
include VTK_INSTALLL\include
lib VTK_build\lib
dll VTK_build\bin
plugin VTK_build\bin\Release\QVTKWidgetPlugin.dll
lib和dll都是区分debug和release的。
替换bin
将VTK_build\bin的debug和release文件夹复制到C:\PCL1.8.1\3rdParty\VTK\bin
替换lib
将VTK_build\lib的debug和release复制到C:\PCL1.8.1\3rdParty\VTK\lib
替换include
删除C:\PCL1.8.1\3rdParty\VTK\include目录的文件。
将VTK_Install\include目录的内容复制到C:\PCL1.8.1\3rdParty\VTK\include
安装plugin
VTK_build\bin\Release\QVTKWidgetPlugin.dll文件复制到qt的插件目录
3.3 设置环境变量
PCL自动添加的环境变量不一定正确完整,建议检查一下。
PCL_ROOT存在且位置正确。
4个bin文件存在,且位置正确。
注意:这里要将VTK\bin路径删除。因为PCL中的VTK dll没有区分release和debug版本。需要通过编译器的环境配置,通过路径区分版本,这里如果包含了VTK\bin路径就会形成干扰。
4 编译qt_visualizer
4.1 打开qt_visualizer
位于C:\PCL1.8.1\share\doc\pcl-1.8\tutorials\sources\qt_visualizer
4.2 配置环境变量(dll路径)
debug
PATH=KaTeX parse error: Undefined control sequence: \bin at position 8: (QTDIR)\̲b̲i̲n̲(PATH)KaTeX parse error: Undefined control sequence: \3 at position 11: (PCL_ROOT)\̲3̲rdParty\VTK\bin…(QTDIR)\bin
(
P
A
T
H
)
(PATH)
(PATH)(PCL_ROOT)\3rdParty\VTK\bin\release
4.3 配置include(.h路径)
debug|release
.\GeneratedFiles$(ConfigurationName);
.\GeneratedFiles;
$(QTDIR)\include;
$(QTDIR)\include\QtWidgets;
$(QTDIR)\include\QtGui;
$(QTDIR)\include\QtANGLE;
$(QTDIR)\include\QtCore;
debug;
$(QTDIR)\mkspecs\win32-msvc;
$(PCL_ROOT)\include\pcl-1.8;
$(PCL_ROOT)\include\pcl-1.8\pcl;
$(PCL_ROOT)\3rdParty\Boost\include\boost-1_64;
$(PCL_ROOT)\3rdParty\Eigen\eigen3;
$(PCL_ROOT)\3rdParty\FLANN\include;
$(PCL_ROOT)\3rdParty\OpenNI2\Include\Win32;
$(PCL_ROOT)\3rdParty\Qhull\include;
$(PCL_ROOT)\3rdParty\VTK\include\vtk-8.0;
%(AdditionalIncludeDirectories)
4.4 配置lib路径
debug
$(QTDIR)\lib;
$(PCL_ROOT)\lib;
$(PCL_ROOT)\3rdParty\FLANN\lib;
$(PCL_ROOT)\3rdParty\Boost\lib;
$(PCL_ROOT)\3rdParty\Qhull\lib;
$(PCL_ROOT)\3rdParty\VTK\lib\debug;
$(PCL_ROOT)\3rdParty\OpenNI2\Lib;
%(AdditionalLibraryDirectories)
release
$(QTDIR)\lib;
$(PCL_ROOT)\lib;
$(PCL_ROOT)\3rdParty\FLANN\lib;
$(PCL_ROOT)\3rdParty\Boost\lib;
$(PCL_ROOT)\3rdParty\Qhull\lib;
$(PCL_ROOT)\3rdParty\VTK\lib\release;
$(PCL_ROOT)\3rdParty\OpenNI2\Lib;
%(AdditionalLibraryDirectories)
4.5 配置lib文件
debug
qtmaind.lib
shell32.lib
Qt5Widgetsd.lib
Qt5Guid.lib
Qt5Cored.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-vc140-mt-gd-1_64.lib
libboost_bzip2-vc140-mt-gd-1_64.lib
libboost_chrono-vc140-mt-gd-1_64.lib
libboost_container-vc140-mt-gd-1_64.lib
libboost_context-vc140-mt-gd-1_64.lib
libboost_coroutine-vc140-mt-gd-1_64.lib
libboost_date_time-vc140-mt-gd-1_64.lib
libboost_exception-vc140-mt-gd-1_64.lib
libboost_fiber-vc140-mt-gd-1_64.lib
libboost_filesystem-vc140-mt-gd-1_64.lib
libboost_graph-vc140-mt-gd-1_64.lib
libboost_graph_parallel-vc140-mt-gd-1_64.lib
libboost_iostreams-vc140-mt-gd-1_64.lib
libboost_locale-vc140-mt-gd-1_64.lib
libboost_log-vc140-mt-gd-1_64.lib
libboost_log_setup-vc140-mt-gd-1_64.lib
libboost_math_c99-vc140-mt-gd-1_64.lib
libboost_math_c99f-vc140-mt-gd-1_64.lib
libboost_math_c99l-vc140-mt-gd-1_64.lib
libboost_math_tr1-vc140-mt-gd-1_64.lib
libboost_math_tr1f-vc140-mt-gd-1_64.lib
libboost_math_tr1l-vc140-mt-gd-1_64.lib
libboost_mpi-vc140-mt-gd-1_64.lib
libboost_numpy3-vc140-mt-gd-1_64.lib
libboost_numpy-vc140-mt-gd-1_64.lib
libboost_prg_exec_monitor-vc140-mt-gd-1_64.lib
libboost_program_options-vc140-mt-gd-1_64.lib
libboost_python3-vc140-mt-gd-1_64.lib
libboost_python-vc140-mt-gd-1_64.lib
libboost_random-vc140-mt-gd-1_64.lib
libboost_regex-vc140-mt-gd-1_64.lib
libboost_serialization-vc140-mt-gd-1_64.lib
libboost_signals-vc140-mt-gd-1_64.lib
libboost_system-vc140-mt-gd-1_64.lib
libboost_test_exec_monitor-vc140-mt-gd-1_64.lib
libboost_thread-vc140-mt-gd-1_64.lib
libboost_timer-vc140-mt-gd-1_64.lib
libboost_type_erasure-vc140-mt-gd-1_64.lib
libboost_unit_test_framework-vc140-mt-gd-1_64.lib
libboost_wave-vc140-mt-gd-1_64.lib
libboost_wserialization-vc140-mt-gd-1_64.lib
libboost_zlib-vc140-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
vtkGUISupportQt-8.0.lib
vtkRenderingOpenGL2-8.0.lib
vtkglew-8.0.lib
vtkInteractionImage-8.0.lib
vtkInteractionWidgets-8.0.lib
vtkFiltersHybrid-8.0.lib
vtkFiltersModeling-8.0.lib
vtkImagingGeneral-8.0.lib
vtkImagingHybrid-8.0.lib
vtkRenderingAnnotation-8.0.lib
vtkRenderingFreeType-8.0.lib
vtkfreetype-8.0.lib
vtkRenderingVolume-8.0.lib
vtkIOXML-8.0.lib
vtkIOXMLParser-8.0.lib
vtkexpat-8.0.lib
vtkInteractionStyle-8.0.lib
vtkFiltersExtraction-8.0.lib
vtkFiltersStatistics-8.0.lib
vtkImagingFourier-8.0.lib
vtkalglib-8.0.lib
vtkImagingSources-8.0.lib
vtkIOImage-8.0.lib
vtkDICOMParser-8.0.lib
vtkmetaio-8.0.lib
vtkpng-8.0.lib
vtktiff-8.0.lib
vtkjpeg-8.0.lib
vtkImagingColor-8.0.lib
vtkImagingCore-8.0.lib
vtkRenderingCore-8.0.lib
vtkFiltersSources-8.0.lib
vtkFiltersGeneral-8.0.lib
vtkCommonComputationalGeometry-8.0.lib
vtkCommonColor-8.0.lib
vtkFiltersGeometry-8.0.lib
vtkFiltersCore-8.0.lib
vtkIOCore-8.0.lib
vtkCommonExecutionModel-8.0.lib
vtkCommonDataModel-8.0.lib
vtkCommonTransforms-8.0.lib
vtkCommonMisc-8.0.lib
vtkCommonMath-8.0.lib
vtkCommonSystem-8.0.lib
vtkCommonCore-8.0.lib
vtksys-8.0.lib
release
qtmain.lib
shell32.lib
Qt5Widgets.lib
Qt5Gui.lib
Qt5Core.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
libboost_atomic-vc140-mt-1_64.lib
libboost_bzip2-vc140-mt-1_64.lib
libboost_chrono-vc140-mt-1_64.lib
libboost_container-vc140-mt-1_64.lib
libboost_context-vc140-mt-1_64.lib
libboost_coroutine-vc140-mt-1_64.lib
libboost_date_time-vc140-mt-1_64.lib
libboost_exception-vc140-mt-1_64.lib
libboost_fiber-vc140-mt-1_64.lib
libboost_filesystem-vc140-mt-1_64.lib
libboost_graph-vc140-mt-1_64.lib
libboost_graph_parallel-vc140-mt-1_64.lib
libboost_iostreams-vc140-mt-1_64.lib
libboost_locale-vc140-mt-1_64.lib
libboost_log-vc140-mt-1_64.lib
libboost_log_setup-vc140-mt-1_64.lib
libboost_math_c99-vc140-mt-1_64.lib
libboost_math_c99f-vc140-mt-1_64.lib
libboost_math_c99l-vc140-mt-1_64.lib
libboost_math_tr1-vc140-mt-1_64.lib
libboost_math_tr1f-vc140-mt-1_64.lib
libboost_math_tr1l-vc140-mt-1_64.lib
libboost_mpi-vc140-mt-1_64.lib
libboost_numpy3-vc140-mt-1_64.lib
libboost_numpy-vc140-mt-1_64.lib
libboost_prg_exec_monitor-vc140-mt-1_64.lib
libboost_program_options-vc140-mt-1_64.lib
libboost_python3-vc140-mt-1_64.lib
libboost_python-vc140-mt-1_64.lib
libboost_random-vc140-mt-1_64.lib
libboost_regex-vc140-mt-1_64.lib
libboost_serialization-vc140-mt-1_64.lib
libboost_signals-vc140-mt-1_64.lib
libboost_system-vc140-mt-1_64.lib
libboost_test_exec_monitor-vc140-mt-1_64.lib
libboost_thread-vc140-mt-1_64.lib
libboost_timer-vc140-mt-1_64.lib
libboost_type_erasure-vc140-mt-1_64.lib
libboost_unit_test_framework-vc140-mt-1_64.lib
libboost_wave-vc140-mt-1_64.lib
libboost_wserialization-vc140-mt-1_64.lib
libboost_zlib-vc140-mt-1_64.lib
flann.lib
flann_cpp.lib
flann_cpp_s.lib
flann_s.lib
qhull_d.lib
qhullcpp_d.lib
qhullstatic_d.lib
qhullstatic_r_d.lib
qhull_p_d.lib
qhull_r_d.lib
vtkGUISupportQt-8.0.lib
vtkRenderingOpenGL2-8.0.lib
vtkglew-8.0.lib
vtkInteractionImage-8.0.lib
vtkInteractionWidgets-8.0.lib
vtkFiltersHybrid-8.0.lib
vtkFiltersModeling-8.0.lib
vtkImagingGeneral-8.0.lib
vtkImagingHybrid-8.0.lib
vtkRenderingAnnotation-8.0.lib
vtkRenderingFreeType-8.0.lib
vtkfreetype-8.0.lib
vtkRenderingVolume-8.0.lib
vtkIOXML-8.0.lib
vtkIOXMLParser-8.0.lib
vtkexpat-8.0.lib
vtkInteractionStyle-8.0.lib
vtkFiltersExtraction-8.0.lib
vtkFiltersStatistics-8.0.lib
vtkImagingFourier-8.0.lib
vtkalglib-8.0.lib
vtkImagingSources-8.0.lib
vtkIOImage-8.0.lib
vtkDICOMParser-8.0.lib
vtkmetaio-8.0.lib
vtkpng-8.0.lib
vtktiff-8.0.lib
vtkjpeg-8.0.lib
vtkImagingColor-8.0.lib
vtkImagingCore-8.0.lib
vtkRenderingCore-8.0.lib
vtkFiltersSources-8.0.lib
vtkFiltersGeneral-8.0.lib
vtkCommonComputationalGeometry-8.0.lib
vtkCommonColor-8.0.lib
vtkFiltersGeometry-8.0.lib
vtkFiltersCore-8.0.lib
vtkIOCore-8.0.lib
vtkCommonExecutionModel-8.0.lib
vtkCommonDataModel-8.0.lib
vtkCommonTransforms-8.0.lib
vtkCommonMisc-8.0.lib
vtkCommonMath-8.0.lib
vtkCommonSystem-8.0.lib
vtkCommonCore-8.0.lib
vtksys-8.0.lib
4.6 修改代码
在pclviewer.h中添加如下代码
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);