win10+pcl1.8.1+VS2015下载与环境配置踩坑

身为一个学术界的小白,从大一开始跟着项目做起·,第一步是opencv,从而对视觉识别产生兴趣,几天前在听一个讲座的时候了解到3D点云,如下图

win10+pcl1.8.1+VS2015下载与环境配置踩坑_第1张图片win10+pcl1.8.1+VS2015下载与环境配置踩坑_第2张图片
了解到通过这个可以将2D图像转化为3D点云,即进行单目视觉的三维重建,觉得很有意思也很感兴趣,今天心血来潮下载了pcl的软件与库并且进行了与win10、VS2015的配置

不多说了,直接上过程:

1.首先在pcl官网上已经下载不到1.7版本以上的了(里面有一些不错的介绍) http://www.pointclouds.org/downloads/windows.html

最后我在Github上找到了1.8.1版本:
https://github.com/PointCloudLibrary/pcl/releases

还有这里也可以找到(其中还有外国网友的一些评论)
http://unanancyowen.com/en/pcl181

下图为下载好的win64可执行文件样式
在这里插入图片描述

2.双击运行.exe文件,连续点击下一步,我同意,出现以下界面
选择第二项 Add PCL to the system PATH for all users
这样省去了自己添加环境变量的麻烦
勾选并安装后系统变量中出现了PCL_ROOT的变量(本人下载在了D盘下)
在这里插入图片描述
安装后 右键此电脑,点击“控制面板”中“高级系统设置”,出现系统属性页面中点击高级,在下面的系统变量中找到PATH,双击打开,并添加如下字样(前提是前面的PCL_ROOT已经出现)

%PCL_ROOT%\3rdParty\FLANN\bin
%PCL_ROOT%\bin
%PCL_ROOT%\3rdParty\Qhull\bin
%PCL_ROOT%\3rdParty\OpenNI2\Tools
%PCL_ROOT%\3rdParty\VTK\bin

搞完前面的这两步,PCL的安装就基本完成了,下面就是在VS中的配置了

3.pcl在VS中的配置VS2015

新建项目,这里命名为PCLPropertySheet_D,表示Debug下的配置

在包含目录与库目录中根据自己的路径进行添加
win10+pcl1.8.1+VS2015下载与环境配置踩坑_第3张图片
win10+pcl1.8.1+VS2015下载与环境配置踩坑_第4张图片
在链接器 —> 输入项 —> 附加依赖项中添加(以下为各lib文件夹下的全部.lib文件)
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
flann_cpp_s-gd.lib
flann_s-gd.lib
flann-gd.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
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
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
vtkFiltersVerdict-8.0-gd.lib
vtkfreetype-8.0-gd.lib
vtkGeovisCore-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
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
vtkIOPLY-8.0-gd.lib
vtkIOSQL-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
vtklibxml2-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
vtkRenderingCore-8.0-gd.lib
vtkRenderingFreeType-8.0-gd.lib
vtkRenderingImage-8.0-gd.lib
vtkRenderingLabel-8.0-gd.lib
vtkRenderingLOD-8.0-gd.lib
vtkRenderingVolume-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

以上步骤非常关键,下面会有对这一步失误或错误的报错解决方案,大多数都是在这里有错误

注意:必须是在与我相同的环境与版本中才可以使用,若版本不同,如下为从各文件夹中提取所有文件名称的方法,最好从中分离出debug版本的文件

例如要获取目录中D:\PCL 1.8.1\3rdParty\VTK\lib下的所有静态链接库文件名并存储至文本.txt,方法如下:
1、win+r
2、输入:cmd回车
3、输入:cd /d D:\PCL 1.8.1\3rdParty\VTK\lib 回车
4、输入:dir /b *.lib *>0.txt 回车
即可存储在.txt文件中,其中包含需要删除的内容(我遇到的有0.txt、cmake和pkgconfig)

这里整个配置就完成了,检验下配置是否正确:
程序1:

