环境:Ubuntu16.04
一、文件夹内创建pcd_write.cpp 和 CMakeLists.txt 文件
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); }
CMakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR) project(pcd_write) find_package(PCL 1.2 REQUIRED) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS}) add_executable (pcd_write pcd_write.cpp) target_link_libraries (pcd_write ${PCL_LIBRARIES})
二、编译
创建build文件夹
mkdir build cd build cmake ..
make
编译后生成 pcd_write可执行程序
运行pcd_write程序
./pcd_write
生成 test_pcd.pcd。
cat查看pcd文件内容
cat test_pcd.pcd
如果想要看一下这个pcd的点云,使用pcl_viewer
pcl_viewer test_pcd.pcd
可以看到5个点
测试完成