def contour_match(self, img):
        '''
        Returns 1. Image with bounding boxes added
                2. an ObstacleImageDetectionList
        '''

        object_list = ObstacleImageDetectionList()
        object_list.list = []

        height,width = img.shape[:2]
        object_list.imwidth = width
        object_list.imheight = height
        
        # get filtered contours
        cone_contours = self.get_filtered_contours(img, "CONE")
        duck_contours = self.get_filtered_contours(img, "DUCK_COLOR")

        all_contours = [duck_contours, cone_contours]
        for i, contours in enumerate(all_contours):
            for (cnt, box, ds, aspect_ratio, mean_color)  in contours:
                            
                # plot box around contour
                x,y,w,h = box
                font = cv2.FONT_HERSHEY_SIMPLEX
                cv2.putText(img,self.terms[i], (x,y), font, 0.5,mean_color,4)
                cv2.rectangle(img,(x,y),(x+w,y+h), mean_color,2)
                
                r = Rect()
                r.x = x
                r.y = y
                r.w = w
                r.h = h

                t = ObstacleType()
                t.type = i

                d = ObstacleImageDetection()
                d.bounding_box = r
                d.type = t
                object_list.list.append(d);
        return img, object_list
예제 #2
0
    def contour_match(self, img):
        '''
        Returns 1. Image with bounding boxes added
                2. an ObstacleImageDetectionList
        '''

        object_list = ObstacleImageDetectionwithimageList()
        object_list.list = []

        height, width = img.shape[:2]
        object_list.imwidth = width
        object_list.imheight = height

        # get filtered contours
        x, y, w, h, img = self.get_filtered_contours(img)
        object_list.im = self.bridge1.cv2_to_imgmsg(img, "bgr8")

        r = Rect()
        r.x = x
        r.y = y
        r.w = w
        r.h = h
        rospy.loginfo("the x,y,h,w is")
        rospy.loginfo(str(x))
        rospy.loginfo(str(y))
        rospy.loginfo(str(w))
        rospy.loginfo(str(h))
        #t = ObstacleType()
        #t.type =

        d = ObstacleImageDetection()
        d.bounding_box = r
        #d.type = t
        object_list.list.append(d)
        return img, object_list
예제 #3
0
    def contour_match(self, img):
        #rospy.loginfo("[static_object_detector_node] [4.0] in contour_match.")
        '''
        Returns 1. Image with bounding boxes added
                2. an ObstacleImageDetectionList
        '''
        object_list = ObstacleImageDetectionList()
        object_list.list = []

        height,width = img.shape[:2]
        object_list.imwidth = width
        object_list.imheight = height

        # get filtered contours
        #rospy.loginfo("[static_object_detector_node] [4.1] before get_filtered_contours.")
        try:
            cone_contours = self.get_filtered_contours(img, "CONE")
        except Exception as e:
            rospy.loginfo("[static_object_detector_node] [4.1.5] get_filtered_contours ERROR. %s" %(e))
        #rospy.loginfo("[static_object_detector_node] [4.2] after get_filtered_contours.")
	# disable duck detection
        # duck_contours = self.get_filtered_contours(img, "DUCK_COLOR")

        # disable duck detection
	# all_contours = [duck_contours, cone_contours]
        all_contours = [[], cone_contours]

        for i, contours in enumerate(all_contours):
            for (cnt, box, ds, aspect_ratio, mean_color)  in contours:

                # plot box around contour
                x,y,w,h = box
                font = cv2.FONT_HERSHEY_SIMPLEX
                cv2.putText(img,self.terms[i], (x,y), font, 0.5,mean_color,4)
                cv2.rectangle(img,(x,y),(x+w,y+h), mean_color,2)

                r = Rect()
                r.x = x
                r.y = y
                r.w = w
                r.h = h

                t = ObstacleType()
                t.type = i

                d = ObstacleImageDetection()
                d.bounding_box = r
                d.type = t
                object_list.list.append(d);
        return img, object_list
예제 #4
0
    def contour_match(self, img):
        '''
        Returns 1. Image with bounding boxes added
                2. an ObstacleImageDetectionList
        '''

        object_list = ObstacleImageDetectionList()
        object_list.list = []

        height, width = img.shape[:2]
        object_list.imwidth = width
        object_list.imheight = height

        # get filtered contours
        cone_contours = self.get_filtered_contours(img, "CONE")
        duck_contours = self.get_filtered_contours(img, "DUCK_COLOR")

        all_contours = [duck_contours, cone_contours]
        for i, contours in enumerate(all_contours):
            for (cnt, box, ds, aspect_ratio, mean_color) in contours:

                # plot box around contour
                x, y, w, h = box
                font = cv2.FONT_HERSHEY_SIMPLEX
                cv2.putText(img, self.terms[i], (x, y), font, 0.5, mean_color,
                            4)
                cv2.rectangle(img, (x, y), (x + w, y + h), mean_color, 2)

                r = Rect()
                r.x = x
                r.y = y
                r.w = w
                r.h = h

                t = ObstacleType()
                t.type = i

                d = ObstacleImageDetection()
                d.bounding_box = r
                d.type = t
                object_list.list.append(d)
        return img, object_list
예제 #5
0
def contour_match(img):

    # rospy.loginfo("contour_match")

    object_list = ObstacleImageDetectionList()
    object_list.list = []

    height, width = img.shape[:2]
    object_list.imwidth = width
    object_list.imheight = height

    # get filtered contours
    # cone_contours = get_filtered_contours(img, "CONE")
    duck_contours = get_filtered_contours(img, "DUCK_COLOR")

    all_contours = [duck_contours]
    for i, contours in enumerate(all_contours):
        for (cnt, box, ds, aspect_ratio, mean_color) in contours:
            # plot box around contour
            x, y, w, h = box
            font = cv2.FONT_HERSHEY_SIMPLEX
            cv2.putText(img, terms[i], (x, y), font, 0.5, mean_color, 4)
            cv2.rectangle(img, (x, y), (x + w, y + h), mean_color, 2)

            r = Rect()
            r.x = x
            r.y = y
            r.w = w
            r.h = h

            t = ObstacleType()
            t.type = i

            d = ObstacleImageDetection()
            d.bounding_box = r
            d.type = t
            object_list.list.append(d)
    # rospy.loginfo("duck_contours" + str(len(duck_contours)))
    # rospy.loginfo("object_list" + str(len(object_list.list)))

    return img, object_list