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

std::string input_file = "../testCloud.xyz";
// 读取txt文件中的点云数据
std::ifstream infile(input_file.c_str());
std::vector data;
float value;
while (infile >> value)
{
	data.push_back(value);
}
infile.close();
// 将数据转换为点云格式
pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
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];
}

你可能感兴趣的:(PCL,c++)