利用Realsense D435和Mocap制作TUM数据集

利用Realsense D435和Mocap制作TUM数据集

开门见山

步骤

  1. 如果有Mocap,根据mocap系统指示获取Groundtruth,我实验室的mocap为optitrack,使用vrpn_client_ros包获取groundtruth。具体参考这里

  2. 同时录制话题/camera/color/image_raw/camera/aligned_depth_to_color/image_raw/vrpn_client_node/RigidBody1/pose,分别为RGB数据、对齐到RGB相机后的深度图和mocap输出的真实pose。

  3. 使用以下程序一键生成TUM数据格式,前提是已经安装好ROS,注意修改代码中bag包名字、话题名和输出路径

#!/bin/python
import roslib
import rosbag
import rospy
import cv2
import os
from sensor_msgs.msg import Image
from geometry_msgs.msg import Pose, Quaternion, Point
from cv_bridge import CvBridge
from cv_bridge import CvBridgeError


ros_bag = 'sence5.bag'  #bag包路径
save_path = 'sence5/'   #输出数据集的路径
rgb = save_path + 'rgb/'  #rgb path
depth = save_path + 'depth/'   #depth path

bridge = CvBridge()

file_handle1 = open(save_path + 'rgb.txt', 'w')
file_handle2 = open(save_path + 'depth.txt', 'w')
file_handle3 = open(save_path + 'groundtruth.txt', 'w')

with rosbag.Bag(ros_bag, 'r') as bag:
    for topic,msg,t in bag.read_messages():

        if topic == "/camera/color/image_raw":   #rgb topic
            cv_image = bridge.imgmsg_to_cv2(msg,"bgr8")
            timestr = "%.6f" %  msg.header.stamp.to_sec()   #rgb time stamp
            image_name = timestr+ ".png"
            path = "rgb/" + image_name
            file_handle1.write(timestr + " " + path + '\n')
            cv2.imwrite(rgb + image_name, cv_image)

        if topic == "/camera/aligned_depth_to_color/image_raw":  #depth topic
            cv_image = bridge.imgmsg_to_cv2(msg)
            #cv_image = bridge.imgmsg_to_cv2(msg, '32FC1')
            #cv_image = cv_image * 255
            timestr = "%.6f" %  msg.header.stamp.to_sec()   #depth time stamp
            image_name = timestr+ ".png"
            path = "depth/" + image_name
            file_handle2.write(timestr + " " + path + '\n')
            cv2.imwrite(depth + image_name, cv_image)

        if topic == '/vrpn_client_node/RigidBody_ZLT_UAV/pose': #groundtruth topic
            p = msg.pose.position
            q = msg.pose.orientation
            timestr = "%.6f" %  msg.header.stamp.to_sec()
            file_handle3.write(timestr + " " + str(round(p.x, 4)) + " " + str(round(p.y, 4)) + " " + str(round(p.z, 4)) + " ")
            file_handle3.write(str(round(q.x, 4)) + " " + str(round(q.y, 4)) + " " + str(round(q.z, 4)) + " " + str(round(q.w, 4)) + '\n')
file_handle1.close()
file_handle2.close()
file_handle3.close()

  1. 值得注意的是,获取的真值pose和SLAM输出的pose不在同一个坐标系下,如果要使用自己制作的数据集并进行精度评估,则需要使用evo评估工具
  2. 使用时,由于真值pose帧率高(我这儿mocap输出是100Hz),而d435输出RGB和depth被设定为30Hz,所以两者时间戳会不同步。在使用evo工具时,则需要指定相关参数,否则评估将会出错,如下所示:
    evo_ape tum Groundtruth.txt OurCameraTrajectory.txt -p -va --save_results results/Our.zip --t_max_diff=0.05 --t_offset=0.05
    
    这儿的--t_max_diff=0.05 --t_offset=0.05-a分别表示允许的最大时间误差、时间偏移和对齐坐标系。

猜你喜欢

转载自blog.csdn.net/qq_27350133/article/details/128103921