kitti点云数据.bin转.pcd

参考大佬的代码:
https://github.com/Miranda1994/bin_to_pcd

这边我自己也记录一下

#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
    writer.write (outfile, *points, false);
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
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)

cmake .
make

编译完成后得到可执行文件,在执行

i=1;for x in /home/jie/文档/bin_to_pcd/bin/*.bin; do /home/jie/文档/bin_to_pcd/bulid/bin2pcd --infile $x --outfile /home/jie/文档/bin_to_pcd/pcd/$i.pcd; let i=i+1; done

第一部分为.bin文件地址
第二部分为cmake出来的可执行文件地址
第三部分为输出的.pcd文件地址
kitti点云数据.bin转.pcd_第1张图片
kitti点云数据.bin转.pcd_第2张图片

每个地址都使用绝对地址,不然会出现以下错误

Read KTTI point cloud with 125636 points, writing to data/1.pcd
terminate called after throwing an instance of 'pcl::IOException'
  what():  : [pcl::PCDWriter::writeASCII] Could not open file for writing!
已放弃 (核心已转储)

你可能感兴趣的:(笔记,自动驾驶)