点云pcd格式转换成ply格式

转载请注明出处:http://my.csdn.net/ye_shen_wei_mian

PCL中的常用的点云存储文件为.pcd文件,但是很多场合下使用的点云存储文件为.ply文件,特别是要在meshlab中查看的时候。

PCL中有相应的类PLYWriter可以帮助我们实现从.pcd文件到.ply文件的转换。值得一提的是,在PCL的源码pcl-master中的tools文件夹里有很多范例的例程,可以帮助我们参照着实现很多简单但基本的功能。其中,pcd2ply.cpp便是指导我们实现从.pcd文件到.ply文件的转换的一个cpp文件。

以下的小程序便是根据上述的指导文件写成的。值得注意的是,以下将用到的 PCLPointCloud2 类并不适用于PCL官网上的pcl-1.6.0版本,因为pcl-1.6.0实在是太老了,并没有实现这个类。解决方法是使用较新的pcl-1.7.2版本,这样就可以了。

#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include<pcl/PCLPointCloud2.h>
#include<iostream>
#include<string>

using namespace pcl;
using namespace pcl::io;
using namespace std;

int PCDtoPLYconvertor(string & input_filename ,string& output_filename)
{
pcl::PCLPointCloud2 cloud;
if (loadPCDFile(input_filename , cloud) < 0)
{
cout << "Error: cannot load the PCD file!!!"<< endl;
return -1;
}
PLYWriter writer;
writer.write(output_filename, cloud, Eigen::Vector4f::Zero(), Eigen::Quaternionf::Identity(),true,true);
return 0;

}

int main()
{
string input_filename = ".//source//cloud_pcd.pcd";
string output_filename = ".//result//cloud_ply.ply";
PCDtoPLYconvertor(input_filename , output_filename);
return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43712770/article/details/89402181
今日推荐