引言
pcl1.8.0,较pcl1.7和1.6多了不少算法,很多感兴趣的方法都在pcl1.8中有所实现。当pcl11.8.0rc1和rc2发布时就迫不及待的下载下来进行使用,用了几个月发现pcl1.8.0rc版有几个bug无法解决,如:表面重建时无法映射纹理。得知2016/06/14 github 发布正式版pcl1.8.0时,就立马下载下来准备编译并记录整个过程,感兴趣的小伙伴可以参考。
pcl官网已经有windows平台下的编译过程,现在我基于此教程编译PCL1.8.0并配置。
PCL1.8.0源码包下载
下载地址:https://github.com/PointCloudLibrary/pcl/releases
准备工具
编译器VS2013,CMakeGUI 3.3.2,系统版本win7 64位。
提示:软件版本根据自己情况选择,没必要非要和博客中一致。
第三方依赖库
第三方库 | 用途 | 是否必须 |
---|---|---|
Boost | 用于智能指针等操作 | 必选 |
Eigen | 用于矩阵运算等 | 必选 |
FLANN | 用于邻域搜索等 | 必选 |
VTK | 可视化库,用于显示点云等 | 必选 |
Qt | 用于图像交互界面等 | 可选 |
QHULL | used for convex/concave hull decompositions in surface | 可选 |
OpenNI | 用于获取点云等 | 可选 |
提示:在编译PCL1.8.0时请确保您已安装了正确的第三方依赖库。不能混合32位和64位代码,并且不能混用不同编译器编译第三方库。有些库需要自己编译,这篇博客里就不对如何编译第三方依赖库进行讲解了,只详述PCL1.8.0的编译过程。
编译PCL1.8.0
官方编译教程:http://www.pointclouds.org/documentation/tutorials/compiling_pcl_windows.php
提示:跟着官方教程操作即可成功。
(1) 将源码包pcl-pcl-1.8.0.zip解压到目录:F:\pcl-1.8.0
提示:根据自己需要解压即可,本博客一定程度上参考了官方教程。
(2)打开CMakeGUI
源码路径:F:/pcl-1.8.0
项目路径:F:/pcl-1.8.0/build
如图:
点击configure,选择合适的编译器(VS2013 64位)
(3)出现无法找到Eigen库
将变量EIGEN_INCLUDE_DIR对应的值修改为Eigen库所在目录。
如:F:\Eigen\eigen3
重新configure
提示找不到Boost库,添加下面三个变量和相应的路径,重新configure。
BOOST_ROOT="F:\Boost"
Boost_LIBRARY_DIRS="F:\Boost\lib"
BOOST_INCLUDEDIR="F:\Boost\include\boost-1_59"
(4)修改安装路径
或者,打开CPackConfig.cmake文件,修改CPACK_INSTALL_PREFIX值为F:\PCL1.8.0
点Generate生成VS工程。
(5)打开PCL.sln
分别批生成Debug和Release版本,并分别安装。
(6)Debug和Release版编译、安装成功
Debug
Release
(7)提示
Cmake构建工程时可能会出现其他依赖库缺失情况,一一补上就行。使用Cmake构建工程成功,也可能在VS中编译时会出现其他问题,根据提示也可以一一解决。整个编译过程很耗时,Debug和Release完全编译一次要一个小时左右。如果需要All in One安装包,在Cmake中勾选生成All in One包即可(特别费时所以就没勾选)。
配置
将下列路径加入环境变量:
F:\PCL1.8.0C\bin;F:\PCL1.8.0C\3rdParty\FLANN\bin;F:\PCL1.8.0C\3rdParty\OpenNI2\Tools;F:\PCL1.8.0C\3rdParty\Qhull\bin;F:\PCL1.8.0C\3rdParty\VTK\bin;
测试Debug版
(1)打开VS2013新建项目,添加如下代码
#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 main()
{
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;
}
(2)新建属性表PCLCDebug
VC++目录,添加包含目录
VC++目录,添加库目录
连接器,输入,附加依赖项
提示:我是把所有的Debug依赖库都加上,因为用的多,懒得去挑。
(2)最终结果