申明:再找到一款点云标注工具(https://blog.csdn.net/r1141207831/article/details/103788891)的时候发现只能输入pcd文件,那么现有的bin文件无法使用,于是找到了bin文件转换为pcd文件的方法,现在分享出来和大家一起讨论学习,如有问题可以留言评论。也感谢那些默默支持和帮助的人。
程序运行环境:
运行系统:Ubuntu16.04
一、新建如下目录结构的文件夹以及文件
-
PointCloud
-
└── bin2pcd
-
├── bin2pcd.cpp
-
├── build
-
├── CMakeLists.txt
-
├── run.sh
-
└── velodyne
-
├──
bin
-
└── pcd
二、填充文件代码
1 bin2pcd.cpp代码如下所示:
*斜体样式*
-
#include <boost/program_options.hpp>
-
#include <pcl/point_types.h>
-
#include <pcl/io/pcd_io.h>
-
#include <pcl/common/point_operators.h>
-
#include <pcl/common/io.h>
-
#include <pcl/search/organized.h>
-
#include <pcl/search/octree.h>
-
#include <pcl/search/kdtree.h>
-
#include <pcl/features/normal_3d_omp.h>
-
#include <pcl/filters/conditional_removal.h>
-
#include <pcl/segmentation/sac_segmentation.h>
-
#include <pcl/segmentation/extract_clusters.h>
-
#include <pcl/surface/gp3.h>
-
#include <pcl/io/vtk_io.h>
-
#include <pcl/filters/voxel_grid.h>
-
-
#include <iostream>
-
#include <fstream>
-
-
using
namespace pcl;
-
using
namespace std;
-
-
namespace po = boost::program_options;
-
-
int main(int argc, char **argv){
-
///The file to read from.
-
string infile;
-
-
///The file to output to.
-
string outfile;
-
-
// Declare the supported options.
-
po::options_description desc("Program options");
-
desc.
add_options()
-
//Options
-
(
"infile", po::
value<string>(&infile)->
required(),
"the file to read a point cloud from")
-
(
"outfile", po::
value<string>(&outfile)->
required(),
"the file to write the DoN point cloud & normals to")
-
;
-
// Parse the command line
-
po::variables_map vm;
-
po::
store(po::
parse_command_line(argc, argv, desc), vm);
-
-
// Print help
-
if (vm.
count(
"help"))
-
{
-
cout << desc <<
"\n";
-
return
false;
-
}
-
-
// Process options.
-
po::
notify(vm);
-
-
// load point cloud
-
fstream input(infile.c_str(), ios::in | ios::binary);
-
if(!input.
good()){
-
cerr <<
"Could not read file: " << infile << endl;
-
exit(EXIT_FAILURE);
-
}
-
input.
seekg(
0, ios::beg);
-
-
pcl::PointCloud<PointXYZI>::
Ptr points (new pcl::PointCloud<PointXYZI>);
-
-
int i;
-
for (i=
0; input.
good() && !input.
eof(); i++) {
-
PointXYZI point;
-
input.
read((
char *) &point.x,
3*
sizeof(
float));
-
input.
read((
char *) &point.intensity,
sizeof(
float));
-
points->
push_back(point);
-
}
-
input.
close();
-
-
cout <<
"Read KTTI point cloud with " << i <<
" points, writing to " << outfile << endl;
-
-
pcl::PCDWriter writer;
-
-
// Save DoN features
-
writer.
write<PointXYZI> (outfile, *points,
false);
-
}
2 CMakeLists.txt代码如下所示:
-
cmake_minimum_required(VERSION 3.5)
-
project
(bin2pcd)
-
-
find_package
(PCL 1.2 REQUIRED)
-
-
find_package
(Boost COMPONENTS program_options REQUIRED )
-
include_directories
(${Boost_INCLUDE_DIRS})
-
link_directories
(${Boost_LIBRARY_DIRS})
-
-
include_directories
(${PCL_INCLUDE_DIRS})
-
link_directories
(${PCL_LIBRARY_DIRS})
-
add_definitions
(${PCL_DEFINITIONS})
-
-
add_executable
(bin2pcd bin2pcd.cpp)
-
-
target_link_libraries
(bin2pcd ${PCL_LIBRARIES} ${Boost_LIBRARIES})
-
-
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文件夹下,输入以下命令进行编译
-
cd build
-
cmake ..
-
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