Ejemplo n.º 1
0
    def classify_object(self, object):
        # class_dict = {'red_cube': 1, 'green_cylinder': 2, 'blue_handle': 0, 'obstacle': 0}
        # load object
        unclassified_object = object.unclassifiedObject
        if self.logging >= 2 : print("Got Object to Classify: \r\n %s" %unclassified_object)
        height = unclassified_object.c_height
        # h = unclassified_object.c_avg_col_h
        # s = unclassified_object.c_avg_col_s
        # v = unclassified_object.c_avg_col_v
        color_class = unclassified_object.c_color_class

        # Classifier steps:
        # 1) Consider the color
        # 2) Consider the height of the object. This should be close to one of the dimensions of one object
        # 3) Consider the volume (this may be optional if we already get good results)

        # 1)
        object_candidates = self.original_objects
        for obj in object_candidates:
          print obj.color 
          print "vs."
          print color_class
          print obj.color == color_class

        object_candidates = [obj for obj in object_candidates if obj.color == color_class]
        # if self.logging >= 1 : print("Remaining object candidates after color filtering {0}:".format(len(object_candidates) ) )
        if self.logging >= 1 : print("Remaining object candidates after color filtering:" )
        if self.logging >= 1 :
          for c in object_candidates:
            print c.name

        # 2)
        object_candidates = [obj for obj in object_candidates if self.check_dimension_tolerance(obj, height) ]
        if self.logging >= 1 : print("Remaining object candidates after height filtering:")
        if self.logging >= 1 :
          for c in object_candidates:
            print c.name

        # 3)
        # Not implemented yet

        # Evaluate the remaining object_candidates
        if len(object_candidates) > 1:
          # We couldn't filter the data to get only one object. Set the class name to ambiguous 
          unclassified_object.object.id = "ambiguous"
          unclassified_object.c_type = 255 # Classified as UNKNOWN(255)
        elif len(object_candidates) == 1:
          unclassified_object.object.id = object_candidates[0].name
          unclassified_object.c_type = 1 # Classified as object, otherwise 0
        else:
          unclassified_object.object.id = "unknown"
          unclassified_object.c_type = 255 # Classified as UNKNOWN(255)

        # unclassified_object.c_shape = class_dict[class_name[0]] # TODO is this neccessary?
        # unclassified_object.object.id = class_name
        resp = ClassifierResponse()
        resp.classifiedObject = unclassified_object
        if self.logging >= 1: print("Classified Object as: %s"%unclassified_object.object.id)
        self.publish_marker_for_object(unclassified_object, unclassified_object.object.id + "\nheight: " + str(height))
        return resp
Ejemplo n.º 2
0
    def classify_object(self, cobject):
        # load object
        unclassified_object = cobject.unclassifiedObject
        if self.logging >= 1:
            rospy.loginfo("Got Object to Classify: \r\n %s" % unclassified_object)
        height = unclassified_object.c_height
        h = unclassified_object.c_avg_col_h
        s = unclassified_object.c_avg_col_s
        v = unclassified_object.c_avg_col_v
        # Convert c++ hsv room to python one (take care only to 180 to fit in 8 bit)
        h = int(h / 360. * 180)
        s = int(s * 255)
        v = int(v * 255)
        hsv_color = np.uint8([[[h, s, v]]])
        bgr_color = cv2.cvtColor(hsv_color, cv2.COLOR_HSV2BGR)
        r = bgr_color[0][0][2]
        g = bgr_color[0][0][1]
        b = bgr_color[0][0][0]
        color_class = self.__color_class_number_mapping[unclassified_object.c_color_class]
        volume = unclassified_object.c_volume
        # build classifyable object and classify it
        classifyable_unclassified_object = []
        if 'color_class' in self.__selected_attributes:
            classifyable_unclassified_object.append(color_class)
        if 'height' in self.__selected_attributes:
            classifyable_unclassified_object.append(height)
        if 'volume' in self.__selected_attributes:
            classifyable_unclassified_object.append(volume)
        if 'cuboid' in self.__selected_attributes:
            classifyable_unclassified_object += unclassified_object.object.primitives[0].dimensions
        if 'color_hsv' in self.__selected_attributes:
            classifyable_unclassified_object += [h, s, v]
        if 'color_rgb' in self.__selected_attributes:
            classifyable_unclassified_object += [r, g, b]

        if self.logging >= 1:
            rospy.loginfo("Object to Classify: \r\n %s" % classifyable_unclassified_object)

        class_name = self.__classifier.predict(classifyable_unclassified_object)[0]
        if class_name == "obstacle":
            c_type = EurocObject.OBSTACLE
        else:
            c_type = EurocObject.OBJECT

        # print class_name
        # unclassified_object.c_shape = self.get_shape_of_class(class_name[0])
        unclassified_object.object.id = class_name
        unclassified_object.c_type = c_type
        resp = ClassifierResponse()
        resp.classifiedObject = unclassified_object
        if self.logging >= 1:
            rospy.loginfo("Classified Object as: %s" % class_name)
        self.__publish_marker_for_object(unclassified_object, unclassified_object.object.id + "\nheight: " + str(height))
        return resp
