资源简介
利用pcl,转换txt格式点云数据为pcd格式
代码片段和文件信息
#include
#include
#include
#include
#include
#include
using namespace std;
pcl::PointCloud cloud;
void write_pcd(double arrry[]int i);
std::string Txt_or_Asc_filename_;
std::string pcd_filename_;
void
showHelp (char *filename)
{
std::cout << std::endl;
std::cout << “***************************************************************************“ << std::endl;
std::cout << “* *“ << std::endl;
std::cout << “* TO_PCD.EXE - Usage Guide *“ << std::endl;
std::cout << “* *“ << std::endl;
std::cout << “***************************************************************************“ << std::endl << std::endl;
std::cout << “Usage: “ << filename << “ filename_IN.asc(.txt) filename_OUT.pcd [Options]“ << std::endl << std::endl;
std::cout << “Options:“ << std::endl;
std::cout << “ -h: Show this help.“ << std::endl;
}
int
main (int argc
char *argv[])
{
//显示帮助菜单
if (pcl::console::find_switch (argc argv “-h“) || argc < 3)
{
showHelp (argv[0]);
exit (0);
}
//获取读入,输出文件名
std::vector filenames_out;
filenames_out = pcl::console::parse_file_extension_argument (argc argv “.pcd“);
if (filenames_out.size () != 1)
{
std::cout << “Filenames missing--pcd.\n“;
showHelp (argv[0]);
exit (-1);
}
pcd_filename_ = argv[filenames_out[0]];//输出文件名
std::vector filenames_in;
filenames_in = pcl::console::parse_file_extension_argument (argc argv “.txt“);
if (filenames_in.size () != 1)
{
std::cout << “Filenames missing--asc or txt.\n“;
showHelp (argv[0]);
exit (-1);
}
Txt_or_Asc_filename_ = argv[filenames_in[0]];//读入文件名
ifstream inFile;
ifstream fin;
int i=0Txt_size=0;
double xyzRGB;
inFile.open(Txt_or_Asc_filename_);
if(!inFile.is_open())
cout<<“Open Failed!“< cout << “Starting!“ << endl;
while(!inFile.eof())
{
inFile>> x >> y >> z >> R >> G >> B;
//cout << x <<“ “<< y <<“ “ < Txt_size++;
}
cout<< “txt文件的行数为:“ << Txt_size << endl;// text 的行数*3
cloud.width=Txt_size;
cloud.height=1;
cloud.points.resize(cloud.width*cloud.height);
inFile.close();
fin.open(Txt_or_Asc_filename_);
if(!fin.is_open())
cout<<“Open Failed!“< while(!fin.eof())
{
fin >> x >> y >> z >> R >> G >> B;
cloud.points[i].x = x;
cloud.points[i].y = y;
cloud.points[i].z = z;
cloud.points[i].r = R;
cloud.points[i].g = G;
cloud.points[i].b = B;
i++;
}
pcl::io::savePCDFileASCII(pcd_filename_cloud);
cout<<“转换的点云行数:“ << i << endl;
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-08-16 15:37 txt2pcd\
文件 103 2015-10-16 20:14 txt2pcd\0说明.txt
目录 0 2016-08-16 15:42 txt2pcd\CMAKE\
文件 274944 2015-10-25 13:06 txt2pcd\CMAKE\To_pcd.exe
文件 1454316 2015-10-25 13:06 txt2pcd\CMAKE\To_pcd.ilk
文件 4844544 2015-10-25 13:06 txt2pcd\CMAKE\To_pcd.pdb
文件 36864 2015-10-25 13:06 txt2pcd\CMAKE\To_pcd.v11.suo
文件 9 2016-04-23 17:27 txt2pcd\CMAKE\_desktop.ini
目录 0 2016-08-16 15:37 txt2pcd\source\
文件 301 2015-10-16 15:50 txt2pcd\source\CMakeLists.txt
文件 326 2015-04-23 10:32 txt2pcd\source\CMakeLists.txt.bak
文件 2954 2015-10-25 13:05 txt2pcd\source\To_pcd.cpp
文件 9 2016-04-23 17:27 txt2pcd\source\_desktop.ini
- 上一篇:Fast ICP算法源码
- 下一篇:listview与viewpager组合2
评论
共有 条评论