欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【点云(一)】将KITTI数据集中点云文件.bin转换成.pcd

程序员文章站 2022-04-17 17:46:36
...

KITTI数据集下载:

https://pan.baidu.com/s/14WchJlcZ2guwcfbHqrdFw
密码:grys

关于KITTI数据集的介绍可以参考这篇博客:

https://blog.csdn.net/u013086672/article/details/103913361

以下部分均在点云数据集上做研究:
【点云(一)】将KITTI数据集中点云文件.bin转换成.pcd【点云(一)】将KITTI数据集中点云文件.bin转换成.pcd

在ubuntu16.04下使用pcl将.bin文件转化为.pcd文件

具体流程:home→新建文件夹PointCloud→在PointCloud文件里继续新建文件夹bin2pcd→在bin2pcd文件夹里新建velodyne、build、bin2pcd.cpp、CMakeLists.txt(在该目录下打开终端输入命令:touch bin2pcd.cpp && CMakeLists.txt)→在新建的velodyne文件里,新建bin、pcd文件夹。
详情图如下:
【点云(一)】将KITTI数据集中点云文件.bin转换成.pcd
【点云(一)】将KITTI数据集中点云文件.bin转换成.pcd
【点云(一)】将KITTI数据集中点云文件.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)
 
# 加入Boost setting
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)然后再该目录下编译

cmake .
make

【点云(一)】将KITTI数据集中点云文件.bin转换成.pcd【点云(一)】将KITTI数据集中点云文件.bin转换成.pcd
(4)继续执行

i=1;for x in /home/iv/PointCloud/bin2pcd/velodyne/bin/*.bin; do /home/iv/PointCloud/bin2pcd/build/bin2pcd --infile $x --outfile /home/iv/PointCloud/bin2pcd/velodyne/pcd/$i.pcd; let i=i+1; done

/home/iv/PointCloud/bin2pcd/velodyne/bin/*.bin:是储存 .bin文件的路径;
/home/iv/PointCloud/bin2pcd/build/bin2pcd 是可执行程序的路径;(此时需要将它移植到该路径下面)
【点云(一)】将KITTI数据集中点云文件.bin转换成.pcd
/home/iv/PointCloud/bin2pcd/velodyne/pcd/$i.pcd 是转换后的.pcd文件的路径。
【点云(一)】将KITTI数据集中点云文件.bin转换成.pcd

(5)打开点云图
可以在终端下输入命令:pcl_viewer 【pcd文件名】查看点云图
【点云(一)】将KITTI数据集中点云文件.bin转换成.pcd