1

I have 2 rosbags, one with camera data, the other with lidar data, and I want to synchronize the topics listed below to get something like a kitti dataset.

Topics Types Message Count Frequency
/os_cloud_node/points sensor_msgs/PointCloud2 3111 20.115842
/cam/realsense_d435_1/color/image_raw sensor_msgs/Image 1488 12.216965

I tried to sync data using frequency (scripts below). I know that my simplification greatly distorts the result of these operations and my data is very quickly mismatched.

How should I do it correctly using timestamps? I don't really know how to compare them when they come in different frequencies and as very small numbers.

camera_loader.py

import rosbag
from helper import convert2image

bag = rosbag.Bag('data/cam2.bag')
print("# File content:")
print(bag.get_type_and_topic_info())

messages = bag.read_messages(topics=["/cam/realsense_d435_1/color/image_raw"])

name=0

for msg in messages:
    tittle="raw_images/"+f"{name:06d}" +".png"
    name=name+1
    print(tittle)
    i =convert2image(msg.message)
    i.save(tittle)

lidar_loader.py

import rosbag
import open3d as o3d
from helper import convert2pointcloud

bag = rosbag.Bag('data/lidar2.bag')

print("# File content:")
print(bag.get_type_and_topic_info())
messages = bag.read_messages(topics=["/os_cloud_node/points"])

name=0
counter=0

for msg in messages:
    if counter % 2 == 0:
        tittle = "lidar_points/"+f"{name:06d}"+".pcd"
        print(tittle)
        name = name+1
        pcd = convert2pointcloud(msg)
        o3d.io.write_point_cloud(tittle, pcd, write_ascii=False, compressed=False, print_progress=False)
    counter=counter+1
speszal
  • 51
  • 1
  • 5

0 Answers0