【LiDAR】KITTI数据集格式、bin转pcd

KITTI数据集点云格式

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<num; i++) {
    point_cloud.points.push_back(tPoint(*px,*py,*pz,*pr));
    px+=4; py+=4; pz+=4; pr+=4;
  }
  fclose(stream);

x,y and y are stored in metric (m) Velodyne coordinates.

bin转pcd

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 <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
    pcl::io::savePCDFileBinary(outfile, *points);
    //writer.write<PointXYZI> (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

  • 12
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要将DAIR-V2X数据集换为Kitti数据集格式,你可以使用官方提供的命令行工具\[2\]。在命令行中运行以下命令: python tools/dataset_converter/dair2kitti.py --source-root ./data/DAIR-V2X/single-infrastructure-side \ --target-root ./data/DAIR-V2X/single-infrastructure-side \ --split-path ./data/split_datas/single-infrastructure-split-data.json \ --label-type lidar --sensor-view infrastructure 这个命令将会把DAIR-V2X数据集换为Kitti数据集格式,并将结果保存在指定的目标路径中。在换过程中,如果遇到错误,可能会出现一些问题。例如,你提到的错误\[3\]是由于在代码中使用了eval()函数,但是传入的参数不是一个字符串导致的。你可以检查代码中的相关部分,确保传入的参数是一个字符串。 请注意,换过程可能需要一些时间,具体取决于数据集的大小和计算机的性能。完成后,你将获得一个符合Kitti数据集格式数据集,可以在后续的任务中使用。 #### 引用[.reference_title] - *1* *2* *3* [DAIR-V2X数据集kitti数据集格式(保姆级教程)](https://blog.csdn.net/m0_57273938/article/details/126418351)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值