main.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <boost/program_options.hpp>
  2. #include <pcl/point_types.h>
  3. #include <pcl/io/pcd_io.h>
  4. #include <pcl/common/point_operators.h>
  5. #include <pcl/common/io.h>
  6. #include <pcl/search/organized.h>
  7. #include <pcl/search/octree.h>
  8. #include <pcl/search/kdtree.h>
  9. #include <pcl/features/normal_3d_omp.h>
  10. #include <pcl/filters/conditional_removal.h>
  11. #include <pcl/segmentation/sac_segmentation.h>
  12. #include <pcl/segmentation/extract_clusters.h>
  13. #include <pcl/surface/gp3.h>
  14. #include <pcl/io/vtk_io.h>
  15. #include <pcl/filters/voxel_grid.h>
  16. #include <iostream>
  17. #include <fstream>
  18. using namespace pcl;
  19. using namespace std;
  20. namespace po = boost::program_options;
  21. //i=1;for x in ./*.bin; do ./build/bin2pcd --infile $x --outfile ./$i.pcd; let i=i+1; done
  22. int main(int argc, char **argv){
  23. ///The file to read from.
  24. string infile;
  25. ///The file to output to.
  26. string outfile;
  27. // Declare the supported options.
  28. po::options_description desc("Program options");
  29. desc.add_options()
  30. //Options
  31. ("infile", po::value<string>(&infile)->required(), "the file to read a point cloud from")
  32. ("outfile", po::value<string>(&outfile)->required(), "the file to write the DoN point cloud & normals to")
  33. ;
  34. // Parse the command line
  35. po::variables_map vm;
  36. po::store(po::parse_command_line(argc, argv, desc), vm);
  37. // Print help
  38. if (vm.count("help"))
  39. {
  40. cout << desc << "\n";
  41. return false;
  42. }
  43. // Process options.
  44. po::notify(vm);
  45. // load point cloud
  46. fstream input(infile.c_str(), ios::in | ios::binary);
  47. if(!input.good()){
  48. cerr << "Could not read file: " << infile << endl;
  49. exit(EXIT_FAILURE);
  50. }
  51. input.seekg(0, ios::beg);
  52. pcl::PointCloud<PointXYZI>::Ptr points (new pcl::PointCloud<PointXYZI>);
  53. int i;
  54. for (i=0; input.good() && !input.eof(); i++) {
  55. PointXYZI point;
  56. input.read((char *) &point.x, 3*sizeof(float));
  57. input.read((char *) &point.intensity, sizeof(float));
  58. points->push_back(point);
  59. std::cout<<" x: "<<point.x<<" y: "<<point.y<<std::endl;
  60. }
  61. input.close();
  62. cout << "Read KTTI point cloud with " << i << " points, writing to " << outfile << endl;
  63. pcl::PCDWriter writer;
  64. // Save DoN features
  65. writer.write<PointXYZI> (outfile, *points, false);
  66. }