“Using PCL in your own project”
官方来源:Using PCL in your own project — Point Cloud Library 0.0 documentation
B站学习来源:00-PCL教程-Basic Usage-Using PCL in your own project_哔哩哔哩_bilibili
跟着视频实操步骤:
1.安装PCL
可以从中参考:(我使用ubuntu20.04 ,安装的1.10.0版本)
PCL(Point Cloud Library)学习指南&资料推荐 · 语雀
【Ubuntu】Ubuntu安装PCL(安装PCL/卸载PCL/查看PCL版本/PCL报错处理相关操作)(史上最详细)-CSDN博客
2.开始项目
2.1新建一个文件夹using_PCL
1.在新文件夹using_PCL下新建文件pcd_write.cpp
终端指令:
gedit pcd_write.cpp
把代码输入并保存。
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
int
main ()
{
pcl::PointCloud<pcl::PointXYZ> cloud;
// Fill in the cloud data
cloud.width = 5;
cloud.height = 1;
cloud.is_dense = false;
cloud.resize (cloud.width * cloud.height);
for (auto& point: cloud)
{
point.x = 1024 * rand () / (RAND_MAX + 1.0f);
point.y = 1024 * rand () / (RAND_MAX + 1.0f);
point.z = 1024 * rand () / (RAND_MAX + 1.0f);
}
pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
std::cerr << "Saved " << cloud.size () << " data points to test_pcd.pcd." << std::endl;
for (const auto& point: cloud)
std::cerr << " " << point.x << " " << point.y << " " << point.z << std::endl;
return (0);
}
2.在using_PCL下新建文件CMakeLists.txt
gedit CMakeLists.txt
代码输入并保存:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(MY_GRAND_PROJECT)
find_package(PCL 1.3 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcd_write_test pcd_write.cpp)
target_link_libraries(pcd_write_test ${PCL_LIBRARIES})
3.开始编译
在using_PCL文件夹下,打开终端 :
mkdir build
cd build
cmake ..
make
3.项目结果
3.1运行项目
3.1.1代码
./pcd_write_test
pcl_viewer test_pcd.pcd
3.1.2结果
![](https://img-blog.csdnimg.cn/direct/dc9c3f40176d4bafb69474c1f1786ed1.png)
-end-