点云数据格式转换(.xyz→.pcd)

  • Post author:
  • Post category:其他


std::string input_file = "../testCloud.xyz";
// 读取txt文件中的点云数据
std::ifstream infile(input_file.c_str());
std::vector<float> data;
float value;
while (infile >> value)
{
	data.push_back(value);
}
infile.close();
// 将数据转换为点云格式
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
int size = data.size() / 3;
cloud->points.resize(size);
for (int i = 0; i < size; ++i)
{
	cloud->points[i].x = data[i * 3];
	cloud->points[i].y = data[i * 3 + 1];
	cloud->points[i].z = data[i * 3 + 2];
}



版权声明:本文为xiaoyaolangwj原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。