# coding: utf-8 #!/usr/bin/env python2 import os import rosbag import csv import math import sys import time def parsebag(input_dir, output_dir): dic_object_detection = ['Time','FrameID','HeadingAngle','ID','East', 'North' ,'position_z', 'altitude', 'AbsVel','Type'] object_detection_file = open(output_dir + "/"+"pos_orig.csv", 'w') writer_object_detection = csv.writer(object_detection_file) writer_object_detection.writerow(dic_object_detection) frame_max=sys.maxsize with rosbag.Bag(input_dir ,'r') as bag: #flag=False framenum = 1 hasLoc = False for topic,msg,t in bag.read_messages(): #t代表时间 if topic == "/cicv_location":#100hz hasLoc = True ego_speed=math.sqrt(msg.velocity_x**2+msg.velocity_y**2+msg.velocity_z**2) message_location =[str(t)[:-6],framenum,msg.yaw,'-1',msg.position_x,msg.position_y,msg.position_z,msg.altitude,ego_speed,'2'] global pos_x ,pos_y,pos_z pos_x=msg.position_x pos_y=msg.position_y pos_z=msg.position_z egocar_yaw=msg.yaw if topic == "/tpperception": # 10hz output_type=' ' if not hasLoc : # print("666") continue #global pos_x ,pos_y,pos_z m=msg.header.sequence_num if m