.bin转pcd(注释掉bin2pcd.cpp第四行,否则编译时出错,提示point_operators.h找不到)

申明:再找到一款点云标注工具(https://blog.csdn.net/r1141207831/article/details/103788891)的时候发现只能输入pcd文件,那么现有的bin文件无法使用,于是找到了bin文件转换为pcd文件的方法,现在分享出来和大家一起讨论学习,如有问题可以留言评论。也感谢那些默默支持和帮助的人。


程序运行环境:

  运行系统:Ubuntu16.04


一、新建如下目录结构的文件夹以及文件


   
   
  1. PointCloud
  2. └── bin2pcd
  3. ├── bin2pcd.cpp
  4. ├── build
  5. ├── CMakeLists.txt
  6. ├── run.sh
  7. └── velodyne
  8. ├── bin
  9. └── pcd

二、填充文件代码

 1 bin2pcd.cpp代码如下所示:

*斜体样式*

   
   
  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. int main(int argc, char **argv){
  22. ///The file to read from.
  23. string infile;
  24. ///The file to output to.
  25. string outfile;
  26. // Declare the supported options.
  27. po::options_description desc("Program options");
  28. desc. add_options()
  29. //Options
  30. ( "infile", po:: value<string>(&infile)-> required(), "the file to read a point cloud from")
  31. ( "outfile", po:: value<string>(&outfile)-> required(), "the file to write the DoN point cloud & normals to")
  32. ;
  33. // Parse the command line
  34. po::variables_map vm;
  35. po:: store(po:: parse_command_line(argc, argv, desc), vm);
  36. // Print help
  37. if (vm. count( "help"))
  38. {
  39. cout << desc << "\n";
  40. return false;
  41. }
  42. // Process options.
  43. po:: notify(vm);
  44. // load point cloud
  45. fstream input(infile.c_str(), ios::in | ios::binary);
  46. if(!input. good()){
  47. cerr << "Could not read file: " << infile << endl;
  48. exit(EXIT_FAILURE);
  49. }
  50. input. seekg( 0, ios::beg);
  51. pcl::PointCloud<PointXYZI>:: Ptr points (new pcl::PointCloud<PointXYZI>);
  52. int i;
  53. for (i= 0; input. good() && !input. eof(); i++) {
  54. PointXYZI point;
  55. input. read(( char *) &point.x, 3* sizeof( float));
  56. input. read(( char *) &point.intensity, sizeof( float));
  57. points-> push_back(point);
  58. }
  59. input. close();
  60. cout << "Read KTTI point cloud with " << i << " points, writing to " << outfile << endl;
  61. pcl::PCDWriter writer;
  62. // Save DoN features
  63. writer. write<PointXYZI> (outfile, *points, false);
  64. }

 2 CMakeLists.txt代码如下所示:


   
   
  1. cmake_minimum_required(VERSION 3.5)
  2. project (bin2pcd)
  3. find_package (PCL 1.2 REQUIRED)
  4. find_package (Boost COMPONENTS program_options REQUIRED )
  5. include_directories (${Boost_INCLUDE_DIRS})
  6. link_directories (${Boost_LIBRARY_DIRS})
  7. include_directories (${PCL_INCLUDE_DIRS})
  8. link_directories (${PCL_LIBRARY_DIRS})
  9. add_definitions (${PCL_DEFINITIONS})
  10. add_executable (bin2pcd bin2pcd.cpp)
  11. target_link_libraries (bin2pcd ${PCL_LIBRARIES} ${Boost_LIBRARIES})
  12. install (TARGETS bin2pcd RUNTIME DESTINATION bin)

 3 run.sh代码如下所示:

i=1; for x in $(cd "$(dirname "$0")"; pwd)/velodyne/bin/*bin; do $(cd "$(dirname "$0")"; pwd)/build/bin2pcd --infile $x --outfile $(cd "$(dirname "$0")"; pwd)/velodyne/pcd/$i.pcd; let i=i+1; done
   
   

三、编译程序

 启动终端切换目录到build文件夹下,输入以下命令进行编译


   
   
  1. cd build
  2. cmake ..
  3. make

四、执行转换程序

 1  将需要转换的bin文件复制到velodyne目录下的bin文件夹下

 2 使用下面命令为run.sh文件赋予可执行权限

sudo chmod a+x run.sh
   
   

 3  切换到run.sh文件目录下,执行以下命令开始bin转换pcd程序

sh run.sh
   
   

至此该过程已经全部走完,现在可以到velodyne目录下的pcd文件夹下查看已经转换好的pcd文件了。


附录:

bash 中sh脚本自身路径的获取 https://blog.csdn.net/zhml8951/article/details/51669401

ubuntu16.04下用pcl库将点云bin文件转成pcd文件 https://blog.csdn.net/qq_35491306/article/details/82903371

kitti2pcd.cpp https://github.com/yanii/kitti-pcl/blob/master/src/kitti2pcd.cpp

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值