相对于txt转pcd,pcd转txt就方便多了,只需应文件输出流将cloud对象中的数据输出到相应文档保存即可。
#include<iostream>
#include<fstream>
#include <iomanip>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
int main()
{
//txt2pcd
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile("my_point_cloud.pcd", *cloud);
ofstream outfile("my_point_cloud.txt");
if (!outfile)
{
cerr << "open my_point_cloud.txt error!" << endl;
exit(1);
}
cout << "the cloud width is" << cloud->width << endl;
cout << "the cloud height is" << cloud->height << endl;
for (size_t i = 0; i < cloud->points.size(); i++)
{
outfile <<setprecision(6)<< cloud->points[i].x <<"\t"<< cloud->points[i].y<<"\t"<< cloud->points[i].z << endl;
cout << setprecision(6) << cloud->points[i].x << "\t" << cloud->points[i].y << "\t" << cloud->points[i].z << endl;
}
outfile.close();
system("pause");
return 0;
}