设置首页收藏本站
开启左侧

[Pcl] qt+pcl之pcd转ply格式文件代码

[复制链接]
太极真人 发表于 2019-9-19 20:04:17 | 显示全部楼层 |阅读模式
  1. #include <iostream>
  2. #include <pcl/point_types.h>
  3. #include <pcl/PCLPointCloud2.h>
  4. #include <pcl/io/pcd_io.h>
  5. #include <pcl/io/ply_io.h>
  6. #include <QApplication>
  7. #include <QFileDialog>
  8. #include <QString>

  9. using namespace std;

  10. int main (int argc, char *argv[])
  11. {
  12.     QApplication a (argc, argv);
  13.    
  14.     pcl::PCDReader pcdreader;
  15.     pcl::PCDWriter pcdwriter;
  16.     pcl::PLYReader plyreader;
  17.     pcl::PLYWriter plywriter;

  18.     //QString q_filename = QFileDialog::getExistingDirectory(Q_NULLPTR,
  19.     //                                                    "Select .pcd or .ply file",
  20.     //                                                    ".");
  21.     QString q_name = QFileDialog::getOpenFileName(Q_NULLPTR,
  22.                                                       "Select .pcd or .ply file",
  23.                                                       ".");
  24.     string name = q_name.toStdString();
  25.     cout << "read: " << name << endl;

  26.     int path_i = name.find_last_of("\")+1;
  27.     int ext_i = name.find_last_of(".");
  28.     string extname = name.substr(ext_i,name.size()-ext_i);
  29.     string filename = name.substr(path_i,ext_i-path_i);
  30.    
  31.     pcl::PCLPointCloud2 cloud2;

  32.     if(extname == ".pcd")
  33.     {
  34.         int ret = pcdreader.read(name, cloud2);
  35.         if (ret == -1) //* load the file
  36.         {
  37.             PCL_ERROR ("Couldn't read pcd file \n");
  38.             return (-1);
  39.         }
  40.         plywriter.writeASCII(filename+".ply", cloud2);
  41.         cout << "write: " << filename+".ply" << endl;
  42.     }
  43.    
  44.     else if(extname == ".ply")
  45.     {
  46.         int ret = plyreader.read(name, cloud2);
  47.         if (ret == -1) //* load the file
  48.         {
  49.             PCL_ERROR ("Couldn't read ply file \n");
  50.             return (-1);
  51.         }
  52.         pcdwriter.writeASCII(filename+".pcd", cloud2);
  53.         cout << "write: " << filename+".pcd" << endl;
  54.     }
  55.    
  56.     else cout << "please choose .pcd or .ply file" << endl;

  57.     return 0;
  58. }
复制代码


奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表