本文主要是介绍ROS笔记之rosbag的合并与拼接merge_bag.py,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
ROS笔记之rosbag的合并与拼接merge_bag.py
代码来源:https://www.clearpathrobotics.com/assets/downloads/support/merge_bag.py
使用方法:
python merge_bag.py 输出命名.bag 输入1.bag 输入2.bag 输入3.bag …
代码文件:merge_bag.py
#!/usr/bin/env pythonimport sys
import argparse
from fnmatch import fnmatchcasefrom rosbag import Bagdef main():parser = argparse.ArgumentParser(description='Merge one or more bag files with the possibilities of filtering topics.')parser.add_argument('outputbag',help='output bag file with topics merged')parser.add_argument('inputbag', nargs='+',help='input bag files')parser.add_argument('-v', '--verbose', action="store_true", default=False,help='verbose output')parser.add_argument('-t', '--topics', default="*",help='string interpreted as a list of topics (wildcards \'*\' and \'?\' allowed) to include in the merged bag file')args = parser.parse_args()topics = args.topics.split(' ')total_included_count = 0total_skipped_count = 0if (args.verbose):print("Writing bag file: " + args.outputbag)print("Matching topics against patters: '%s'" % ' '.join(topics))with Bag(args.outputbag, 'w') as o: for ifile in args.inputbag:matchedtopics = []included_count = 0skipped_count = 0if (args.verbose):print("> Reading bag file: " + ifile)with Bag(ifile, 'r') as ib:for topic, msg, t in ib:if any(fnmatchcase(topic, pattern) for pattern in topics):if not topic in matchedtopics:matchedtopics.append(topic)if (args.verbose):print("Including matched topic '%s'" % topic)o.write(topic, msg, t)included_count += 1else:skipped_count += 1total_included_count += included_counttotal_skipped_count += skipped_countif (args.verbose):print("< Included %d messages and skipped %d" % (included_count, skipped_count))if (args.verbose):print("Total: Included %d messages and skipped %d" % (total_included_count, total_skipped_count))if __name__ == "__main__":main()
这篇关于ROS笔记之rosbag的合并与拼接merge_bag.py的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!