save_markers.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import rospy
00004 import yaml
00005 import random
00006 import uuid
00007 import unique_id
00008 import world_canvas_msgs.msg
00009 import world_canvas_msgs.srv
00010 
00011 from geometry_msgs.msg import *
00012 from rospy_message_converter import message_converter
00013 from ar_track_alvar_msgs.msg import AlvarMarkers, AlvarMarker
00014 from world_canvas_msgs.msg import Annotation, AnnotationData
00015 from world_canvas_utils.serialization import *
00016 
00017 
00018 def read(file):
00019     yaml_data = None 
00020     with open(file) as f:
00021        yaml_data = yaml.load(f)
00022 
00023     anns_list = []
00024     data_list = []
00025 
00026     for t in yaml_data:
00027         ann = Annotation()
00028         ann.timestamp = rospy.Time.now()
00029         ann.data_id = unique_id.toMsg(unique_id.fromRandom())
00030         ann.id = unique_id.toMsg(unique_id.fromRandom())
00031         ann.world = world
00032         ann.name = t['name']
00033         ann.type = 'ar_track_alvar_msgs/AlvarMarker'
00034         for i in range(0, random.randint(0,11)):
00035             ann.keywords.append('kw'+str(random.randint(1,11)))
00036         # if 'prev_id' in vars():
00037         #     ann.relationships.append(prev_id)
00038         # prev_id = ann.id
00039         ann.shape = 1 # CUBE
00040         ann.color.r = 1.0
00041         ann.color.g = 1.0
00042         ann.color.b = 1.0
00043         ann.color.a = 1.0
00044         ann.size.x = 0.18
00045         ann.size.y = 0.18
00046         ann.size.z = 0.01
00047         ann.pose.header.frame_id = t['frame_id']
00048         ann.pose.header.stamp = rospy.Time.now()
00049         ann.pose.pose.pose = message_converter.convert_dictionary_to_ros_message('geometry_msgs/Pose',t['pose'])
00050 
00051         anns_list.append(ann)
00052         
00053         object = AlvarMarker()
00054         object.id = t['id']
00055         object.confidence = t['confidence']
00056         object.pose.header.frame_id = t['frame_id']
00057         object.pose.header.stamp = rospy.Time.now()
00058         object.pose.pose = message_converter.convert_dictionary_to_ros_message('geometry_msgs/Pose',t['pose'])
00059         data = AnnotationData()
00060         data.id = ann.data_id
00061         data.type = ann.type
00062         data.data = serialize_msg(object)
00063         
00064         data_list.append(data)
00065 
00066     return anns_list, data_list
00067 
00068 
00069 
00070 if __name__ == '__main__':
00071     rospy.init_node('markers_saver')
00072     world = rospy.get_param('~world')
00073     file  = rospy.get_param('~file')
00074     anns, data = read(file)
00075 
00076     rospy.loginfo("Waiting for save_annotations_data service...")
00077     rospy.wait_for_service('save_annotations_data')
00078     save_srv = rospy.ServiceProxy('save_annotations_data', world_canvas_msgs.srv.SaveAnnotationsData)
00079 
00080     rospy.loginfo("Saving AR markers from file '%s' for world '%s'" % (file, world))
00081     save_srv(anns, data)
00082     rospy.loginfo("Done")


world_canvas_server
Author(s): Jorge Santos Simón
autogenerated on Thu Jun 6 2019 21:25:07