基于pcl库输出点云ply文件的所有点的三维坐标的C++代码
下面是一个基于pcl库输出点云PLY文件的所有点的三维坐标的C++代码示例:
#include <iostream>
#include <pcl/io/ply_io.h>
#include <pcl/point_types.h>
int main()
{
// 创建一个点云对象
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// 添加一些点到点云中
for (float x = -1.0; x <= 1.0; x += 0.1)
{
for (float y = -1.0; y <= 1.0; y += 0.1)
{
for (float z = -1.0; z <= 1.0; z += 0.1)
{
pcl::PointXYZ point;
point.x = x;
point.y = y;
point.z = z;
cloud->push_back(point);
}
}
}
// 输出点云的三维坐标到PLY文件
pcl::io::savePLYFile("point_cloud.ply", *cloud);
std::cout << "Point cloud saved as point_cloud.ply" << std::endl;
return 0;
}
这段代码创建一个点云对象,然后使用三个嵌套的循环来生成一些点,并将这些点添加到点云对象中。最后,使用pcl::io::savePLYFile函数将点云的三维坐标保存到PLY文件中
原文地址: https://www.cveoy.top/t/topic/hIDG 著作权归作者所有。请勿转载和采集!