class RecognizeObjects(State): def __init__(self): State.__init__(self, input_keys=['clusters', 'bounding_boxes', 'names'], output_keys=['names'], outcomes=['done']) self.label_vis = LabelVisualizer('object_labels', 'teal') try: rospy.wait_for_service('recognize_object', timeout=5) self.recognize = rospy.ServiceProxy('recognize_object', RecognizeObject) except rospy.ROSException: rospy.logwarn('Object recognition service is not available, ' 'will return "unknown" for all objects.') self.recognize = None def execute(self, ud): ud.names = list() for c, b in zip(ud.clusters, ud.bounding_boxes): if not self.recognize is None: response = self.recognize(c, b.dimensions) name = response.name else: name = 'unknown' ud.names.append(name) self.label_vis.publish(ud.names, [b.center for b in ud.bounding_boxes]) return 'done'
def __init__(self): State.__init__(self, input_keys=['clusters', 'bounding_boxes', 'names'], output_keys=['names'], outcomes=['done']) self.label_vis = LabelVisualizer('object_labels', 'teal') try: rospy.wait_for_service('recognize_object', timeout=5) self.recognize = rospy.ServiceProxy('recognize_object', RecognizeObject) except rospy.ROSException: rospy.logwarn('Object recognition service is not available, ' 'will return "unknown" for all objects.') self.recognize = None