Author: 琅琊土肥圆
E-mail: wt_lor@163.com
Date: 2018-09-21
上回书说道,如何读取PCD文件,本回则来讲讲如何将一个PointCloud结构写入pcd文件。闲言少叙,先上代码,然后一点点的讲解。代码如下。
/* 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; // This point cloud should be filled with points.
pcl::PCDWriter writer
writer.write<pcl::PointXYZ>("filename.pcd", cloud);
return 0;
}
关于点云点类型的问题,此处不再赘述,可以查阅上篇文章,或者到pcl的官网查阅相关文档。
不同于读取PCD文件,在写入PCD文件时,主要使用了如下两行代码。
pcl::PCDWriter writer;
writer.write<pcl::PointXYZ>("filenamepcd", cloud);
在上一节的CMakeLists.txt文件中,添加如下两行,用于添加编译pcd_write.cpp的内容。
add_executable(pcd_writer ./pcd_write.cpp)
target_link_libraries(pcd_writer ${PCL_LIBRARIES})
完整的CMakeLists.txt文件如下所示。
cmake_minimum_required(VERSION 3.0)
project(pcd_read)
find_package(
PCL 1.2 REQUIRED
)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_executable(pcd_read ./pcd_read.cpp)
target_link_libraries(pcd_read ${PCL_LIBRARIES})
add_executable(pcd_write ./pcd_write.cpp)
target_link_libraries(pcd_write ${PCL_LIBRARIES})