KITTI Odometry中的bin文件转pcd文件

比较简单,直接上代码~

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);
}

使用方法

i=1;for x in velodyne_points/data/*.bin; do build/bin/kitti2pcd --infile $x --outfile data/$i.pcd; let i=i+1; done

<think>嗯,用户想了解如何使用FastLIO保存PCD文件。我之前看过一些相关的引用资料,需要整理一下。首先,根据引用[3],FAST-LIO2运行时可能无法进入保存PCD的函数,特别是当数据话题不是原始的livox/lidar和livox/imu时。这可能是因为代码中保存PCD的功能依赖于特定的话题名称。引用[4]提到需要修改laserMapping.cpp文件,替换代码并设置正确的路径。还有引用[2]提到在map_incremental中有保存每一帧PCD的代码,可以利用这部分代码。 那具体步骤应该是怎样的呢?首先,用户可能需要检查源码中的相关部分,比如lasermapping.cpp里的save_pcd_en部分,确保保存功能被正确触发。然后,修改话题名称或者调整代码逻辑,使得即使话题名称不同也能保存。另外,路径设置是否正确也很重要,需要用户更改为自己电脑上的有效路径。 用户可能需要知道如何修改源代码,添加保存PCD的功能。比如在激光雷达数据处理的回调函数里,当接收到新数据时,将点云写入PCD文件。同时,保存位姿信息到txt文件,这可能需要访问里程计的输出数据。 还要注意,FAST-LIO2可能默认不开启保存功能,所以需要手动启用。比如检查是否有控制保存的变量,如save_pcd_en,并确保其设置为true。此外,编译安装修改后的代码也是必须的,用户需要重新编译项目以使更改生效。 可能遇到的问题包括:代码修改后没有进入保存函数,话题名称不匹配导致数据无法获取,路径权限问题导致无法写入文件。用户需要根据实际情况调试,比如添加打印语句确认代码执行流程,检查话题名称是否正确,确保目标目录存在且有写入权限。 总结步骤应该是:1. 定位保存功能的源码部分;2. 修改代码以正确触发保存,设置路径;3. 处理话题名称问题;4. 编译运行并测试。同时,引用相关的参考资料来支持每一步的操作,比如引用[4]中的代码修改示例。</think>### FastLIO保存PCD文件的方法及实现 #### 一、核心问题分析 FastLIO默认未直接提供保存PCD文件的功能,但可通过源码修改实现。其核心在于处理激光雷达数据的回调函数和位姿输出模块。根据实际应用场景,需要解决以下问题: 1. **数据接口匹配**:原始代码可能未适配特定设备(如Mid360)的话题名称,导致无法触发保存逻辑[^3] 2. **文件写入路径**:需确保代码中指定的保存路径具有可写权限且格式正确[^4] 3. **触发时机控制**:应在激光雷达数据处理完毕后立即保存当前帧数据 #### 二、实现步骤详解 1. **源码定位** 在`laserMapping.cpp`中找到数据处理主循环,通常位于`void LaserMapping::run(...)`函数中。插入以下代码片段: ```cpp if(save_pcd_en){ std::string pcd_path = "/your/path/frame_" + std::to_string(frame_num) + ".pcd"; pcl::io::savePCDFileBinary(pcd_path, *current_cloud); frame_num++; } ``` 注意将`/your/path/`替换为实际存储路径[^4] 2. **话题适配修改** 若使用Mid360设备,需将话题订阅改为设备原始输出: ```cpp // 原始代码 subscribeLaserCloud_ = nh.subscribe<livox_ros_driver::CustomMsg>("/livox/lidar", 100, &LaserMapping::cloudHandler, this); // 修改为Mid360话题 subscribeLaserCloud_ = nh.subscribe<livox_ros_driver::CustomMsg>("/livox_ros_driver/livox/lidar", 100, &LaserMapping::cloudHandler, this); ``` 3. **位姿保存实现** 在状态估计完成后的位置添加位姿记录: ```cpp std::ofstream odom_file("/your/path/odometry.txt", std::ios::app); odom_file << state_estimation.pos.x() << " " << state_estimation.pos.y() << " " << state_estimation.pos.z() << "\n"; odom_file.close(); ``` #### 三、验证与调试 1. **编译配置** ```bash cd ~/catkin_ws catkin_make -DCMAKE_BUILD_TYPE=Release ``` 2. **运行检测** ```bash roslaunch fast_lio mapping_mid360.launch ``` 观察终端输出是否包含`Saving PCD to...`提示信息 3. **常见问题处理: - **文件未生成**:检查路径权限`chmod 777 /your/path` - **数据错位**:确认时间戳同步机制正常工作 - **内存溢出**:添加`cloud->points.shrink_to_fit()`优化点云存储
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值