Ejemplo n.º 3
0
 def classify_object(self, object):
     class_dict = {
         'red_cube': 1,
         'green_cylinder': 2,
         'blue_handle': 0,
         'obstacle': 0
     }
     # load object
     unclassified_object = object.unclassifiedObject
     if self.logging >= 2:
         print("Got Object to Classify: \r\n %s" % unclassified_object)
     height = unclassified_object.c_height
     volume = unclassified_object.c_volume
     h = unclassified_object.c_avg_col_h
     s = unclassified_object.c_avg_col_s
     v = unclassified_object.c_avg_col_v
     #Convert c++ hsv room to python one (take care only to 180 to fit in 8 bit)
     h = int(h / 360. * 180)
     s = int(s * 255)
     v = int(v * 255)
     hsv_color = np.uint8([[[h, s, v]]])
     # bgr_color = cv2.cvtColor(hsv_color, cv2.COLOR_HSV2BGR)
     # r = bgr_color[0][0][2]
     # g = bgr_color[0][0][1]
     # b = bgr_color[0][0][0]
     #sort edges
     if unclassified_object.c_cuboid_success:
         edges = list(unclassified_object.object.primitives[0].dimensions)
         edges.sort()
     #build classifyable object and classify it
     classifyable_unclassified_object = [h, s, v, height]  # + edges
     if self.logging >= 1:
         print("Object to Classify: \r\n %s" %
               classifyable_unclassified_object)
     class_name = self.clf.predict(classifyable_unclassified_object)
     # print class_name
     # class_name = self.lolloosed(r,g,b)
     if (volume > 0.0001) or (height >
                              (self.max_height + self.max_height * 0.05)):
         class_name[0] = 'obstacle'
     unclassified_object.c_shape = class_dict[class_name[0]]
     unclassified_object.object.id = class_name[0]
     resp = ClassifierResponse()
     resp.classifiedObject = unclassified_object
     if self.logging >= 1:
         print("Classified Object as: %s" % class_name)
     self.publish_marker_for_object(
         unclassified_object, class_name[0] + "\nheight: " + str(height))
     return resp
Ejemplo n.º 4
0
 def classify_object(self, object):
     class_dict = {'red_cube': 1, 'green_cylinder': 2, 'blue_handle': 0, 'obstacle': 0}
     # load object
     unclassified_object = object.unclassifiedObject
     if self.logging >= 2:
         print("Got Object to Classify: \r\n %s" %unclassified_object)
     height = unclassified_object.c_height
     volume = unclassified_object.c_volume
     h = unclassified_object.c_avg_col_h
     s = unclassified_object.c_avg_col_s
     v = unclassified_object.c_avg_col_v
     #Convert c++ hsv room to python one (take care only to 180 to fit in 8 bit)
     h = int(h / 360. * 180)
     s = int(s * 255)
     v = int(v * 255)
     hsv_color = np.uint8([[[h, s, v]]])
     # bgr_color = cv2.cvtColor(hsv_color, cv2.COLOR_HSV2BGR)
     # r = bgr_color[0][0][2]
     # g = bgr_color[0][0][1]
     # b = bgr_color[0][0][0]
     #sort edges
     if unclassified_object.c_cuboid_success:
         edges = list(unclassified_object.object.primitives[0].dimensions)
         edges.sort()
     #build classifyable object and classify it
     classifyable_unclassified_object = [h, s, v, height]# + edges
     if self.logging >= 1:
         print("Object to Classify: \r\n %s"%classifyable_unclassified_object)
     class_name = self.clf.predict(classifyable_unclassified_object)
     # print class_name
     # class_name = self.lolloosed(r,g,b)
     if (volume > 0.0001) or (height > (self.max_height + self.max_height*0.05)):
         class_name[0] = 'obstacle'
     unclassified_object.c_shape = class_dict[class_name[0]]
     unclassified_object.object.id = class_name[0]
     resp = ClassifierResponse()
     resp.classifiedObject = unclassified_object
     if self.logging >= 1:
         print("Classified Object as: %s"%class_name)
     self.publish_marker_for_object(unclassified_object, class_name[0] + "\nheight: " + str(height))
     return resp
