Reprint please indicate the source: Http://my.csdn.net/ye_shen_wei_mian
The commonly used point cloud in PCL stores files as. pcd files, but the point cloud used in many situations is a. ply file, especially when viewed in MeshLab.
A corresponding class Plywriter in PCL can help us implement conversions from. pcd files to. ply files. It is worth mentioning that in the PCL source Pcl-master in the Tools folder there are many examples of routines that can help us to realize many simple but basic functions. Among them, Pcd2ply.cpp is a CPP file that instructs us to convert from. pcd files to. ply files.
The following small procedure is written in accordance with the above guidance document. It is noteworthy that the following PCLPOINTCLOUD2 classes will not apply to the pcl-1.6.0 version of the PCL official web site because pcl-1.6.0 is too old to implement this class. The solution is to use the newer version of pcl-1.7.2, so that's it.
#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::P CLPOINTCLOUD2 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;
}