ubuntu1804安装pcl点云库


什么是PCL点云库?
PCL(Point Cloud Library)是大型跨平台开源C++编程库,它实现了大量点云相关的通用算法和高效数据结构,涉及到点云获取、滤波、分割、配准、检索、特征提取、识别、追踪、曲面重建、可视化等。支持多种操作系统平台,可在windows、linux、android、mac os、部分嵌入式实时系统上运行。
PCL起初是ROS(Robot Operating System)下由来自于慕尼黑大学和斯坦福大学等人维护和开发的开源项目,主要应用于机器人研究应用领域,随着各个算法模块的积累,于2011年独立出来。

官方文档地址:
https://pointclouds.org/documentation/ 
 
1.pcl的安装
终端输入命令:
#点云库
sudo apt install libpcl-dev


#pcl-tools
sudo apt install pcl-tools

安装成功。默认安装pcl1.8.1.
通过pcl_viewer显示点云。

2.测试
test.cpp
#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; // ptr需要new初始化 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)set(CMAKE_CXX_STANDARD 14) # C++ 11find_package(PCL 1.8 REQUIRED)find_package(OpenCV 4 REQUIRED)include_directories( ${OPENCV_INCLUDE_DIRS})include_directories(${PCL_INCLUDE_DIRS})link_directories(${PCL_LIBRARY_DIRS})add_definitions(${PCL_DEFINITIONS})# list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")add_executable(pcl_test test.cpp)target_link_libraries (pcl_test ${PCL_LIBRARIES} ${OpenCV_LIBS})


《完》
点击上方小卡片关注我
到顶部