KITTI的LiDAR型号为 Velodyne HDL-64E ,参数如下:
Velodyne HDL-64E rotating 3D laser scanner
- 10 Hz
- 64 beams
- 0.09 degree angular resolution
- 2 cm distanceaccuracy
- collecting∼1.3 million points/second
- field of view: 360°
- horizontal, 26.8°
- vertical, range: 120 m
Readme文档:
Velodyne 3D laser scan data
===========================
The velodyne point clouds are stored in the folder 'velodyne_points'. To
save space, all scans have been stored as Nx4 float matrix into a binary
file using the following code:
stream = fopen (dst_file.c_str(),"wb");
fwrite(data,sizeof(float),4*num,stream);
fclose(stream);
Here, data contains 4*num values, where the first 3 values correspond to
x,y and z, and the last value is the reflectance information. All scans
are stored row-aligned, meaning that the first 4 values correspond to the
first measurement. Since each scan might potentially have a different
number of points, this must be determined from the file size when reading
the file, where 1e6 is a good enough upper bound on the number of values:
// allocate 4 MB buffer (only ~130*4*4 KB are needed)
int32_t num = 1000000;
float *data = (float*)malloc(num*sizeof(float));
// pointers
float *px = data+0;
float *py = data+1;
float *pz = data+2;
float *pr = data+3;
// load point cloud
FILE *stream;
stream = fopen (currFilenameBinary.c_str(),"rb");
num = fread(data,sizeof(float),num,stream)/4;
for (int32_t i=0; i
1.建立工作空间
$ mkdir -p transform/bin2pcd/src
2.创建程序包
$ cd transform/bin2pcd/src
$ catkin_create_pkg kitti_velodyne pcl_ros roscpp
3.创建bin2pcd.cpp
$ cd
$ cd transform/bin2pcd/src/kitti_velodyne/src
$ touch bin2pcd.cpp
写入以下代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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(&infile)->required(), "the file to read a point cloud from")
("outfile", po::value(&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::Ptr points (new pcl::PointCloud);
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
pcl::io::savePCDFileBinary(outfile, *points);
//writer.write (outfile, *points, false);
}
4.修改CMakeLists.txt
将kitti_velodyne文件夹中的CMakeLists.txt文件修改如下:
cmake_minimum_required(VERSION 2.8.3)
project(kitti_velodyne)
add_compile_options(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
pcl_ros
roscpp
)
find_package(PCL 1.7 REQUIRED)
catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS roscpp pcl_ros
)
include_directories(
include
${catkin_INCLUDE_DIRS}
)
link_directories(${PCL_LIBRARY_DIRS})
add_executable(bin2pcd src/bin2pcd.cpp)
target_link_libraries(bin2pcd
${catkin_LIBRARIES}
${PCL_LIBRARIES}
)
5.编译
$ cd
$ cd transform/bin2pcd
$ catkin_make
编译通过后如图所示
6.运行
在 transform/bin2pcd 下新建文件夹bin和pcd分别存放bin文件和转换完成的pcd文件
终端输入:
i=1;
for x in /home/song/transform/bin2pcd/bin/*.bin;
do /home/song/transform/bin2pcd/devel/lib/kitti_velodyne/bin2pcd --infile $x --outfile /home/song/transform/bin2pcd/pcd/$i.pcd;
let i=i+1;
done
相应pcd出现在 transform/bin2pcd/pcd 文件夹下
参考资料:
https://blog.csdn.net/zengzeyu/article/details/79575702
https://blog.csdn.net/tuyim7124/article/details/88615937