使用PCL批量将点云.bin文件转.pcd

在这里插入图片描述

B站|公众号啥都会一点的研究生

  • 新建文件夹datasets
  • datasets文件将下新建两个文件夹binpcdbin中存放要转换的二进制文件,pcd存放转换后的点云文件
  • datasets下新建CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(bin2pcd)
 
find_package(PCL 1.2 REQUIRED)
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)
  • 新建bin2pcd.cpp
#include <boost/program_options.hpp>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/common/io.h>
#include <pcl/io/vtk_io.h>
#include <vector>
#include <iostream>
#include <fstream>

using namespace pcl;
using namespace std;

void topcd(string name);
void topcd(string infile,string outfile) {

	// 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 point cloud with " << i << " points, writing to " << outfile << endl;

	pcl::PCDWriter writer;

	// Save DoN features
	writer.write<PointXYZI>(outfile, *points, false);
}
int main(int argc, char** argv) {
    string binpath = "/home/xxxx/datasets/bin/";
    string pcdpath = "/home/xxxx/datasets/pcd/";
    vector<boost::filesystem::path> stream(boost::filesystem::directory_iterator{binpath}, boost::filesystem::directory_iterator{});
    sort(stream.begin(), stream.end());
    auto streamIterator = stream.begin();
    int j = 0;
    while(streamIterator != stream.end()){
        string binfile((*streamIterator).string());

        stringstream ss;
        string str;
        ss << setw(10) << setfill('0') << j; // 补零
        ss >> str;
        string surfix = ".pcd";
        string pcdfile = pcdpath + str + surfix;

        topcd(binfile,pcdfile);
        streamIterator++;
        j++;
    }
	return 0;
}

  • 注意仅需修改binpathpcdpath为你的路径
  • 新建build文件夹,所以现在的文件层级为这样
├── bin2pcd.cpp
├── build
├── CMakeLists.txt
└── datasets
    ├── bin
        ├── 0000000000.bin
        ├── 0000000001.bin
            ...
    └── pcd
        ├── 0000000000.bin
        ├── 0000000001.bin
            ...

  • 剩下的步骤就是正常编译,进入build文件夹
cmake .. && make -j12 
  • 然后运行文件
./bin2pcd
  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
很抱歉,我目前还没有能力提供完整的代码。但是我可以给您提供一些思路和参考资料。 基于雷达点数据进行可行驶区域点集可视化的过程可以分为以下几个步骤: 1. 读取雷达点数据 您可以使用 PCL(Point Cloud Library)库中的 PCD(Point Cloud Data)格式,或者其他一些格式(如 LAS、BIN 等)。 2. 点预处理 点预处理通常包括去噪(如使用 VoxelGrid 滤波器等)、体素网格化、下采样等操作。这可以使得点数据更加规则、易处理。 3. 地面分割 利用 RANSAC 或者其他一些算法,可以将点数据中的地面部分分离出来。地面上的点数据可以作为基础层,不参与后续的障碍物检测和可行驶区域生成。 4. 障碍物检测 在地面分割后,可以使用 PCL 中提供的各种障碍物检测算法(如 VoxelGrid 滤波器、Passthrough 滤波器、欧几里得聚类等算法)检测点数据中的障碍物。 5. 可行驶区域生成 将地面部分和障碍物部分去除,剩下的点数据就是可行驶区域部分。可以将这些点数据可视化,使用 PCL 中的可视化工具(如 PCLVisualizer)进行可视化。 除了 PCL 库之外,您还可以参考以下文章和代码: - https://github.com/xuefeng-zhu/kitti_visualization:该项目实现了从 KITTI 数据集中读取雷达点数据,并将可行驶区域点集可视化。 - https://www.cnblogs.com/-flq/p/12432531.html:这篇文章介绍了如何从 Velodyne HDL-64E 雷达输出的 pcap 文件中读取雷达点数据,并进行地面分割和障碍物检测。 - https://github.com/Slamtec/rplidar_sdk:这是 RPLIDAR 2D 激光雷达的 SDK,其中包括了如何读取雷达数据并进行预处理、地面分割和障碍物检测的示例代码。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

啥都生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值