脚本:截取euroc数据集bag文件的其中一段

脚本:截取euroc数据集bag文件的其中一段

功能:截取euroc数据集bag中的一段供算法测试

python脚本

#!/usr/bin/env python

# ------------------------------------------------------------------------------
# Function : restamp ros bagfile (using header timestamps)
# Project  : IJRR MAV Datasets
# Author   : www.asl.ethz.ch
# Version  : V01  21JAN2016 Initial version.
# Comment  :
# Status   : under review
#
# Usage    : python restamp_bag.py -i inbag.bag -o outbag.bag
# ------------------------------------------------------------------------------

import roslib
import rosbag
import rospy
import sys
import getopt
from   std_msgs.msg import String
from   std_msgs.msg import Time


def main(argv):

    inputfile = ''
    outputfile = ''

    # parse arguments
    try:
        opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
    except getopt.GetoptError:
        print 'usage: restamp_bag.py -i <inputfile> -o <outputfile>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'usage: python restamp_bag.py -i <inputfile> -o <outputfile>'
            sys.exit()
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg

    # print console header
    print ""
    print "restamp_bag"
    print ""
    print 'input file:  ', inputfile
    print 'output file: ', outputfile
    print ""
    print "starting restamping (may take a while)"
    print ""

    outbag = rosbag.Bag(outputfile, 'w')
    messageCounter = 0
    kPrintDotReductionFactor = 1000
    

    try:
        for topic, msg, t in rosbag.Bag(inputfile).read_messages():
            stamp = float(str(msg.header.stamp)) / 1000000000
            print stamp
            if (stamp < 1403636700.827958):
                outbag.write(topic, msg, msg.header.stamp)

            # Write message in output bag with input message header stamp
            #outbag.write(topic, msg, msg.header.stamp)

            #if (messageCounter % kPrintDotReductionFactor) == 0:
                    #print '.',
            #        sys.stdout.write('.')
            #        sys.stdout.flush()
            #messageCounter = messageCounter + 1

    # print console footer
    finally:
        print ""
        print ""
        print "finished iterating through input bag"
        print "output bag written"
        print ""
        outbag.close()

if __name__ == "__main__":
   main(sys.argv[1:])

 

转载于:https://www.cnblogs.com/feifanrensheng/p/10712307.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值