#include<iostream>
#include<pcl/io/pcd_io.h>
#include<pcl/point_types.h>
int
main(int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>cloud;
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);
for (const auto& point : cloud)
std::cerr << "" << point.x << "" << point.y << "" << point.z << std::endl;
return (0);
}
该代码示例展示了如何在C++中利用Point Cloud Library (PCL) 创建一个5x1的点云数据集,每个点的坐标通过随机数生成,并保存为ASCII格式的PCD文件。程序还输出了点云中每个点的x, y, z坐标。
8329

被折叠的 条评论
为什么被折叠?



