Qt 5.9使用VTK显示点云的详解详解
注意:
1.以下第一部分PCL安装使用教程可供参考,第二部分在VS中使用Qt亲测有效;第三第四部分有问题,希望通过这个教程了解如何使用Qt可视化点云的可能要失望了,如果你实现了还请不吝赐教。
2.目前我自己对于既使用Qt设计界面又能使用PCL库的做法是在VS中使用PCL库和Qt库,如果想可视化点云可能需要自己定义可视化类和控件了,最后我做到的话再补个教程。
3.基于VS中使用Qt库和PCL库生成的文件想要发布也跟一般的Qt程序相似,使用Qt自带的Qt命令行在exe文件目录下执行windeployqt *.exe命令即可配置好所需dll;也可以自己运行exe看缺什么dll并找到复制到当前文件夹下也一样。如果想进一步做成安装包,可使用setupfactory打包你的exe生成安装包,这个以后我熟悉了也加个教程。
1.PCL安装及在VS2013中使用PCL
(1)下载PCL,下载地址
链接: https://pan.baidu.com/s/1dDsWsXlv9ln_UngRXg_qZg?pwd=j13m 提取码: j13m
点击PCL-1.8.0-AllInOne-msvc2015-win32.exe安装即可。
(2)环境变量的配置。添加环境变量名称为:
PCL_ROOT,路径设为PCL的安装根目录。
path环境变量添加 %PCL_ROOT%\bin;%PCL_ROOT%\3rdParty\FLANN\bin;%PCL_ROOT%\3rdParty\Qhull\bin;%PCL_ROOT%\3rdParty\VTK\bin;%PCL_ROOT%\3rdParty\OpenNI2\Tools。
(3)项目属性配置。原本可以在项目-属性中设置属性,但是每一次都要设置未免太麻烦,所以这里打开安装包附带的PCLdebug.props和PCLrelease.props文件直接导入设置(如果没有的话新建项目属性表也可),打开方法为打开属性管理器,右键对应的解决方案平台添加现有属性表,然后Debug|Win32添加PCLdebug.props,Release|Win32添加PCLrelease.props即可。如下
这里添加的属性表并没有进行设置,所以其实自己新建属性表也是一样的,之后我们要双击添加的debug,release属性表分别进行设置最后进行保存即可在下一次直接添加这个属性表就可以,不必多次设置。双击属性表后在属性设置中点击配置属性-Vc++目录,在包含目录与库目录中分别添加如下目录,
在属性表-链接器-输入中的附加依赖项添加如下依赖项,如果为其他版本的只需把对应文件夹里的lib文件添加到依赖项即可,为快速导出这些lib文件名,可使用批处理命令导出,参考Https://www.jb51.net/article/256395.htm。
//debug模式下添加的附加依赖项:
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
libboost_atomic-vc120-mt-gd-1_59.lib
libboost_chrono-vc120-mt-gd-1_59.lib
libboost_container-vc120-mt-gd-1_59.lib
libboost_context-vc120-mt-gd-1_59.lib
libboost_coroutine-vc120-mt-gd-1_59.lib
libboost_date_time-vc120-mt-gd-1_59.lib
libboost_exception-vc120-mt-gd-1_59.lib
libboost_filesystem-vc120-mt-gd-1_59.lib
libboost_graph-vc120-mt-gd-1_59.lib
libboost_iOStreams-vc120-mt-gd-1_59.lib
libboost_locale-vc120-mt-gd-1_59.lib
libboost_log-vc120-mt-gd-1_59.lib
libboost_log_setup-vc120-mt-gd-1_59.lib
libboost_math_c99-vc120-mt-gd-1_59.lib
libboost_math_c99f-vc120-mt-gd-1_59.lib
libboost_math_c99l-vc120-mt-gd-1_59.lib
libboost_math_tr1-vc120-mt-gd-1_59.lib
libboost_math_tr1f-vc120-mt-gd-1_59.lib
libboost_math_tr1l-vc120-mt-gd-1_59.lib
libboost_mpi-vc120-mt-gd-1_59.lib
libboost_prg_exec_monitor-vc120-mt-gd-1_59.lib
libboost_program_options-vc120-mt-gd-1_59.lib
libboost_random-vc120-mt-gd-1_59.lib
libboost_regex-vc120-mt-gd-1_59.lib
libboost_serialization-vc120-mt-gd-1_59.lib
libboost_signals-vc120-mt-gd-1_59.lib
libboost_system-vc120-mt-gd-1_59.lib
libboost_test_exec_monitor-vc120-mt-gd-1_59.lib
libboost_thread-vc120-mt-gd-1_59.lib
libboost_timer-vc120-mt-gd-1_59.lib
libboost_unit_test_framework-vc120-mt-gd-1_59.lib
libboost_wave-vc120-mt-gd-1_59.lib
libboost_wserialization-vc120-mt-gd-1_59.lib
vtkalglib-7.0-gd.lib
vtkChartsCore-7.0-gd.lib
vtkCommonCore-7.0-gd.lib
vtkCommonColor-7.0-gd.lib
vtkCommonComputationalGeometry-7.0-gd.lib
vtkCommonDataModel-7.0-gd.lib
vtkCommonExecutionModel-7.0-gd.lib
vtkCommonMath-7.0-gd.lib
vtkCommonMisc-7.0-gd.lib
vtkCommonSystem-7.0-gd.lib
vtkCommonTransfORMs-7.0-gd.lib
vtkDICOMParser-7.0-gd.lib
vtkDomainsChemistry-7.0-gd.lib
vTKExoIIc-7.0-gd.lib
vtkexpat-7.0-gd.lib
vtkFiltersAMR-7.0-gd.lib
vtkFiltersCore-7.0-gd.lib
vtkFiltersExtraction-7.0-gd.lib
vtkFiltersFlowPaths-7.0-gd.lib
vtkFiltersGeneral-7.0-gd.lib
vtkFiltersGeneric-7.0-gd.lib
vtkFiltersGeometry-7.0-gd.lib
vtkFiltersHybrid-7.0-gd.lib
vtkFiltersHyperTree-7.0-gd.lib
vtkFiltersImaging-7.0-gd.lib
vtkFiltersModeling-7.0-gd.lib
vtkFiltersParallel-7.0-gd.lib
vtkFiltersParallelImaging-7.0-gd.lib
vtkFiltersProgrammable-7.0-gd.lib
vtkFiltersSelection-7.0-gd.lib
vtkFilterSSMP-7.0-gd.lib
vtkFiltersSources-7.0-gd.lib
vtkFiltersStatistics-7.0-gd.lib
vtkFiltersTexture-7.0-gd.lib
vtkFiltersVerdict-7.0-gd.lib
vtkfreetype-7.0-gd.lib
vtkGeovisCore-7.0-gd.lib
vtkhdf5-7.0-gd.lib
vtkhdf5_hl-7.0-gd.lib
vtkImaginGColor-7.0-gd.lib
vtkImagingCore-7.0-gd.lib
vtkImagingFourier-7.0-gd.lib
vtkImagingGeneral-7.0-gd.lib
vtkImagingHybrid-7.0-gd.lib
vtkImagingMath-7.0-gd.lib
vtkImagingMorphological-7.0-gd.lib
vtkImagingSources-7.0-gd.lib
vtkImagingStatistics-7.0-gd.lib
vtkImagingStencil-7.0-gd.lib
vtkInfovisCore-7.0-gd.lib
vtkInfovisLayout-7.0-gd.lib
vtkInteractionImage-7.0-gd.lib
vtkInteractionStyle-7.0-gd.lib
vtkInteractionWidgets-7.0-gd.lib
vtkIOAMR-7.0-gd.lib
vtkiocore-7.0-gd.lib
vtkIOEnSight-7.0-gd.lib
vtkIOExodus-7.0-gd.lib
vtkIOExport-7.0-gd.lib
vtkIOGeometry-7.0-gd.lib
vtkIOImage-7.0-gd.lib
vtkIOImport-7.0-gd.lib
vtkIOInfovis-7.0-gd.lib
vtkIOLegacy-7.0-gd.lib
vtkIOLSDyna-7.0-gd.lib
vtkIOMINC-7.0-gd.lib
vtkIOMovie-7.0-gd.lib
vtkIONetCDF-7.0-gd.lib
vtkIOParallel-7.0-gd.lib
vtkIOParallelXML-7.0-gd.lib
vtkIOPLY-7.0-gd.lib
vtkIOsql-7.0-gd.lib
vtkIOVideo-7.0-gd.lib
vtkIOXML-7.0-gd.lib
vtkIOXMLParser-7.0-gd.lib
vtkjpeg-7.0-gd.lib
vtkJSONcpp-7.0-gd.lib
vtklibxml2-7.0-gd.lib
vtkmetaio-7.0-gd.lib
vtkNetCDF-7.0-gd.lib
vtkNetCDF_cxx-7.0-gd.lib
vtkoggtheora-7.0-gd.lib
vtkParallelCore-7.0-gd.lib
vtkpng-7.0-gd.lib
vtkproj4-7.0-gd.lib
vtkRenderingAnnotation-7.0-gd.lib
vtkRenderingContext2D-7.0-gd.lib
vtkRenderingContextOpenGL2-7.0-gd.lib
vtkRenderingCore-7.0-gd.lib
vtkRenderingFreeType-7.0-gd.lib
vtkRenderingImage-7.0-gd.lib
vtkRenderingLabel-7.0-gd.lib
vtkRenderingLOD-7.0-gd.lib
vtkRenderinGopenGL2-7.0-gd.lib
vtkRenderingVolume-7.0-gd.lib
vtkRenderingVolumeOpenGL2-7.0-gd.lib
vtksqlite-7.0-gd.lib
vtksys-7.0-gd.lib
vtktiff-7.0-gd.lib
vtkverdict-7.0-gd.lib
vtkViewsContext2D-7.0-gd.lib
vtkViewsCore-7.0-gd.lib
vtkViewsInfovis-7.0-gd.lib
vtkzlib-7.0-gd.lib
vtkGUISupportQt-7.0-gd.lib
vtkRenderingQt-7.0-gd.lib
vtkViewsQt-7.0-gd.lib
flann_cpp_s-gd.lib
qhullstatic-gd.lib
OpenNI2.lib
//release模式下添加的附加依赖项:
pcl_common_release.lib
pcl_features_release.lib
pcl_filters_release.lib
pcl_io_release.lib
pcl_io_ply_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-vc120-mt-1_59.lib
libboost_chrono-vc120-mt-1_59.lib
libboost_container-vc120-mt-1_59.lib
libboost_context-vc120-mt-1_59.lib
libboost_coroutine-vc120-mt-1_59.lib
libboost_date_time-vc120-mt-1_59.lib
libboost_exception-vc120-mt-1_59.lib
libboost_filesystem-vc120-mt-1_59.lib
libboost_graph-vc120-mt-1_59.lib
libboost_iostreams-vc120-mt-1_59.lib
libboost_locale-vc120-mt-1_59.lib
libboost_log-vc120-mt-1_59.lib
libboost_log_setup-vc120-mt-1_59.lib
libboost_math_c99-vc120-mt-1_59.lib
libboost_math_c99f-vc120-mt-1_59.lib
libboost_math_c99l-vc120-mt-1_59.lib
libboost_math_tr1-vc120-mt-1_59.lib
libboost_math_tr1f-vc120-mt-1_59.lib
libboost_math_tr1l-vc120-mt-1_59.lib
libboost_mpi-vc120-mt-1_59.lib
libboost_prg_exec_monitor-vc120-mt-1_59.lib
libboost_program_options-vc120-mt-1_59.lib
libboost_random-vc120-mt-1_59.lib
libboost_regex-vc120-mt-1_59.lib
libboost_serialization-vc120-mt-1_59.lib
libboost_signals-vc120-mt-1_59.lib
libboost_system-vc120-mt-1_59.lib
libboost_test_exec_monitor-vc120-mt-1_59.lib
libboost_thread-vc120-mt-1_59.lib
libboost_timer-vc120-mt-1_59.lib
libboost_unit_test_framework-vc120-mt-1_59.lib
libboost_wave-vc120-mt-1_59.lib
libboost_wserialization-vc120-mt-1_59.lib
vtkalglib-7.0.lib
vtkChartsCore-7.0.lib
vtkCommonCore-7.0.lib
vtkCommonColor-7.0.lib
vtkCommonComputationalGeometry-7.0.lib
vtkCommonDataModel-7.0.lib
vtkCommonExecutionModel-7.0.lib
vtkCommonMath-7.0.lib
vtkCommonMisc-7.0.lib
vtkCommonSystem-7.0.lib
vtkCommonTransforms-7.0.lib
vtkDICOMParser-7.0.lib
vtkDomainsChemistry-7.0.lib
vtkexoIIc-7.0.lib
vtkexpat-7.0.lib
vtkFiltersAMR-7.0.lib
vtkFiltersCore-7.0.lib
vtkFiltersExtraction-7.0.lib
vtkFiltersFlowPaths-7.0.lib
vtkFiltersGeneral-7.0.lib
vtkFiltersGeneric-7.0.lib
vtkFiltersGeometry-7.0.lib
vtkFiltersHybrid-7.0.lib
vtkFiltersHyperTree-7.0.lib
vtkFiltersImaging-7.0.lib
vtkFiltersModeling-7.0.lib
vtkFiltersParallel-7.0.lib
vtkFiltersParallelImaging-7.0.lib
vtkFiltersProgrammable-7.0.lib
vtkFiltersSelection-7.0.lib
vtkFiltersSMP-7.0.lib
vtkFiltersSources-7.0.lib
vtkFiltersStatistics-7.0.lib
vtkFiltersTexture-7.0.lib
vtkFiltersVerdict-7.0.lib
vtkfreetype-7.0.lib
vtkGeovisCore-7.0.lib
vtkhdf5-7.0.lib
vtkhdf5_hl-7.0.lib
vtkImagingColor-7.0.lib
vtkImagingCore-7.0.lib
vtkImagingFourier-7.0.lib
vtkImagingGeneral-7.0.lib
vtkImagingHybrid-7.0.lib
vtkImagingMath-7.0.lib
vtkImagingMorphological-7.0.lib
vtkImagingSources-7.0.lib
vtkImagingStatistics-7.0.lib
vtkImagingStencil-7.0.lib
vtkInfovisCore-7.0.lib
vtkInfovisLayout-7.0.lib
vtkInteractionImage-7.0.lib
vtkInteractionStyle-7.0.lib
vtkInteractionWidgets-7.0.lib
vtkIOAMR-7.0.lib
vtkIOCore-7.0.lib
vtkIOEnSight-7.0.lib
vtkIOExodus-7.0.lib
vtkIOExport-7.0.lib
vtkIOGeometry-7.0.lib
vtkIOImage-7.0.lib
vtkIOImport-7.0.lib
vtkIOInfovis-7.0.lib
vtkIOLegacy-7.0.lib
vtkIOLSDyna-7.0.lib
vtkIOMINC-7.0.lib
vtkIOMovie-7.0.lib
vtkIONetCDF-7.0.lib
vtkIOParallel-7.0.lib
vtkIOParallelXML-7.0.lib
vtkIOPLY-7.0.lib
vtkIOSQL-7.0.lib
vtkIOVideo-7.0.lib
vtkIOXML-7.0.lib
vtkIOXMLParser-7.0.lib
vtkjpeg-7.0.lib
vtkjsoncpp-7.0.lib
vtklibxml2-7.0.lib
vtkmetaio-7.0.lib
vtkNetCDF-7.0.lib
vtkNetCDF_cxx-7.0.lib
vtkoggtheora-7.0.lib
vtkParallelCore-7.0.lib
vtkpng-7.0.lib
vtkproj4-7.0.lib
vtkRenderingAnnotation-7.0.lib
vtkRenderingContext2D-7.0.lib
vtkRenderingContextOpenGL2-7.0.lib
vtkRenderingCore-7.0.lib
vtkRenderingFreeType-7.0.lib
vtkRenderingImage-7.0.lib
vtkRenderingLabel-7.0.lib
vtkRenderingLOD-7.0.lib
vtkRenderingOpenGL2-7.0.lib
vtkRenderingVolume-7.0.lib
vtkRenderingVolumeOpenGL2-7.0.lib
vtksqlite-7.0.lib
vtksys-7.0.lib
vtktiff-7.0.lib
vtkverdict-7.0.lib
vtkViewsContext2D-7.0.lib
vtkViewsCore-7.0.lib
vtkViewsInfovis-7.0.lib
vtkzlib-7.0.lib
vtkGUISupportQt-7.0.lib
vtkRenderingQt-7.0.lib
vtkViewsQt-7.0.lib
flann_cpp_s.lib
qhullstatic.lib
OpenNI2.lib
编写测试代码,新建一个c++的win32控制台程序,更改代码如下:
#include "stdafx.h"
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
int user_data;
void viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
{
viewer.setBackgroundColor(1.0, 0.5, 1.0);
pcl::PointXYZ o;
o.x = 1.0;
o.y = 0;
o.z = 0;
viewer.addSphere(o, 0.25, "sphere", 0);
std::cout << "i only run once" << std::endl;
}
void viewerPsycho(pcl::visualization::PCLVisualizer& viewer)
{
static unsigned count = 0;
std::stringstream ss;
ss << "Once per viewer loop: " << count++;
viewer.removeShape("text", 0);
viewer.addText(ss.str(), 200, 300, "text", 0);
//FIXME: possible race condition here:
user_data++;
}
int _tmain(int argc, _TCHAR* argv[])
{
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile("example.pcd的位置", *cloud);
pcl::visualization::CloudViewer viewer("Cloud Viewer");
//blocks until the cloud is actually rendered
viewer.showCloud(cloud);
//use the following functions to get access to the underlying more advanced/powerful
//PCLVisualizer
//This will only get called once
viewer.runOnVisualizationThreadOnce(viewerOneOff);
//This will get called once per visualization iteration
viewer.runOnVisualizationThread(viewerPsycho);
while (!viewer.wasStopped())
{
//you can also do cool processing here
//FIXME: Note that this is running in a separate thread from viewerPsycho
//and you should guard against race conditions yourself...
user_data++;
}
return 0;
}
这时候运行一个测试程序很有可能会抛出error c4996错误,只需在项目-属性-C/C++-预处理器-预处理器定义中添加_SCL_SECURE_NO_WARNINGS就可以。
完成以上设置后别忘了保存属性表,右击属性表保存即可。经过以上步骤,运气好的话,PCL库就可以用了,运气不好只能出啥问题找度娘了。
2.Vs2013与Qt协同
在工具-拓展和更新-联机中搜索Qt可以找到Qt visual studio Tools,点击下载,然后安装即可。
安装完毕之后在界面菜单栏上会多一个Qt VS Tools菜单,点击Qt Options在Qt version中添加一项名称随意,路径设为Qt的安装目录下相应目录,即指定了Qt版本,这时候可以使用Qt了。
测试一下,现在在文件-新建-项目向导中已经有Qt的内容,可以选择Qt GUI Application,就可以开发带有GUI界面的Qt程序。
现在可以在VS中写代码,双击.ui文件可打开Qt Designer设计界面。
3.编译vtk
参考https://www.jb51.net/article/256422.htm。原地址讲解会更详细。
使用CMAKE配置VTK for Qt的编译环境,cmake版本为3.11.3,下载地址为https://cmake.org/download/。VTK使用版本为8.1.1,下载地址为https://www.vtk.org/download/。
下载VTK-8.1.1.zip和VTKData-8.1.1.zip于同一目录,解压到当前目录,二者会合并成一个文件夹,即编译源码所在目录。
打开cmake,选择源码目录和构建目录(构建目录自己建一个),点击configure。
选择visual studio 12 2013 win 32(对应版本的编译器,不然在Qt中没法使用)。
选择BUILD_EXAMPLES,BUUILD_SHARED_LIBS,BUILD_TESTING。
CMAKE_INSTALL_PREFIX选择VTK的安装目录。
选择VTK_Group_Qt。点击configure。
这里一般都会自动设置好。Qt5_DIR选择路径为F:/Qt/5.9.4/msvc2015_64/lib/cmake/Qt5。点击configure,configure done后点击generate。
Generate done后点击Open Project即可在VS2015中打开项目。选择ALL_BUILD右键生成,生成完毕后改为release再生成一次release版本。这个过程会比较长。
至此编译完成,将build/bin/release下的QVTKWidget.dll复制到Qt安装目录的plugins/designer下,这样打开Qt Designer就可以看到工具箱里有QVTKWidget控件了(在Qt Creator中是看不到的,在Qt Creator中使用QVTKWidget可以使用Widget代替,然后提升为QVTKWidget)。
4.在vs2013下使用vtk,Qt显示点云
目前无法使用QVTKWidget,在VS2015中可以使用Qt Designer拖动QVTKWidget设计界面,但是运行时会出现错误,debug模式下调试出现error LNK2019: 无法解析的外部符号错误,看起来貌似是加载dll文件时无法识别QVTKWidget中的函数;release模式下则报错fatal error C1083: 无法打开包括文件: “QVTKWidget.h,看起来是不能找到头文件,即使是在项目属性的VC++目录的包含目录中添加相应包含目录也不成,添加包含目录后debug与release模式下均显示error LNK2019。
而Qt下也不可使用QVTKWidget,Qt Creator中工具箱中没有QVTKWidget,虽可通过提升的方式使用QVTKWidget,但是运行的时候同样遇到问题。debug与release模式下都出现LNK 2019无法解析的外部符号问题,看起来貌似与visual studio中的报错是一样的。
到此这篇关于Qt 5.9使用VTK显示点云的文章就介绍到这了,更多相关Qt 5.9 VTK显示点云内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
相关文章