当前位置: 首页 > news >正文

KITTI数据集中的二进制激光雷达数据(.bin文件)转换为点云数据(.pcd文件)(C++代码)

目录

main.cpp

CMakeLists.txt


main.cpp

#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <fstream>
#include <iostream>
#include <vector>int main() {// Define file pathsstd::string input_filename = "/home/fairlee/KITTI/2011_09_26_drive_0011_sync/velodyne_points/data/0000000000.bin";std::string output_filename = "/home/fairlee/KITTI/2011_09_26_drive_0011_sync/velodyne_points/data/0000000000.pcd";// Open the binary filestd::ifstream input_file(input_filename, std::ios::binary);if (!input_file.good()) {std::cerr << "Error: Could not read file: " << input_filename << std::endl;return -1;}// Define point cloud objectpcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(new pcl::PointCloud<pcl::PointXYZI>);// Read points from bin fileint i = 0;while (input_file.good() && !input_file.eof()) {pcl::PointXYZI point;input_file.read(reinterpret_cast<char*>(&point.x), sizeof(float));input_file.read(reinterpret_cast<char*>(&point.y), sizeof(float));input_file.read(reinterpret_cast<char*>(&point.z), sizeof(float));input_file.read(reinterpret_cast<char*>(&point.intensity), sizeof(float));point_cloud->points.push_back(point);i++;}input_file.close();// Set additional point cloud propertiespoint_cloud->width = i;point_cloud->height = 1;  // 1 for unorganized point cloudpoint_cloud->is_dense = true;// Save the point cloud to a PCD filepcl::io::savePCDFileASCII(output_filename, *point_cloud);std::cerr << "Saved " << point_cloud->points.size() << " data points to " << output_filename << std::endl;return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.17)
project(TEST2)set(CMAKE_CXX_STANDARD 14)# Find PCL
find_package(PCL 1.8 REQUIRED)# If PCL was found, add its include directories to the project
if(PCL_FOUND)include_directories(${PCL_INCLUDE_DIRS})link_directories(${PCL_LIBRARY_DIRS})add_definitions(${PCL_DEFINITIONS})
else()message(FATAL_ERROR "PCL not found.")
endif()add_executable(TEST2 main.cpp)# Link PCL libraries to the project
target_link_libraries(TEST2 ${PCL_LIBRARIES})

 

http://www.lryc.cn/news/190543.html

相关文章:

  • 全球AI人工智能领袖:Anthropic联合创始人丹妮拉·阿莫迪!
  • CoT 的方式使用 LLM 设计测试用例实践
  • 神秘的锦衣卫
  • Springboot中使用Redis
  • 超声波波形生成电路设计
  • C#和JS交互之Microsoft.ClearScript.V8(V8引擎)
  • 9月活动回顾(免费领取PPT)|火山引擎DataLeap、ByteHouse多位专家带来DataOps、实时计算等前沿技术分享!
  • salesforce的按钮执行js代码如何链接到apex代码
  • C语言 —— 操作符
  • 物联网AI MicroPython传感器学习 之 CCS811空气质量检测传感器
  • TCP/IP(十五)拥塞控制
  • vue3 404解决方法
  • Unity中使用Xlua调用lua相关
  • 基于http的protobuf服务实现
  • 基于uniapp的商城外卖小程序
  • 【CSS】Tailwind CSS
  • leetcode-电话号码组合(C CODE)
  • Leetcode92. 反转链表 II
  • 【算法作业记录】
  • 回归预测、分类预测、时间序列预测 都有什么区别?
  • 关于网络协议的若干问题(三)
  • 办公室人人在用的iTab桌面真的好用吗?
  • 循环中的else语句
  • 三.镜头知识之FOV
  • 分布式事务入门
  • Ubuntu的中文乱码问题
  • [GXYCTF2019]Ping Ping Ping - RCE(空格、关键字绕过[3种方式])
  • ceph 分布式存储与部署
  • Go 结构体深度探索:从基础到应用
  • 分布式系统开发技术中的CAP定理原理