记录个人工作日志。恳求大佬指点简单的方法!!
1. <利用ros记录话题,获得bag文件>
首先launch相机节点:
roslaunch realsense2_camera rs_camera.launch
rosbag获得.bag 文件:
(xxx为.bag文件的命名,后面两个是相机的rgb和depth话题)
rosbag record -O xxx /camera/color/image_raw /camera/depth/image_rect_raw
2. <使用Python代码将bag文件转成图片png输出>
注意是Python2代码。
更改输出路径和.bag文件路径
# -*- coding: UTF-8 -*- import numpy import rosbag import cv2 import os from sensor_msgs.msg import Image from cv_bridge import CvBridge from cv_bridge import CvBridgeError rgb_path = '/home/zzj/dataset/bagfiles/rgb_images/' # absolute path of extracted rgb images depth_path = '/home/zzj/dataset/bagfiles/depth_images/' # absolute path of extracted depth images bridge = CvBridge() with rosbag.Bag('/home/zzj/dataset/bagfiles/1220.bag', 'r') as bag: num = 1 for topic,msg,t in bag.read_messages(): if topic =="/camera/depth/image_rect_raw": #if topic == "/camera/depth/image_rect_raw": cv_image = bridge.imgmsg_to_cv2(msg, '32FC1') cv_image = cv_image * 255 # 不知为何转化的深度图显示不出来。将其乘以 255 才能看到显示效果. # timestr = "%.8f" % msg.header.stamp.to_sec() # 时间戳命名 # image_name = timestr + '.png'# an extension is necessary image_name = str(num) + '.png'# 编号命名 cv2.imwrite(depth_path + image_name, cv_image) # 实际应用可直接保存为 numpy array # np.save(depth_path + image_name, cv_image) print(depth_path + image_name) if topic == "/camera/color/image_raw": cv_image = bridge.imgmsg_to_cv2(msg, "bgr8") timestr = "%.8f" % msg.header.stamp.to_sec() image_name = str(num) + '.png' cv2.imwrite(rgb_path + image_name, cv_image) num += 1
3. <使用Python代码制作数据集获得rgb.txt和depth.txt文件>
4. <使用associate.py将rgb.txt数据和depth.txt数据融合
编译png_to_klg将数据集转为klg格式>
详情可见下方链接
./associate.py depth.txt rgb.txt > associations.txt
将TUM数据集的RGB-D数据集转化为klg格式 - Ponder-Lee - 博客园
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)