点云.PCD格式转为KITTI数据集格式的.bin

采用ubuntu18.04+PCL

代码如下:

#include <omp.h>
#include <ctime>
#include <vector>
#include <string>
#include <algorithm>
#include <pcl/io/pcd_io.h>
#include <pcl/common/common_headers.h>
#include <sys/stat.h>
#include <pcl/io/boost.h>
#include <boost/program_options.hpp>
#include <fstream>
void convertPCDtoBin(std::string &in_file, std::string& out_file)
{
	std::cout << "2 "<< std::endl;
	pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>);
      

	if (pcl::io::loadPCDFile<pcl::PointXYZI>(in_file, *cloud) == -1) //* load the file
	{
                 
		std::string err = "Couldn't read file " + in_file;
		std::cout << "4 "<< std::endl;
		PCL_ERROR(err.c_str());
		std::cout << "5 "<< std::endl;
		return;// (-1);
	}
	std::cout << "Loaded "
		<< cloud->width * cloud->height
		<< " data points from "
		<< in_file
		<< " with the following fields: "
		<< std::endl;
        
        std::string out_file1 = out_file + ".bin";
	std::ofstream myFile(out_file1.c_str(), std::ios::out | std::ios::binary);
	for (int j = 0; j < cloud->size(); j++) {
             std::cout << "3 "<< std::endl;
		myFile.write((char*)& cloud->at(j).x, sizeof(cloud->at(j).x));
		myFile.write((char*)& cloud->at(j).y, sizeof(cloud->at(j).y));
		myFile.write((char*)& cloud->at(j).z, sizeof(cloud->at(j).z));
		myFile.write((char *)& cloud->at(j).intensity, sizeof(cloud->at(j).intensity));
		//myFile << cloud->at(j).x << " " << cloud->at(j).y << " " << cloud->at(j).z << endl;
		std::cout << "4 "<< std::endl;
	}
	//myFile.write(reinterpret_cast<char*>(myFile),nume*7sizeof(float));
	myFile.close();
	std::cout << "5 "<< std::endl;
}
int main(int argc, char **argv)
{
  
	std::string path_input = "/home/*****/pcd2bin/pcd/000005.pcd";
	std::string path_output= "/home/*****/pcd2bin/bin/00.txt";#这里就是需要一个文件来存储
#二进制文件,等代码运行完成后就自动生成为.bin文件了
std::cout << "1 "<< std::endl;
	convertPCDtoBin(path_input,path_output);

}

CMakeLists.txt就和常规使用的一样。

cd build
cmake ..
make
./pcd2bin

需要改的就是path_input和path_output了。

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值