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

C++手写PCD文件

前言

一般pcd读写只需要调pcl库接口,直接用pcl的结构写就好了

这里是不依赖pcl库的写入方法
主要是开头写一个header
注意字段大小,类型不要写错

结构定义

写入点需要与header中定义一致
这里用的RoboSense的结构写demo
加了个1字节对齐

struct PointXYZIT {float x;float y;float z;uint16_t intensity;double timestamp;
} __attribute__((packed));template <typename PointType>
class PointCloudT {public:typedef PointType PointT;typedef std::vector<PointT> VectorT;uint32_t height = 0;uint32_t width = 0;double timestamp = 0.0;uint32_t seq = 0;VectorT points;
};


代码实现

int record_pcd(PointCloudT<PointXYZIT> &point_cloud) {static int frame_id = 0;frame_id++;std::string pcd_file = "frame_" + std::to_string(frame_id) + ".pcd";int fd = open(pcd_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644);const char *pcd_header ="# .PCD v.7 - Point Cloud Data file format\n""FIELDS ""x y z intensity timestamp\n""SIZE 4 4 4 2 8\n""TYPE F F F U F\n""COUNT 1 1 1 1 1\n""WIDTH %zu\n""HEIGHT 1\n""VIEWPOINT 0 0 0 1 0 0 0\n""POINTS %zu\n""DATA binary\n";char header_buffer_[400];memset(header_buffer_, 0, sizeof(header_buffer_));uint64_t write_size =snprintf(header_buffer_, sizeof(header_buffer_), pcd_header, point_cloud.width, point_cloud.width);assert(write_size > 0 && write_size < sizeof(header_buffer_));int r = write(fd, header_buffer_, write_size);assert(r >= 0);for (int i = 0; i < point_cloud.width; i++) {r = write(fd, &point_cloud.points[i], sizeof(PointXYZIT));assert(r >= 0);}close(fd);fd = -1;return 0;
}


验证方法

可用pcl_viewer工具,打开写入的文件
或者用CloudCompare打开

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

相关文章:

  • 优选算法(双指针)
  • 【保姆级】Mac上IDEA卡顿优化
  • python实战案例----使用 PyQt5 构建简单的 HTTP 接口测试工具
  • pytest 接口串联场景
  • Springboot项目搭建(2)-用户详细信息查询
  • Stable Diffusion的加噪和去噪详解
  • 解决 Gradle 报错:`Plugin with id ‘maven‘ not found` 在 SDK 开发中的问题
  • EMD-KPCA-Transformer多变量回归预测!分解+降维+预测!多重创新!直接写核心!
  • 前端 px、rpx、em、rem、vh、vw计量单位的区别
  • OceanBase数据库产品与工具介绍
  • 学习threejs,对模型多个动画切换展示
  • 【Bug合集】——Java大小写引起传参失败,获取值为null的解决方案
  • Python爬虫:如何从1688阿里巴巴获取公司信息
  • 单片机学习笔记 2. LED灯闪烁
  • 折叠光腔衰荡高反射率测量技术的matlab模拟理论分析
  • ubuntu 16.04 中 VS2019 跨平台开发环境配置
  • C语言第13节:指针(3)
  • java:简单小练习,面积
  • @Autowired 和 @Resource思考(注入redisTemplate时发现一些奇怪的现象)
  • PostgreSQL提取JSON格式的数据(包含提取list指定索引数据)
  • 如何利用谷歌浏览器提高网络安全
  • go-zero(四) 错误处理(统一响应信息)
  • 1.1 爬虫的一些知识(大模型提供语料)
  • Linux开发工具:Vim 与 gcc,打造高效编程的魔法双剑
  • cesium for unity的使用
  • Android AOSP 架构和各层次开发内容介绍
  • Kafka 到 Kafka 数据同步
  • 华为刷题笔记--题目索引
  • osgEarth加载倾斜摄影测量数据
  • 消息推送问题梳理-团队管理