0
点赞
收藏
分享

微信扫一扫

3d激光雷达开发(pcd数据读取)

AbrahamW 2022-11-23 阅读 116


        之前谈到了,如果从lidar获取数据,那么需要保存成pcd的形式。那么如何从pcd加载数据,其实方法也是一样的。相关内容可以参考这个链接​​​​​​​

​​https://pcl.readthedocs.io/projects/tutorials/en/master/reading_pcd.html#reading-pcd​​

1、编写pcd_read.cpp文件

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

int
main ()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);

if (pcl::io::loadPCDFile<pcl::PointXYZ> ("test_pcd.pcd", *cloud) == -1) //* load the file
{
PCL_ERROR ("Couldn't read file test_pcd.pcd \n");
return (-1);
}
std::cout << "Loaded "
<< cloud->width * cloud->height
<< " data points from test_pcd.pcd with the following fields: "
<< std::endl;
for (const auto& point: *cloud)
std::cout << " " << point.x
<< " " << point.y
<< " " << point.z << std::endl;

return (0);
}

2、编写CMakeLists.txt

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(pcd_read)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (pcd_read pcd_read.cpp)
target_link_libraries (pcd_read ${PCL_LIBRARIES})

3、准备生成sln文件

mkdir build
cd build
cmake ..

        不出意外,应该可以正常编译通过

3d激光雷达开发(pcd数据读取)_当前目录

4、运行pcd_read.exe

        在运行前,有两个事情需要注意一下:第一,保证exe需要的dll都已经拷贝到当前目录下面;第二,保证test_pcd.pcd文件已经准备好。如果一切ok,就会得到下面这些输出,

3d激光雷达开发(pcd数据读取)_3d_02

举报

相关推荐

0 条评论