3D点云之PCL学习之路(一)
序
由于種種原因,又要進行3D點云的相關開發任務。對比了PCL和Open3D,針對應用的具體環境,最后還是決定基于PCL進行開發。如果覺得有所幫助,歡迎各位轉發收藏~
首先進行開發環境的搭建(如果對于環境搭建配置已經非常熟練,建議查看下一章節)。
軟件環境:Win10,MSVC2019,QT6.4.0,PCL1.12.1。
一.PCL安裝與配置
應用2019可以使用PCL-1.12.1-AllInOne-msvc2019-win64.exe.這樣可方便3rdParty的使用。PCL1.12.1下載:https://github.com/PointCloudLibrary/pcl/releases.安裝過程直接進行下一步,進行即可。不建議安裝到program files,也不要安裝在含有中文路徑下,這樣后期使用QT的時候會比較舒適。安裝完值后查看3rdParty\OpenNI2,看一下這個有沒有安裝上,沒安裝上直接運行.exe就可以了,建議安裝到3rdParty\OpenNI2,后期使用起來也比較舒適。(注,有的時候會生成找不到 OpenNI2.dll 的錯誤,可以直接把這個復制到生成的工程目錄.exe下即可。)
1.系統環境的配置:
?點擊path,編輯環境變量
?一切妥當后,注銷(重啟)一下電腦,使得環境變量生效。
2.工程環境的配置
利用msvc2019新建工程,選擇項目->(項目名稱)屬性
修改包含目錄和庫目錄的內容
?包含目錄:
C:\3DApp\PCL1.12.1\include\pcl-1.12
C:\3DApp\PCL1.12.1\3rdParty\Boost\include\boost-1_78
C:\3DApp\PCL1.12.1\3rdParty\Eigen\eigen3
C:\3DApp\PCL1.12.1\3rdParty\FLANN\include
C:\3DApp\PCL1.12.1\3rdParty\OpenNI2\Include
C:\3DApp\PCL1.12.1\3rdParty\Qhull\include
C:\3DApp\PCL1.12.1\3rdParty\VTK\include\vtk-9.1
庫目錄:
C:\3DApp\PCL1.12.1\lib
C:\3DApp\PCL1.12.1\3rdParty\Boost\lib
C:\3DApp\PCL1.12.1\3rdParty\FLANN\lib
C:\3DApp\PCL1.12.1\3rdParty\OpenNI2\Lib
C:\3DApp\PCL1.12.1\3rdParty\Qhull\lib
C:\3DApp\PCL1.12.1\3rdParty\VTK\lib
?再選擇連接器->庫目錄->附加依賴項,添加如下內容(debug)
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
release模式基本一樣(就是lib去掉了d)
配置好以上內容,就可以進行一個簡單的PCL的載入與展示了。
#define _SCL_SECURE_NO_WARNINGS #ifndef _CRT_SECURE_NO_WARNINGS #include <pcl/point_types.h>? #include <pcl/ModelCoefficients.h> ? #include <pcl/filters/project_inliers.h>? #include <pcl/io/pcd_io.h> ? #include <pcl/io/ply_io.h> #include <pcl/point_cloud.h> #include <pcl/console/parse.h> #include <pcl/common/transforms.h> #include <pcl/visualization/pcl_visualizer.h> #include <pcl/point_types.h> #include <iostream>? #include <vector> #include <memory> #include <string> #include "vtkAutoInit.h" #include <vtkOutputWindow.h> int main() {vtkOutputWindow::GlobalWarningDisplayOff();?? ?//vtkOutputWindow::SetGlobalWarningDisplay(0);?pcl::PointCloud<pcl::PointXYZ>::Ptr source_cloud(new pcl::PointCloud<pcl::PointXYZ>());if (pcl::io::loadPLYFile("c:\\fragment.ply", *source_cloud) == -1){PCL_ERROR("Couldn't read fragment.ply\n");return -1;}pcl::visualization::PCLVisualizer viewer("Matrix transformation example");pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> source_cloud_color_handler(source_cloud, 255, 255, 255);viewer.addPointCloud(source_cloud, source_cloud_color_handler, "original_cloud");viewer.addCoordinateSystem(1.0, "cloud", 0);viewer.setBackgroundColor(0.05, 0.05, 0.05, 0); // Setting background to a dark greyviewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "original_cloud");viewer.resetCamera();while (!viewer.wasStopped()) { viewer.spinOnce();}return EXIT_SUCCESS; }不出什么意外就可以看到結果了.
二.vtk9.1的編譯
其實如果不用qt,pcl自帶的3rdParty內的vtk是已經夠用了。如果需要結合qt使用,就需要進行重新編譯了。
?Download | VTK
將下載后的原文件解壓到VTK-9.1.0-src
?
?點擊Configure觀察結果。
其中CMAKE_INSTALL_PREFIX是VTK 庫要安裝的位置,VTK 編譯后生成的庫文件所在位置,將位置修改為VTK-9.1.0-install-debug, 在后續的生成中,先生成Release版本的VTK庫,生成后將生成的文件移動到VTK-9.1.0-install-release,然后生成Debug版本的VTK庫,此時生成的文件就存放于VTK-9.1.0-install-debug文件夾中。接下來在搜框內搜索QT,vtk項的qt都選擇want,設置qt版本為6.?點擊Configure進行相關內容的設置,其中
Qt6QmlCompilerPlusPrivate_dir這項始終無法設置,不過對后期應用影響不大。要是有哪位知道如何設置的,可以私信。我修改一下這個內容。先行謝過。?再點擊Configure,如果沒有錯誤,就可以Generate。Generate done以后,Open Project選擇2019進行打開。選擇 生成->批生成,在出現的界面中選擇ALL_BUILD的Release版本,點擊生成后等待生成完成,再選擇?生成->批生成,去掉ALL_BUILD的Release,選擇INSTALL的Release版,再點擊生成后等待生成完成。這樣Release已經編譯好了,存放在debug文件夾下,需要手動移動到release文件夾下。同樣再選擇?生成->批生成,取消INSTALL的Release版,并同時勾選ALL_BUILD的debug和INSTALL的debug再點擊生成后等待生成完成。到此編譯的內容基本完畢。這時,備份PCL1.12.1\3rdParty\VTK內容后可以將VTK-9.1.0-install-debug和VTK-9.1.0-install-release內容同時復制到PCL1.12.1\3rdParty\VTK下。用以替換原有的vtk。
總結
以上是生活随笔為你收集整理的3D点云之PCL学习之路(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 小程序支持主体迁移了
- 下一篇: java证书cert_java – 使