在自己的项目中使用PCL

2021-09-26

在自己的项目中使用PCL项目设置:1、创建cpp文件,如pcd_write.cpp,文件内容如下例:

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
int
main (int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ> cloud;
// Fill in the cloud data
cloud.width = 5;
cloud.height = 1;
cloud.is_dense = false;
cloud.points.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、创建txt文件,如CMakeLists.txt,文件内容如下例:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(MY_GRAND_PROJECT)
find_package(PCL 1.3 REQUIRED COMPONENTS common io)
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、创建名为build的文件夹,通过终端在cpp文件夹里输入如下指令:
mkdir build 在build文件夹下终端中输入:cmake .. 完成后输入:make 生成可执行文件,输入:./pcd_write 可生成pcd文件,我们可以使用pcd viewer工具来打开pcd文件,指令为:pcl_viewer test_pcd.pcd

 

小总结:在自己的项目中使用pcl还需勤加练习,熟悉基本流程后,方能大展拳脚 嘿嘿~