pcl使用入门
阅读原文时间:2023年07月15日阅读:1

最近在学习pcl,C++早就忘记了,所以踩了好些坑

不过终于通过了,特此记录下来

环境:win7+pcl1.81+vs2015

1.安装pcl1.81

下载PCL-1.8.1-AllInOne-msvc2015-win64.exe

链接:https://pan.baidu.com/s/1wikg-6uNeBdJf2Ra2EA2fA
提取码:j88f

安装一直下一步,在弹出OpenNI的安装程序

  将OpenNI的安装路径设置为“PCL_ROOT”下3rdParty\OpenNI2文件夹,如C:\Program Files\PCL 1.8.1\3rdParty\OpenNI2

  说明:

    安装结束后若提示“路径过长无法添加环境变量”,需要手动加上环境变量

set PCL_ROOT=C:\Program Files\PCL 1.8.
set OPENNI2_INCLUDE64=C:\Program Files\PCL 1.8.\3rdParty\OpenNI2\Include
set OPENNI2_LIB64=C:\Program Files\PCL 1.8.\3rdParty\OpenNI2\Lib
set OPENNI2_REDIST64=C:\Program Files\PCL 1.8.\3rdParty\OpenNI2\Redist
set path=%path%;%PCL_ROOT%\bin\;C:\Program Files\PCL 1.8.\3rdParty\OpenNI2\Tools;C:\Program Files\PCL 1.8.\3rdParty\VTK\bin;

2.应用

  (1)创建工程pcl

  文件—》新建—》项目

  (2)配置,调试—》pcl属性

    A.配置属性—》调试—》环境

      path = C:\Program Files\PCL 1.8.1\bin

 

    B.配置属性—》C/C++—》预处理器

    追加

_SCL_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS
PCL_NO_PRECOMPILE

    C.配置属性—》VC++目录—》包含目录

      C:\Program Files\PCL 1.8.1\include\pcl-1.8

      C:\Program Files\PCL 1.8.1\3rdParty\Boost\include\boost-1_64

      C:\Program Files\PCL 1.8.1\3rdParty\Eigen\eigen3

      C:\Program Files\PCL 1.8.1\3rdParty\FLANN\include

      C:\Program Files\PCL 1.8.1\3rdParty\Qhull\include

      C:\Program Files\PCL 1.8.1\3rdParty\VTK\include\vtk-8.0

      C:\Program Files\PCL 1.8.1\3rdParty\OpenNI2\Include

    D.配置属性—》VC++目录—》库目录  

      C:\Program Files\PCL 1.8.1\lib

      C:\Program Files\PCL 1.8.1\3rdParty\Boost\lib

      C:\Program Files\PCL 1.8.1\3rdParty\FLANN\lib

      C:\Program Files\PCL 1.8.1\3rdParty\Qhull\lib

      C:\Program Files\PCL 1.8.1\3rdParty\VTK\lib

      C:\Program Files\PCL 1.8.1\3rdParty\OpenNI2\Lib

 

    E.配置属性—》链接器—》附加依赖项

    在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-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_filesystem-vc140-mt-gd-1_64.lib
libboost_graph-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_prg_exec_monitor-vc140-mt-gd-1_64.lib
libboost_program_options-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_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
flann-gd.lib
flann_s-gd.lib
flann_cpp-gd.lib
flann_cpp_s-gd.lib
qhull_d.lib
qhull_p_d.lib
qhull_r_d.lib
qhullcpp_d.lib
qhullstatic_d.lib
qhullstatic_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_c++-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
OpenNI2.lib

