【问题标题】:How do you split a rosbag into several files without calling rosbag filter multiple times?如何在不多次调用 rosbag 过滤器的情况下将 rosbag 拆分为多个文件?
【发布时间】:2018-01-31 15:09:23
【问题描述】:

我想将一个 100-GB 的 rosbag 分成 100 个 1-GB 的包。我尝试使用 rosbag 过滤器,但它需要很长时间,因为我必须手动运行每个过滤器,并且每次它都会扫描整个袋子。有没有更好的方法来执行这种拆分(通过命令行或 Python 脚本)?

【问题讨论】:

    标签: ros


    【解决方案1】:

    您可以简单地使用这样的函数将您的包文件分成块:

    import rosbag
    
    def extract_chunks(file_in, chunks):
        bagfile = rosbag.Bag(file_in)
        messages = bagfile.get_message_count()
        m_per_chunk = int(round(float(messages) / float(chunks)))
        chunk = 0
        m = 0
        outbag = rosbag.Bag("chunk_%04d.bag" % chunk, 'w')
        for topic, msg, t in bagfile.read_messages():
            m += 1
            if m % m_per_chunk == 0:
                outbag.close()
                chunk += 1
                outbag = rosbag.Bag("chunk_%04d.bag" % chunk, 'w')
            outbag.write(topic, msg, t)
        outbag.close()
    

    请注意,此方法使用消息的数量来执行拆分,因此生成的块包文件不一定具有相同的大小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-25
      • 2020-01-06
      • 2021-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多