#include  
#include   
#include  
#include   
#include   
int main(int argc, char** argv)
{
 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_projected(new pcl::PointCloud<pcl::PointXYZ>);
 cloud->width = 5;
 cloud->height = 1;
 cloud->points.resize(cloud->width * cloud->height);
 for (size_t i = 0; i < cloud->points.size(); ++i)
 {
  cloud->points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
  cloud->points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
  cloud->points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
 }
 std::cerr << "Cloud before projection: " << std::endl;
 for (size_t i = 0; 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(4);
 coefficients->values[0] = coefficients->values[1] = 0;
 coefficients->values[2] = 1.0;
 coefficients->values[3] = 0;
 // Create the filtering object      
 pcl::ProjectInliers<pcl::PointXYZ> proj;
 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 = 0; 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 (0);
}

运行结果如图win10+pcl1.8.1+VS2015下载与环境配置踩坑_第5张图片到此,配置基本完成,就可以进行下面的pcl学习了。

在下面网址中有我已经配置好的属性页 重要事情说三遍!!!
(必须是同样的环境下才可以使用!!!)
(必须是同样的环境下才可以使用!!!)
(必须是同样的环境下才可以使用!!!)

https://download.csdn.net/download/weixin_45154431/12191818

这是个大招,无需自己配VS中的环境,不过前面两个步骤:下载与环境变量还是要自己配的,有了这个,在属性页中直接添加即可。

以下是一些常见的错误:

1.找不到xxx.h

  这个问题是因为在设置include,即设置附加包含目录,路径不对或缺少导致的,根据提示,找到对应错误的库的头文件路径,更该即可。

2.LINK1104:无法打开文件".obj"原因及解决办法

这个问题和上一个问题很像,是附加库目录中,路径不对或缺少导致的,根据提示,修改对应的路径即可。
注意:如果设置了,还是提示找不到头文件或lib,这时就要查看一下PCL的安装路径下有没有这个头文件或lib,如果有,说明你的路径设置的还是有问题,如果搜索不到这个头文件,那就要修改代码,可能是版本原因导致这个头文件没了,如果搜索不到lib文件,那么把这个lib从附加依赖项里删除。这就涉及到上面.lib文件的添加是否正确,若版本不对一定会出现该问题,不用紧张,将相应目录里的文件名称重新添加到附加依赖项中。

3.error LNK2001:“无法解析的外部符号"protected: virtual void __cdecl pcl::ProjectInliers::applyFilter(class pcl::PointCloud &)" (?applyFilter@? P r o j e c t I n l i e r s @ U P o i n t X Y Z @ p c l @ @ @ p c l @ @ M E A A X A E A V ? ProjectInliers@UPointXYZ@pcl@@@pcl@@MEAAXAEAV? ProjectInliers@UPointXYZ@pcl@@@pcl@@MEAAXAEAV?PointCloud@UPointXYZ@pcl@@@2@@Z)
error LNK2001: 无法解析的外部符号 “private: virtual bool __cdecl pcl::ProjectInliers::initSACModel(int)” (?initSACModel@?$ProjectInliers@UPointXYZ@pcl@@@pcl@@EEAA_NH@Z)

linker找不到符号,
就说明是obj文件或lib文件中没有该符号,
而obj和lib中没有符号的情况,主要还是这个原因:
工程里没有相关代码,所以符号没有被编译。(这种情况obj中常见,寻找.lib文件重新查看,或查看lib是不是有的两个lib写在同一行了,或是pcl 的.lib包含不完整)

4.1>IOCP_Socket.lib(stdafx.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“MTd_StaticDebug”(Code.obj 中)
检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“MTd_Stat…

运行库设置不一样了:
项目属性 -> 配置属性 -> C/C++ -> 代码生成 -> 运行库
都设置一样就行了 多线程调试(/MTd)

5.error C4996: ‘pcl::SAC_SAMPLE_SIZE’: This map is deprecated and is kept only to prevent breaking existing user code. Starting from PCL 1.8.0 model sample size is a protected member of the SampleConsensusModel class

打开项目属性页>C/C++>常规>SDL检查(设置为否)。
win10+pcl1.8.1+VS2015下载与环境配置踩坑_第6张图片
若上面的方法无法解决这个错误,可以打开头文件”model_types.h”,修改其中的代码:

源码:`namespace pcl

{
  const static std::map<pcl::SacModel, unsigned int>
      PCL_DEPRECATED("This map is deprecated and is kept only to prevent breaking "
      "existing user code. Starting from PCL 1.8.0 model sample size "
      "is a protected member of the SampleConsensusModel class")
  SAC_SAMPLE_SIZE (sample_size_pairs, sample_size_pairs + sizeof (sample_size_pairs) / sizeof (SampleSizeModel));
}

修改后:

namespace pcl
{
  const static std::map<pcl::SacModel, unsigned int>
      //PCL_DEPRECATED("This map is deprecated and is kept only to prevent breaking "
      //"existing user code. Starting from PCL 1.8.0 model sample size "
      //"is a protected member of the SampleConsensusModel class")
  SAC_SAMPLE_SIZE (sample_size_pairs, sample_size_pairs + sizeof (sample_size_pairs) / sizeof (SampleSizeModel));
}

6.d:\clibrary\pcl1.8.0\pcl1.8.0x86\3rdparty\flann\include\flann\util\serialization.h(362): error C4996: ‘fopen’: This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

打开项目属性页>C/C++>预处理器,添加: _CRT_SECURE_NO_WARNINGS

7.error LNK2001: 无法解析的外部符号 “public: void __cdecl pcl::ConditionalEuclideanClustering::segment(class std::vector &)” (?segment@? C o n d i t i o n a l E u c l i d e a n C l u s t e r i n g @ U P o i n t X Y Z I N o r m a l @ p c l @ @ @ p c l @ @ Q E A A X A E A V ? ConditionalEuclideanClustering@UPointXYZINormal@pcl@@@pcl@@QEAAXAEAV? ConditionalEuclideanClustering@UPointXYZINormal@pcl@@@pcl@@QEAAXAEAV?vector@UPointIndices@pcl@@V?

在所有库都配置的情况下,若出现上述问题。
开项目属性页>C/C++>预处理器,添加:PCL_NO_PRECOMPILE

8.D:\PCL1.8.1\3rdParty\FLANN\include\flann/util/serialization.h(362): error C4996: ‘fopen’: This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> F:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\stdio.h(211) : 参见“fopen”的声明

打开项目属性页>C/C++>预处理器,添加:_CRT_SECURE_NO_WARNINGS

以上是我遇到的一些问题并结合网上很多大神的解决方案揉成一套常见问题及解决方案,希望可以帮到大家

本文参考的所有文章链接如下:
https://blog.csdn.net/annabelle1130/article/details/78628408
https://cloud.tencent.com/developer/article/1507247
https://www.cnblogs.com/lzpong/p/4631784.html
https://blog.csdn.net/Gloriamin/article/details/47277153?locationNum=15&fps=1
https://blog.csdn.net/wokaowokaowokao12345/article/details/51287011

你可能感兴趣的:(3d成像,计算机视觉,c++)