36 from std_msgs.msg
import String, Int8, ColorRGBA
38 from cnn_bridge.msg
import SegmentationClass
42 def __init__(self, shape, classPath, logdir, mode):
44 classes_parsed = json.load(open(classPath,
"r"))['classes'] 45 if mode ==
"segmentation":
46 self.
metadata = getSegmentationMetadataResponse()
47 self.metadata.class_metadata = []
49 for current_class
in classes_parsed:
50 class_msg = SegmentationClass()
51 class_msg.color = ColorRGBA()
52 class_msg.color.r = classes_parsed[current_class][
'color'][0]
53 class_msg.color.g = classes_parsed[current_class][
'color'][1]
54 class_msg.color.b = classes_parsed[current_class][
'color'][2]
55 class_msg.classification = Int8(classes_parsed[current_class][
'id'])
56 class_msg.classification_name = String(classes_parsed[current_class][
'name'])
57 class_msg.parent_class = Int8(classes_parsed[current_class][
'id_category'])
58 class_msg.parent_name = String(classes_parsed[current_class][
'category'])
59 self.metadata.class_metadata.append(class_msg)
62 self.
s = rospy.Service(rospy.get_name() +
'/get_cnn_metadata',
64 elif mode ==
"detection":
65 self.
metadata = getDetectionMetadataResponse()
66 self.metadata.class_names = []
67 for current_class
in classes_parsed:
68 self.metadata.class_names.append(String(unicodedata.normalize(
'NFKD', current_class).encode(
'ascii',
'ignore')))
69 self.
s = rospy.Service(rospy.get_name() +
'/get_cnn_metadata',
73 rospy.logerr(
"Could not read metadata file\nI/O error({0}): {1}".format(e.errno, e.strerror))
74 self.metadata.image_height = shape[1]
75 self.metadata.image_width = shape[0]
80 rospy.logdebug(
"Sent metadata about node {0}".format(rospy.get_name()))