icra16_play_bag.py
Go to the documentation of this file.
00001 import rosbag
00002 import rospy
00003 import sys
00004 
00005 from sensor_msgs.msg import CameraInfo, PointCloud2, Image
00006 
00007 #import cv2
00008 #from cv_bridge import CvBridge, CvBridgeError
00009 
00010 #bridge = CvBridge()
00011 
00012 #def apply_segmentation(topic_dct):
00013     #try:
00014       #cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
00015     #except CvBridgeError, e:
00016       #print e  
00017 
00018 
00019 if __name__ == "__main__":
00020   if len(sys.argv) < 3:
00021     print "Usage:  <original_bag> <result_bag>]"
00022     sys.exit()
00023     
00024   rospy.init_node("player")
00025 
00026   print "Opening original bag %s" % sys.argv[1]
00027   orig_bag = rosbag.Bag(sys.argv[1], 'r')
00028 
00029   # publish camera info
00030   
00031   info = None
00032   for topic, msg, t in orig_bag.read_messages(topics=['camera/rgb/camera_info', '/camera/rgb/camera_info']):
00033     info = msg
00034   assert (info is not None)
00035   info_pub = rospy.Publisher('/camera/rgb/camera_info', type(info), queue_size=10)
00036 
00037   print "Opening result bag %s" % sys.argv[2]
00038   res_bag = rosbag.Bag(sys.argv[2], 'r')
00039 
00040   #result_topics = ['/camera/rgb/image_rect_color',]
00041   topic_buf = {}
00042   pub_buf = {}
00043   
00044   last_t = None
00045   for topic, msg, t in res_bag.read_messages():
00046 
00047     try:
00048       msg.header.frame_id = info.header.frame_id
00049       info.header.stamp = msg.header.stamp
00050       print "     resetting header of image %s" % topic
00051     except e:
00052       print e
00053 
00054     if last_t is not None and t > last_t:
00055       # publish
00056       info_pub.publish(info)
00057       for topic_, msg_ in topic_buf.items():
00058         print "  Publishing %s at %.3f" % (topic_, last_t.to_sec())
00059         pub_buf[topic_].publish(msg_)
00060         
00061       raw_input("Enter for next")
00062       topic_buf = {}
00063 
00064     topic_buf[topic] = msg
00065 
00066     if topic not in pub_buf:
00067       pub_buf[topic] = rospy.Publisher(topic, type(msg), queue_size=10)
00068       
00069     last_t = t
00070 
00071   orig_bag.close()
00072   res_bag.close()


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:31:50