View Content

    在Release模式

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_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_filesystem-vc140-mt-1_64.lib
libboost_graph-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_prg_exec_monitor-vc140-mt-1_64.lib
libboost_program_options-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_unit_test_framework-vc140-mt-1_64.lib
libboost_wave-vc140-mt-1_64.lib
libboost_wserialization-vc140-mt-1_64.lib
flann.lib
flann_cpp.lib
flann_cpp_s.lib
flann_s.lib
qhull.lib
qhull_p.lib
qhull_r.lib
qhullcpp.lib
qhullstatic.lib
qhullstatic_r.lib
vtkalglib-8.0.lib
vtkChartsCore-8.0.lib
vtkCommonColor-8.0.lib
vtkCommonComputationalGeometry-8.0.lib
vtkCommonCore-8.0.lib
vtkCommonDataModel-8.0.lib
vtkCommonExecutionModel-8.0.lib
vtkCommonMath-8.0.lib
vtkCommonMisc-8.0.lib
vtkCommonSystem-8.0.lib
vtkCommonTransforms-8.0.lib
vtkDICOMParser-8.0.lib
vtkDomainsChemistry-8.0.lib
vtkexoIIc-8.0.lib
vtkexpat-8.0.lib
vtkFiltersAMR-8.0.lib
vtkFiltersCore-8.0.lib
vtkFiltersExtraction-8.0.lib
vtkFiltersFlowPaths-8.0.lib
vtkFiltersGeneral-8.0.lib
vtkFiltersGeneric-8.0.lib
vtkFiltersGeometry-8.0.lib
vtkFiltersHybrid-8.0.lib
vtkFiltersHyperTree-8.0.lib
vtkFiltersImaging-8.0.lib
vtkFiltersModeling-8.0.lib
vtkFiltersParallel-8.0.lib
vtkFiltersParallelImaging-8.0.lib
vtkFiltersPoints-8.0.lib
vtkFiltersProgrammable-8.0.lib
vtkFiltersSelection-8.0.lib
vtkFiltersSMP-8.0.lib
vtkFiltersSources-8.0.lib
vtkFiltersStatistics-8.0.lib
vtkFiltersTexture-8.0.lib
vtkFiltersTopology-8.0.lib
vtkFiltersVerdict-8.0.lib
vtkfreetype-8.0.lib
vtkGeovisCore-8.0.lib
vtkgl2ps-8.0.lib
vtkhdf5-8.0.lib
vtkhdf5_hl-8.0.lib
vtkImagingColor-8.0.lib
vtkImagingCore-8.0.lib
vtkImagingFourier-8.0.lib
vtkImagingGeneral-8.0.lib
vtkImagingHybrid-8.0.lib
vtkImagingMath-8.0.lib
vtkImagingMorphological-8.0.lib
vtkImagingSources-8.0.lib
vtkImagingStatistics-8.0.lib
vtkImagingStencil-8.0.lib
vtkInfovisCore-8.0.lib
vtkInfovisLayout-8.0.lib
vtkInteractionImage-8.0.lib
vtkInteractionStyle-8.0.lib
vtkInteractionWidgets-8.0.lib
vtkIOAMR-8.0.lib
vtkIOCore-8.0.lib
vtkIOEnSight-8.0.lib
vtkIOExodus-8.0.lib
vtkIOExport-8.0.lib
vtkIOExportOpenGL-8.0.lib
vtkIOGeometry-8.0.lib
vtkIOImage-8.0.lib
vtkIOImport-8.0.lib
vtkIOInfovis-8.0.lib
vtkIOLegacy-8.0.lib
vtkIOLSDyna-8.0.lib
vtkIOMINC-8.0.lib
vtkIOMovie-8.0.lib
vtkIONetCDF-8.0.lib
vtkIOParallel-8.0.lib
vtkIOParallelXML-8.0.lib
vtkIOPLY-8.0.lib
vtkIOSQL-8.0.lib
vtkIOTecplotTable-8.0.lib
vtkIOVideo-8.0.lib
vtkIOXML-8.0.lib
vtkIOXMLParser-8.0.lib
vtkjpeg-8.0.lib
vtkjsoncpp-8.0.lib
vtklibharu-8.0.lib
vtklibxml2-8.0.lib
vtklz4-8.0.lib
vtkmetaio-8.0.lib
vtknetcdf_c++.lib
vtkNetCDF-8.0.lib
vtkoggtheora-8.0.lib
vtkParallelCore-8.0.lib
vtkpng-8.0.lib
vtkproj4-8.0.lib
vtkRenderingAnnotation-8.0.lib
vtkRenderingContext2D-8.0.lib
vtkRenderingContextOpenGL-8.0.lib
vtkRenderingCore-8.0.lib
vtkRenderingFreeType-8.0.lib
vtkRenderingGL2PS-8.0.lib
vtkRenderingImage-8.0.lib
vtkRenderingLabel-8.0.lib
vtkRenderingLIC-8.0.lib
vtkRenderingLOD-8.0.lib
vtkRenderingOpenGL-8.0.lib
vtkRenderingVolume-8.0.lib
vtkRenderingVolumeOpenGL-8.0.lib
vtksqlite-8.0.lib
vtksys-8.0.lib
vtktiff-8.0.lib
vtkverdict-8.0.lib
vtkViewsContext2D-8.0.lib
vtkViewsCore-8.0.lib
vtkViewsInfovis-8.0.lib
vtkzlib-8.0.lib
OpenNI2.lib

