예제 #1
0
 def test_clip_to_window(self):
     boxlist = np_box_list.BoxList(
         np.array([[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75],
                   [-0.2, -0.3, 0.7, 1.5]],
                  dtype=np.float32))
     boxlist_clipped = np_box_list_ops.clip_to_window(
         boxlist, [0.0, 0.0, 1.0, 1.0])
     expected_boxlist_clipped = np_box_list.BoxList(
         np.array([[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75],
                   [0.0, 0.0, 0.7, 1.0]],
                  dtype=np.float32))
     self.assertAllClose(expected_boxlist_clipped.get(),
                         boxlist_clipped.get())
예제 #2
0
 def test_clip_to_window(self):
   boxlist = np_box_list.BoxList(
       np.array(
           [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75],
            [-0.2, -0.3, 0.7, 1.5]],
           dtype=np.float32))
   boxlist_clipped = np_box_list_ops.clip_to_window(boxlist,
                                                    [0.0, 0.0, 1.0, 1.0])
   expected_boxlist_clipped = np_box_list.BoxList(
       np.array(
           [[0.25, 0.25, 0.75, 0.75], [0.0, 0.0, 0.5, 0.75],
            [0.0, 0.0, 0.7, 1.0]],
           dtype=np.float32))
   self.assertAllClose(expected_boxlist_clipped.get(), boxlist_clipped.get())
    def get_rect_area_total(obj_list, window):
        if not obj_list:
            return 0.0

        area_total = 0
        box_list = get_box_list(obj_list)

        box_list_clip = np_box_list_ops.clip_to_window(box_list, window)
        box_list_norm = np_box_list_ops.change_coordinate_frame(
            box_list_clip, window)
        n_boxes = box_list_norm.num_boxes()

        index = [str(i) for i in range(n_boxes)]
        box_list_norm.add_field('index', np.asarray(index))
        box_list_norm_org = copy.deepcopy(box_list_norm)

        sign = 1
        while box_list_norm:
            area = np.sum(np_box_list_ops.area(box_list_norm))
            area_total += area * sign
            sign *= -1
            box_list_norm = np_box_list_ops.intersection_boxes(
                box_list_norm_org, box_list_norm)
        return area_total
예제 #4
0
    def get_overlapping(labels, window, ioa_thresh=0.000001, clip=False):
        """Return subset of labels that overlap with window.

        Args:
            labels: ObjectDetectionLabels
            window: Box
            ioa_thresh: the minimum IOA for a box to be considered as
                overlapping
            clip: if True, clip label boxes to the window
        """
        # Lazily load TF Object Detection
        from object_detection.utils.np_box_list import BoxList
        from object_detection.utils.np_box_list_ops import (
            prune_non_overlapping_boxes, clip_to_window)

        window_npbox = window.npbox_format()
        window_boxlist = BoxList(np.expand_dims(window_npbox, axis=0))
        boxlist = prune_non_overlapping_boxes(labels.boxlist,
                                              window_boxlist,
                                              minoverlap=ioa_thresh)
        if clip:
            boxlist = clip_to_window(boxlist, window_npbox)

        return ObjectDetectionLabels.from_boxlist(boxlist)