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

Rosbag 制作 TUM数据集

 Rosbag 制作 TUM数据集

一、创建rgb和depth文件夹和txt文件

mkdir rgb
mkdir depth
touch rgb.txt
touch depth.txt

二、替换 bag 路径 和 topic

tum.py:

import os
import cv2
import numpy as np
import rosbag
from sensor_msgs.msg import Image
from cv_bridge import CvBridge# 定义文件路径
script_dir = os.getcwd()
rgb_path = os.path.join(script_dir, 'rgb')
depth_path = os.path.join(script_dir, 'depth')# 创建 CvBridge 实例
bridge = CvBridge()# 定义常量
DEPTH_ENCODING = '32FC1'
DEPTH_NORMALIZE_MIN = 0.0
DEPTH_NORMALIZE_MAX = 1.0
DEPTH_SCALE = 65535num = 1
rgb_width = None
rgb_height = None# 确保文件夹存在
if not os.path.exists(rgb_path):os.makedirs(rgb_path)
if not os.path.exists(depth_path):os.makedirs(depth_path)with rosbag.Bag(os.path.join(script_dir, 'image.bag'), 'r') as bag:  #bag路径with open(os.path.join(script_dir, 'depth.txt'), 'w') as depth_time_file, open(os.path.join(script_dir, 'rgb.txt'), 'w') as rgb_time_file:for topic, msg, t in bag.read_messages():if topic == "/camera/depth/image_raw": #depth topiccv_image = bridge.imgmsg_to_cv2(msg, desired_encoding=DEPTH_ENCODING)# 将深度图像范围归一化到0-1之间cv_image_normalized = cv2.normalize(cv_image, None, DEPTH_NORMALIZE_MIN, DEPTH_NORMALIZE_MAX, cv2.NORM_MINMAX)# 获取深度图像尺寸depth_height, depth_width = cv_image_normalized.shapeif rgb_width is not None and rgb_height is not None:# 调整深度图像尺寸为与彩色图像相同cv_image_normalized = cv2.resize(cv_image_normalized, (rgb_width, rgb_height), interpolation=cv2.INTER_LINEAR)# 将深度图像范围扩展到0-65535并转换为16位无符号整数(CV_16U)cv_image_mono16 = (cv_image_normalized * DEPTH_SCALE).astype(np.uint16)# 保存深度图像image_name = str(num) + '.png'cv2.imwrite(os.path.join(depth_path, image_name), cv_image_mono16)# 写入深度图像的时间戳timestr = "%.8f" % msg.header.stamp.to_sec()depth_time_file.write(timestr + " depth/" + image_name + "\n")if topic == "/camera/rgb/image_raw":  #rgb topiccv_image = bridge.imgmsg_to_cv2(msg, "bgr8")rgb_height, rgb_width, _ = cv_image.shape# 进行深度图像几何校正和对齐操作,使其与彩色图像对齐# 保存彩色图像image_name = str(num) + '.png'cv2.imwrite(os.path.join(rgb_path, image_name), cv_image)# 写入彩色图像的时间戳timestr = "%.8f" % msg.header.stamp.to_sec()rgb_time_file.write(timestr + " rgb/" + image_name + "\n")num += 1

三、开始转换

1.生成图片和txt

python tum.py

2.使用官方脚本得到associate.txt文件

python3 associate.py rgb.txt depth.txt  > associate.txt

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

相关文章:

  • 本地websocket服务端暴露至公网访问【cpolar内网穿透】
  • 男UI设计师主要是做什么的优漫教育
  • 超实用!Spring Boot 常用注解详解与应用场景
  • 【古月居《ros入门21讲》学习笔记】11_客户端Client的编程实现
  • 小程序和Vue写法的区别主要有什么不同
  • Flutter之MQTT使用
  • vr红色教育虚拟展馆全景制作提升单位品牌形象
  • 【Spring】Spring是什么?
  • 事件循环机制及常见面试题
  • 智能监控平台/视频共享融合系统EasyCVR接入RTSP协议视频流无法播放原因是什么?
  • c# statusStrip 显示电脑主机名、IP地址、MAC地址
  • Cesium.CustomShader颜色值显示错误
  • XSLVGL2.0 User Manual 页面管理器(v2.0)
  • 论文学习-Attention Is All You Need
  • Springboot 使用 RabbitMq 延迟插件 实现订单到期未支付取消订单、设置提醒消息
  • Linux安装Tesseract-OCR(操作系统CentOS)
  • pair和typedef
  • rdf-file:分布式环境下的文件处理
  • Maven下载与安装教程
  • C++(20):通过starts_with/ends_with检查字符串
  • YOLOv8+Nanodet强强联合改进标签分配:使用NanoDet动态标签分配策略,同时集成VFL全新损失,来打造新颖YOLOv8检测器
  • base64字符串转成file
  • NextJS开发:Prisma开启SQL日志输出
  • barcode.js+elementUi——实现二维码的展示——基础积累
  • vue2 el-table 封装
  • harmonyos应用开发者高级认证考试部分答案(2)
  • 【物联网与大数据应用】Hadoop数据处理
  • Kotlin学习——kt里的集合List,Set,Map List集合的各种方法之Int篇
  • docker buildx跨架构构建笔记(x86_64构建下构建aarch64镜像)
  • Sass基础知识详细讲解【附带表图】