Point Cloud Library官网上的Installer很久没更新了,这对于想使用最新版点云库的新手可能是个不小的挑战,现在我就手把手教大家如何编译PCL点云库。
准备工作
PC平台:Win10IDE:VS2015三方工具:cmake 3.7.2Boost 1.64Eigen 3.2.10FLANN 1.8.4VTK 6.3.0QHULL 2015.2GLEW 2.0.0PCL 1.8.0解压下载好的Boost库,cmd下指向根目录,键入命令bootstrap.bat。
bootstrap.bat之后键入如下命令,最终生成的是64位静态库,并安装到了“D:\libs_cpp\vs2015\x64\Boost_1_64”下。(命令解析)
b2 --toolset=msvc-14.0 architecture=x86 address-model=64 link=static variant=debug,release threading=multi runtime-link=shared install --prefix="D:\libs_cpp\vs2015\x64\Boost_1_64"最后需要设置一下环境变量使得cmake能够有效地找到boost:
BOOST_LIBRARYDIR boost静态库安装的目录,我的是"D:\libs_cpp\vs2015\x64\Boost_1_64\lib" BOOST_INCLUDEDIR boost头文件安装的目录,我的是"D:\libs_cpp\vs2015\x64\Boost_1_64\include\boost-1_64"pcl当前并不支持3.3版本以上,所以使用了3.2版本,其实Eigen并不用编译,这里我们只是使用cmake对其进行安装,在cmake中选择默认选项,只是把安装位置选择相应的路径就行,如下图: 接下来直接在VS项目列表中点击INSTALL就可以了。
FLANN的编译稍微复杂一点,需要修改一些文件,首先修改CMakeLists文件,添加如下代码:
project(flann) set(CMAKE_DEBUG_POSTFIX "_d") #Added string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)目的是区分debug和release生成的.lib,防止之后安装时文件覆盖。 其次在serialization.h文件94行添加如下代码,否则编译不通过:
BASIC_TYPE_SERIALIZER(double); BASIC_TYPE_SERIALIZER(bool); #ifdef _MSC_VER BASIC_TYPE_SERIALIZER(unsigned __int64); #endif同样地,在Debug和Release下分别编译安装即可。
VTK编译,同样地修改CMakeLists文件,添加debug后缀,我选择了如下几个模块,大家可以根据情况自己选择: 同样地,在Debug和Release下分别编译安装即可。
QHULL编译,同样地修改CMakeLists文件,添加debug后缀,在Debug和Release下分别编译安装即可。
编译GLEW是为了pcl中的模块simulation,同样使用cmake进行创建VS工程,之后需要更改glew子项目属性才能编译通过: 编译完成之后别忘了把bin文件目录添加至系统变量。
下面来到了最后一步,编译pcl。一般来讲cmake不会主动找到Eigen和VTK库,这里需要手动指定库目录: 同样地我们可以手动选择需要编译的组件,我的选择如下: 当然如果选择WITH_QT的同学需要在编译VTK的时候也选择同样的选项。 编译的过程中会报错,pcl_visualizer.cpp中1495行,修改如下:
vtkSmartPointer<vtkLookupTable> table; // if (!pcl::visualization::getColormapLUT(static_cast<LookUpTableRepresentationProperties>(value), table)) if (!pcl::visualization::getColormapLUT(static_cast<LookUpTableRepresentationProperties>(static_cast<int>(value)), table)) break;同样地,1742行修改如下:
vtkSmartPointer<vtkLookupTable> table = vtkSmartPointer<vtkLookupTable>::New (); // getColormapLUT (static_cast<LookUpTableRepresentationProperties>(value), table); getColormapLUT(static_cast<LookUpTableRepresentationProperties>(static_cast<int>(value)), table); table->SetRange (range[0], range[1]);之后进行漫长的编译安装就可以了。:) 最后别忘了添加环境变量:
PCL_DIR pcl安装根目录,我的是"D:\libs_cpp\vs2015\x64\PCL_1_8_0"建立CMakeLists文件:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR) project(cloud_viewer) find_package(PCL 1.8 REQUIRED) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS}) add_executable (cloud_viewer main.cpp) target_link_libraries (cloud_viewer ${PCL_LIBRARIES})同时建立main.cpp文件:
#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 ("my_point_cloud.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; }编译、运行,享受胜利成果把!
当然没时间的同学可以点击这里,我的邮箱tiny_robot@outlook.com希望多多交流。 :)