Ejemplo n.º 5
0
    def classify_object(self, cobject):
        # load object
        unclassified_object = cobject.unclassifiedObject
        if self.logging >= 1:
            rospy.loginfo("Got Object to Classify: \r\n %s" %
                          unclassified_object)
        height = unclassified_object.c_height
        h = unclassified_object.c_avg_col_h
        s = unclassified_object.c_avg_col_s
        v = unclassified_object.c_avg_col_v
        # Convert c++ hsv room to python one (take care only to 180 to fit in 8 bit)
        h = int(h / 360. * 180)
        s = int(s * 255)
        v = int(v * 255)
        hsv_color = np.uint8([[[h, s, v]]])
        bgr_color = cv2.cvtColor(hsv_color, cv2.COLOR_HSV2BGR)
        r = bgr_color[0][0][2]
        g = bgr_color[0][0][1]
        b = bgr_color[0][0][0]
        color_class = self.__color_class_number_mapping[
            unclassified_object.c_color_class]
        volume = unclassified_object.c_volume
        # build classifyable object and classify it
        classifyable_unclassified_object = []
        if 'color_class' in self.__selected_attributes:
            classifyable_unclassified_object.append(color_class)
        if 'height' in self.__selected_attributes:
            classifyable_unclassified_object.append(height)
        if 'volume' in self.__selected_attributes:
            classifyable_unclassified_object.append(volume)
        if 'cuboid' in self.__selected_attributes:
            classifyable_unclassified_object += unclassified_object.object.primitives[
                0].dimensions
        if 'color_hsv' in self.__selected_attributes:
            classifyable_unclassified_object += [h, s, v]
        if 'color_rgb' in self.__selected_attributes:
            classifyable_unclassified_object += [r, g, b]

        if self.logging >= 1:
            rospy.loginfo("Object to Classify: \r\n %s" %
                          classifyable_unclassified_object)

        class_name = self.__classifier.predict(
            classifyable_unclassified_object)[0]
        if class_name == "obstacle":
            c_type = EurocObject.OBSTACLE
        else:
            c_type = EurocObject.OBJECT

        # print class_name
        # unclassified_object.c_shape = self.get_shape_of_class(class_name[0])
        unclassified_object.object.id = class_name
        unclassified_object.c_type = c_type
        resp = ClassifierResponse()
        resp.classifiedObject = unclassified_object
        if self.logging >= 1:
            rospy.loginfo("Classified Object as: %s" % class_name)
        self.__publish_marker_for_object(
            unclassified_object,
            unclassified_object.object.id + "\nheight: " + str(height))
        return resp
Ejemplo n.º 6
0
    def classify_object(self, object):
        # class_dict = {'red_cube': 1, 'green_cylinder': 2, 'blue_handle': 0, 'obstacle': 0}
        # load object
        unclassified_object = object.unclassifiedObject
        if self.logging >= 2:
            print("Got Object to Classify: \r\n %s" % unclassified_object)
        height = unclassified_object.c_height
        # h = unclassified_object.c_avg_col_h
        # s = unclassified_object.c_avg_col_s
        # v = unclassified_object.c_avg_col_v
        color_class = unclassified_object.c_color_class

        # Classifier steps:
        # 1) Consider the color
        # 2) Consider the height of the object. This should be close to one of the dimensions of one object
        # 3) Consider the volume (this may be optional if we already get good results)

        # 1)
        object_candidates = self.original_objects
        for obj in object_candidates:
            print obj.color
            print "vs."
            print color_class
            print obj.color == color_class

        object_candidates = [
            obj for obj in object_candidates if obj.color == color_class
        ]
        # if self.logging >= 1 : print("Remaining object candidates after color filtering {0}:".format(len(object_candidates) ) )
        if self.logging >= 1:
            print("Remaining object candidates after color filtering:")
        if self.logging >= 1:
            for c in object_candidates:
                print c.name

        # 2)
        object_candidates = [
            obj for obj in object_candidates
            if self.check_dimension_tolerance(obj, height)
        ]
        if self.logging >= 1:
            print("Remaining object candidates after height filtering:")
        if self.logging >= 1:
            for c in object_candidates:
                print c.name

        # 3)
        # Not implemented yet

        # Evaluate the remaining object_candidates
        if len(object_candidates) > 1:
            # We couldn't filter the data to get only one object. Set the class name to ambiguous
            unclassified_object.object.id = "ambiguous"
            unclassified_object.c_type = 255  # Classified as UNKNOWN(255)
        elif len(object_candidates) == 1:
            unclassified_object.object.id = object_candidates[0].name
            unclassified_object.c_type = 1  # Classified as object, otherwise 0
        else:
            unclassified_object.object.id = "unknown"
            unclassified_object.c_type = 255  # Classified as UNKNOWN(255)

        # unclassified_object.c_shape = class_dict[class_name[0]] # TODO is this neccessary?
        # unclassified_object.object.id = class_name
        resp = ClassifierResponse()
        resp.classifiedObject = unclassified_object
        if self.logging >= 1:
            print("Classified Object as: %s" % unclassified_object.object.id)
        self.publish_marker_for_object(
            unclassified_object,
            unclassified_object.object.id + "\nheight: " + str(height))
        return resp