1.依赖项安装
sudo apt-get update
sudo apt-get install git build-essential linux-libc-dev
sudo apt-get install cmake cmake-gui
sudo apt-get install libusb-1.0-0-dev libusb-dev libudev-dev sudo apt-get install mpi-default-dev openmpi-bin openmpi-common
sudo apt-get install libflann1.8 libflann-dev
sudo apt-get install libeigen3-dev sudo apt-get install libboost-all-dev
sudo apt-get install libvtk6.2 libvtk6.2-qt libvtk6-dev
sudo apt-get install libqhull* libgtest-dev
sudo apt-get install freeglut3-dev pkg-config
sudo apt-get install libxmu-dev libxi-dev
sudo apt-get install mono-complete
sudo apt-get install qt-sdk openjdk-8-jdk openjdk-8-jre
2.下载源码
地址:https://github.com/PointCloudLibrary/pcl/
3.编译
mkdir build
cd build
cmake-gui //source code 指的是源码的位置 build binaries//指的是编译文件的存放位置
先点击configure 变成红色之后,看看需要添加那些模块,有些模块如果没有添加,以后使用就会有问题
然后generate
make
sudo make install
注意:在cmake-gui的时候,勾选需要编译的模块,不然在使用的时候会出现类似下面这样的问题,注意看cmake的报告,
fatal error: pcl/visualization/pcl_visualizer.h: 没有那个文件或目录
第一次cmake的时候没有勾选可视化模块,下面的cmake的报告写的很明白,visualization手动禁止,进行修改,成功包含可视化模块
4. 测试
#include <iostream> #include <pcl/common/common_headers.h> #include <pcl/io/pcd_io.h> #include <pcl/visualization/pcl_visualizer.h> #include <pcl/visualization/cloud_viewer.h> #include <pcl/console/parse.h> int main(int argc, char **argv) { std::cout << "Test PCL !!!" << std::endl; pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>); uint8_t r(255), g(15), b(15); for (float z(-1.0); z <= 1.0; z += 0.05) { for (float angle(0.0); angle <= 360.0; angle += 5.0) { pcl::PointXYZRGB point; point.x = 0.5 * cosf (pcl::deg2rad(angle)); point.y = sinf (pcl::deg2rad(angle)); point.z = z; uint32_t rgb = (static_cast<uint32_t>(r) << 16 | static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b)); point.rgb = *reinterpret_cast<float*>(&rgb); point_cloud_ptr->points.push_back (point); } if (z < 0.0) { r -= 12; g += 12; } else { g -= 12; b += 12; } } point_cloud_ptr->width = (int) point_cloud_ptr->points.size (); point_cloud_ptr->height = 1; pcl::visualization::CloudViewer viewer ("test"); viewer.showCloud(point_cloud_ptr); while (!viewer.wasStopped()){ }; return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) project(pcl_test) find_package(PCL 1.2 REQUIRED) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS}) add_executable(TestComplie TestComplie.cpp) target_link_libraries (TestComplie ${PCL_LIBRARIES})
成功!