View Content

  说明:

    debug的比release的文件名多 -gd,_d是不同库中debug的命名规则

    其中文件名来自 PCL 1.8.1\lib,PCL 1.8.1\3rdParty\Boost\lib,PCL 1.8.1\3rdParty\VTK\lib,PCL 1.8.1\3rdParty\FLANN\lib,PCL 1.8.1\3rdParty\OpenNI2\Lib,PCL 1.8.1\3rdParty\Qhull\lib

  (3)测试

使用点云生成点,并输出

#include
#include
#include

int main(int argc, char** argv) {
pcl::PointCloud::Ptr cloud(new pcl::PointCloud);

//Fill in the cloud data  
cloud->width = ;  
cloud->height = ;  
cloud->points.resize(cloud->width\*cloud->height);  
for (size\_t i = ; i < cloud->points.size(); ++i) {  
    cloud->points\[i\].x =  \* rand() / (RAND\_MAX + 1.0f);  
    cloud->points\[i\].y =  \* rand() / (RAND\_MAX + 1.0f);  
    cloud->points\[i\].z =  \* rand() / (RAND\_MAX + 1.0f);  
}  
std::cout << "Cloud before projection:" << std::endl;  
for (size\_t i = ; i < cloud->points.size(); ++i) {  
    std::cout << "      " << cloud->points\[i\].x << "   " << cloud->points\[i\].y << "   " << cloud->points\[i\].z << "   " << std::endl;  
}  
system("pause");  
return ;  

}

过滤器

#include
#include
#include
#include
#include
int main(int argc, char** argv) {
pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
pcl::PointCloud::Ptr cloud_projected(new pcl::PointCloud);
//Fill in the cloud data
cloud->width = ;
cloud->height = ;
cloud->points.resize(cloud->width*cloud->height);
for (size_t i = ; i < cloud->points.size(); ++i) {
cloud->points[i].x = * rand() / (RAND_MAX + 1.0f);
cloud->points[i].y = * rand() / (RAND_MAX + 1.0f);
cloud->points[i].z = * rand() / (RAND_MAX + 1.0f);
}
std::cerr << "Cloud before projection:" << std::endl; for (size_t i = ; i < cloud->points.size(); ++i) {
std::cerr << " " << cloud->points[i].x << " " << cloud->points[i].y << " " << cloud->points[i].z << " " << std::endl; } // Create a set of planar coefficients with X=Y=0,Z=1 pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients()); coefficients->values.resize();
coefficients->values[] = coefficients->values[] = ;
coefficients->values[] = 1.0;
coefficients->values[] = ;
// Create the filtering object
pcl::ProjectInliersproj;
proj.setModelType(pcl::SACMODEL_PLANE);
proj.setInputCloud(cloud);
proj.setModelCoefficients(coefficients);
proj.filter(*cloud_projected);
std::cerr << "Cloud after projection: " << std::endl; for (size_t i = ; i < cloud_projected->points.size(); ++i) {
std::cerr << " " << cloud_projected->points[i].x << " " << cloud_projected->points[i].y << " " << cloud_projected->points[i].z << " " << std::endl;
}
system("pause");
return ;
}

优化将点展示出来

#include
#include
#include
#include
int main() {
pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
//设置点云大小
cloud->points.resize();
//填充点云数据
for (size_t i = ; i < cloud->points.size(); ++i)
{
cloud->points[i].x = * rand() / (RAND_MAX + 1.0f);
cloud->points[i].y = * rand() / (RAND_MAX + 1.0f);
cloud->points[i].z = * rand() / (RAND_MAX + 1.0f);
}
//声明视窗
boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
//设置背景色
viewer->setBackgroundColor(1.0f, 0.5f, 1.0f);
//预处理点云颜色
pcl::visualization::PointCloudColorHandlerCustom magenta(cloud, , , );
//把点云加载到视窗
viewer->addPointCloud(cloud, magenta, "cloud");
//设置点云大小
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, , "cloud");
//显示
viewer->spin();
}

注:

  如果出现以下错误

    (1)LNK1112 模块计算机类型“x64”与目标计算机类型“X86”冲突解决方案

 

 

  生成—配置管理器

      补充:

        需要重新配置,即2(2)部分的操作

     (2)C1010 在查找预编译头时遇到意外的文件结尾

    (3)C4996 'pcl::SAC_SAMPLE_SIZE': This map is deprecated and is kept only to prevent breaking existing user code.

      打开项目属性页>C/C++>常规>SDL检查(设置为否)

      重新编译,原先的错误信息变成了警告。

通过pcl的学习,教训也是很大的:

  不要偷懒,不要整个的复制代码,要认真读,认真看,不要跳跃,一定要沉下心来,沉下心来,要认真