Python imgaug.BoundingBoxesOnImage() Examples

The following are 30 code examples of imgaug.BoundingBoxesOnImage(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module imgaug , or try the search function .
Example #1
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_fill_from_xy_array___list_with_two_coords(self):
        xy = [(100, 101),
              (102, 103),
              (200, 201),
              (202, 203)]
        bbsoi = ia.BoundingBoxesOnImage(
            [ia.BoundingBox(1, 2, 3, 4),
             ia.BoundingBox(10, 20, 30, 40)],
            shape=(2, 2, 3))

        bbsoi = bbsoi.fill_from_xy_array_(xy)

        assert len(bbsoi.bounding_boxes) == 2
        assert bbsoi.bounding_boxes[0].x1 == 100
        assert bbsoi.bounding_boxes[0].y1 == 101
        assert bbsoi.bounding_boxes[0].x2 == 102
        assert bbsoi.bounding_boxes[0].y2 == 103
        assert bbsoi.bounding_boxes[1].x1 == 200
        assert bbsoi.bounding_boxes[1].y1 == 201
        assert bbsoi.bounding_boxes[1].x2 == 202
        assert bbsoi.bounding_boxes[1].y2 == 203 
Example #2
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_copy(self):
        bb1 = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
        bb2 = ia.BoundingBox(y1=15, x1=25, y2=35, x2=51)
        bbsoi = ia.BoundingBoxesOnImage([bb1, bb2], shape=(40, 50, 3))

        bbsoi_copy = bbsoi.copy()

        assert len(bbsoi.bounding_boxes) == 2
        assert bbsoi_copy.bounding_boxes[0].y1 == 10
        assert bbsoi_copy.bounding_boxes[0].x1 == 20
        assert bbsoi_copy.bounding_boxes[0].y2 == 30
        assert bbsoi_copy.bounding_boxes[0].x2 == 40
        assert bbsoi_copy.bounding_boxes[1].y1 == 15
        assert bbsoi_copy.bounding_boxes[1].x1 == 25
        assert bbsoi_copy.bounding_boxes[1].y2 == 35
        assert bbsoi_copy.bounding_boxes[1].x2 == 51

        bbsoi_copy.bounding_boxes[0].y1 = 0
        assert bbsoi.bounding_boxes[0].y1 == 0
        assert bbsoi_copy.bounding_boxes[0].y1 == 0 
Example #3
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_deepcopy(self):
        bb1 = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
        bb2 = ia.BoundingBox(y1=15, x1=25, y2=35, x2=51)
        bbsoi = ia.BoundingBoxesOnImage([bb1, bb2], shape=(40, 50, 3))

        bbsoi_copy = bbsoi.deepcopy()

        assert len(bbsoi.bounding_boxes) == 2
        assert bbsoi_copy.bounding_boxes[0].y1 == 10
        assert bbsoi_copy.bounding_boxes[0].x1 == 20
        assert bbsoi_copy.bounding_boxes[0].y2 == 30
        assert bbsoi_copy.bounding_boxes[0].x2 == 40
        assert bbsoi_copy.bounding_boxes[1].y1 == 15
        assert bbsoi_copy.bounding_boxes[1].x1 == 25
        assert bbsoi_copy.bounding_boxes[1].y2 == 35
        assert bbsoi_copy.bounding_boxes[1].x2 == 51

        bbsoi_copy.bounding_boxes[0].y1 = 0
        assert bbsoi.bounding_boxes[0].y1 == 10
        assert bbsoi_copy.bounding_boxes[0].y1 == 0 
Example #4
Source File: test_debug.py    From imgaug with MIT License 6 votes vote down vote up
def test_two_images_and_bounding_boxes(self):
        rng = iarandom.RNG(0)
        images = rng.integers(0, 256, size=(2, 256, 256, 3), dtype=np.uint8)
        bbs = []
        for x in np.linspace(0, 256, 5):
            for y in np.linspace(0, 256, 5):
                bbs.append(ia.BoundingBox(x1=x, y1=y, x2=x+20, y2=y+20))
        bbsoi1 = ia.BoundingBoxesOnImage(bbs, shape=images[0].shape)
        bbsoi2 = bbsoi1.shift(x=20)
        image1_w_overlay = bbsoi1.draw_on_image(images[0])
        image2_w_overlay = bbsoi2.draw_on_image(images[1])

        debug_image = iaa.draw_debug_image(images,
                                           bounding_boxes=[bbsoi1, bbsoi2])

        assert self._image_contains(images[0, ...], debug_image)
        assert self._image_contains(images[1, ...], debug_image)
        assert self._image_contains(image1_w_overlay, debug_image)
        assert self._image_contains(image2_w_overlay, debug_image) 
Example #5
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_to_polygons_on_image(self):
        bb1 = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
        bb2 = ia.BoundingBox(y1=15, x1=25, y2=35, x2=51)
        bbsoi = ia.BoundingBoxesOnImage([bb1, bb2], shape=(40, 50, 3))

        psoi = bbsoi.to_polygons_on_image()

        assert psoi.shape == (40, 50, 3)
        assert len(psoi.items) == 2
        assert psoi.items[0].coords_almost_equals([
            (20, 10),
            (40, 10),
            (40, 30),
            (20, 30)
        ])
        assert psoi.items[1].coords_almost_equals([
            (25, 15),
            (51, 15),
            (51, 35),
            (25, 35)
        ]) 
Example #6
Source File: augmentation.py    From Unified-Gesture-and-Fingertip-Detection with MIT License 6 votes vote down vote up
def augment(image, bbox):
    x = random.randint(-50, 50)
    y = random.randint(-50, 50)
    aug = iaa.Sequential([iaa.Multiply(random.uniform(0.5, 1.5)),
                          iaa.AdditiveGaussianNoise(random.uniform(0.01, 0.1) * 255),
                          iaa.Affine(translate_px={"x": x, "y": y},
                                     scale=random.uniform(0.5, 1.5),
                                     rotate=random.uniform(-45, 45),
                                     cval=(0, 255))])

    bbs = ia.BoundingBoxesOnImage([ia.BoundingBox(x1=bbox[0], y1=bbox[1], x2=bbox[2], y2=bbox[3])], shape=image.shape)

    aug = aug.to_deterministic()
    image_aug = aug.augment_image(image)
    bbs_aug = aug.augment_bounding_boxes([bbs])[0]
    b = bbs_aug.bounding_boxes
    bbs_aug = [b[0].x1, b[0].y1, b[0].x2, b[0].y2]
    bbs_aug = np.asarray(bbs_aug)

    bbs_aug[0] = bbs_aug[0] if bbs_aug[0] > 0 else 0
    bbs_aug[1] = bbs_aug[1] if bbs_aug[1] > 0 else 0
    bbs_aug[2] = bbs_aug[2] if bbs_aug[2] < size else size
    bbs_aug[3] = bbs_aug[3] if bbs_aug[3] < size else size
    return image_aug, bbs_aug 
Example #7
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_clip_out_of_image(self):
        bb1 = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
        bb2 = ia.BoundingBox(y1=15, x1=25, y2=35, x2=51)
        bbsoi = ia.BoundingBoxesOnImage([bb1, bb2], shape=(40, 50, 3))

        bbsoi_clip = self._func(bbsoi)

        assert len(bbsoi_clip.bounding_boxes) == 2
        assert bbsoi_clip.bounding_boxes[0].y1 == 10
        assert bbsoi_clip.bounding_boxes[0].x1 == 20
        assert bbsoi_clip.bounding_boxes[0].y2 == 30
        assert bbsoi_clip.bounding_boxes[0].x2 == 40
        assert bbsoi_clip.bounding_boxes[1].y1 == 15
        assert bbsoi_clip.bounding_boxes[1].x1 == 25
        assert bbsoi_clip.bounding_boxes[1].y2 == 35
        assert np.isclose(bbsoi_clip.bounding_boxes[1].x2, 50) 
Example #8
Source File: augmentation.py    From Unified-Gesture-and-Fingertip-Detection with MIT License 6 votes vote down vote up
def augment_flip(image, bbox):
    aug = iaa.Sequential([iaa.Fliplr(1.0)])

    bbs = ia.BoundingBoxesOnImage([
        ia.BoundingBox(x1=bbox[0], y1=bbox[1], x2=bbox[2], y2=bbox[3])], shape=image.shape)

    aug = aug.to_deterministic()
    image_aug = aug.augment_image(image)
    image_aug = image_aug.copy()
    bbs_aug = aug.augment_bounding_boxes([bbs])[0]
    b = bbs_aug.bounding_boxes
    bbs_aug = [b[0].x1, b[0].y1, b[0].x2, b[0].y2]
    bbs_aug = np.asarray(bbs_aug)

    bbs_aug[0] = bbs_aug[0] if bbs_aug[0] > 0 else 0
    bbs_aug[1] = bbs_aug[1] if bbs_aug[1] > 0 else 0
    bbs_aug[2] = bbs_aug[2] if bbs_aug[2] < size else size
    bbs_aug[3] = bbs_aug[3] if bbs_aug[3] < size else size
    return image_aug, bbs_aug 
Example #9
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_on_upscaled_by_2_with_shape_given_as_array(self):
        bb1 = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
        bb2 = ia.BoundingBox(y1=15, x1=25, y2=35, x2=45)
        bbsoi = ia.BoundingBoxesOnImage([bb1, bb2], shape=(40, 50, 3))

        bbsoi_projected = self._func(bbsoi, np.zeros((40*2, 50*2, 3), dtype=np.uint8))

        assert bbsoi_projected.bounding_boxes[0].y1 == 10*2
        assert bbsoi_projected.bounding_boxes[0].x1 == 20*2
        assert bbsoi_projected.bounding_boxes[0].y2 == 30*2
        assert bbsoi_projected.bounding_boxes[0].x2 == 40*2
        assert bbsoi_projected.bounding_boxes[1].y1 == 15*2
        assert bbsoi_projected.bounding_boxes[1].x1 == 25*2
        assert bbsoi_projected.bounding_boxes[1].y2 == 35*2
        assert bbsoi_projected.bounding_boxes[1].x2 == 45*2
        assert bbsoi_projected.shape == (40*2, 50*2, 3) 
Example #10
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_on_same_height_width(self):
        bb1 = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
        bb2 = ia.BoundingBox(y1=15, x1=25, y2=35, x2=45)
        bbsoi = ia.BoundingBoxesOnImage([bb1, bb2], shape=(40, 50, 3))

        bbsoi_projected = self._func(bbsoi, (40, 50))

        assert bbsoi_projected.bounding_boxes[0].y1 == 10
        assert bbsoi_projected.bounding_boxes[0].x1 == 20
        assert bbsoi_projected.bounding_boxes[0].y2 == 30
        assert bbsoi_projected.bounding_boxes[0].x2 == 40
        assert bbsoi_projected.bounding_boxes[1].y1 == 15
        assert bbsoi_projected.bounding_boxes[1].x1 == 25
        assert bbsoi_projected.bounding_boxes[1].y2 == 35
        assert bbsoi_projected.bounding_boxes[1].x2 == 45
        assert bbsoi_projected.shape == (40, 50) 
Example #11
Source File: augmentation.py    From Unified-Gesture-and-Fingertip-Detection with MIT License 6 votes vote down vote up
def augment(image, bbox):
    x = random.randint(-60, 60)
    y = random.randint(-60, 60)
    aug = iaa.Sequential([iaa.AdditiveGaussianNoise(scale=random.uniform(.001, .01) * 255),  # gaussian noise
                          iaa.Multiply(random.uniform(0.5, 1.5)),  # brightness
                          iaa.Affine(translate_px={"x": x, "y": y},  # translation
                                     scale=random.uniform(0.5, 1.5),  # zoom in and out
                                     rotate=random.uniform(-25, 25),  # rotation
                                     shear=random.uniform(-5, 5),  # shear transformation
                                     cval=(0, 255))])  # fill the empty space with color

    aug.add(iaa.Salt(.001))
    bbs = ia.BoundingBoxesOnImage([ia.BoundingBox(x1=bbox[0], y1=bbox[1], x2=bbox[2], y2=bbox[3])], shape=image.shape)
    aug = aug.to_deterministic()
    image_aug = aug.augment_image(image)
    bbs_aug = aug.augment_bounding_boxes([bbs])[0]
    b = bbs_aug.bounding_boxes
    bbs_aug = [b[0].x1, b[0].y1, b[0].x2, b[0].y2]
    bbs_aug = np.asarray(bbs_aug)

    bbs_aug[0] = bbs_aug[0] if bbs_aug[0] > 0 else 0
    bbs_aug[1] = bbs_aug[1] if bbs_aug[1] > 0 else 0
    bbs_aug[2] = bbs_aug[2] if bbs_aug[2] < size else size
    bbs_aug[3] = bbs_aug[3] if bbs_aug[3] < size else size
    return image_aug, bbs_aug 
Example #12
Source File: augmentation.py    From Unified-Gesture-and-Fingertip-Detection with MIT License 6 votes vote down vote up
def flip(image, bbox):
    aug = iaa.Sequential([iaa.Fliplr(1.0)])

    bbs = ia.BoundingBoxesOnImage([
        ia.BoundingBox(x1=bbox[0], y1=bbox[1], x2=bbox[2], y2=bbox[3])], shape=image.shape)

    aug = aug.to_deterministic()
    image_aug = aug.augment_image(image)
    image_aug = image_aug.copy()
    bbs_aug = aug.augment_bounding_boxes([bbs])[0]
    b = bbs_aug.bounding_boxes
    bbs_aug = [b[0].x1, b[0].y1, b[0].x2, b[0].y2]
    bbs_aug = np.asarray(bbs_aug)

    bbs_aug[0] = bbs_aug[0] if bbs_aug[0] > 0 else 0
    bbs_aug[1] = bbs_aug[1] if bbs_aug[1] > 0 else 0
    bbs_aug[2] = bbs_aug[2] if bbs_aug[2] < size else size
    bbs_aug[3] = bbs_aug[3] if bbs_aug[3] < size else size
    return image_aug, bbs_aug 
Example #13
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_invert_to_keypoints_on_image_(self):
        bbsoi = ia.BoundingBoxesOnImage(
            [ia.BoundingBox(0, 1, 2, 3),
             ia.BoundingBox(10, 20, 30, 40)],
            shape=(1, 2, 3))
        kpsoi = ia.KeypointsOnImage(
            [ia.Keypoint(100, 101), ia.Keypoint(102, 103),
             ia.Keypoint(104, 105), ia.Keypoint(106, 107),
             ia.Keypoint(110, 120), ia.Keypoint(130, 140),
             ia.Keypoint(150, 160), ia.Keypoint(170, 180)],
            shape=(10, 20, 30))

        bbsoi_inv = bbsoi.invert_to_keypoints_on_image_(kpsoi)

        assert len(bbsoi_inv.bounding_boxes) == 2
        assert bbsoi_inv.shape == (10, 20, 30)
        assert bbsoi_inv.bounding_boxes[0].x1 == 100
        assert bbsoi_inv.bounding_boxes[0].y1 == 101
        assert bbsoi_inv.bounding_boxes[0].x2 == 106
        assert bbsoi_inv.bounding_boxes[0].y2 == 107
        assert bbsoi_inv.bounding_boxes[1].x1 == 110
        assert bbsoi_inv.bounding_boxes[1].y1 == 120
        assert bbsoi_inv.bounding_boxes[1].x2 == 170
        assert bbsoi_inv.bounding_boxes[1].y2 == 180 
Example #14
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_from_xyxy_array_float(self):
        xyxy = np.float32([
            [0.0, 0.0, 1.0, 1.0],
            [1.0, 2.0, 3.0, 4.0]
        ])

        bbsoi = ia.BoundingBoxesOnImage.from_xyxy_array(xyxy, shape=(40, 50, 3))

        assert len(bbsoi.bounding_boxes) == 2
        assert np.allclose(bbsoi.bounding_boxes[0].x1, 0.0)
        assert np.allclose(bbsoi.bounding_boxes[0].y1, 0.0)
        assert np.allclose(bbsoi.bounding_boxes[0].x2, 1.0)
        assert np.allclose(bbsoi.bounding_boxes[0].y2, 1.0)
        assert np.allclose(bbsoi.bounding_boxes[1].x1, 1.0)
        assert np.allclose(bbsoi.bounding_boxes[1].y1, 2.0)
        assert np.allclose(bbsoi.bounding_boxes[1].x2, 3.0)
        assert np.allclose(bbsoi.bounding_boxes[1].y2, 4.0)
        assert bbsoi.shape == (40, 50, 3) 
Example #15
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_from_xyxy_array_float_3d(self):
        xyxy = np.float32([
            [
                [0.0, 0.0],
                [1.0, 1.0]
            ],
            [
                [1.0, 2.0],
                [3.0, 4.0]
            ]
        ])

        bbsoi = ia.BoundingBoxesOnImage.from_xyxy_array(xyxy, shape=(40, 50, 3))

        assert len(bbsoi.bounding_boxes) == 2
        assert np.allclose(bbsoi.bounding_boxes[0].x1, 0.0)
        assert np.allclose(bbsoi.bounding_boxes[0].y1, 0.0)
        assert np.allclose(bbsoi.bounding_boxes[0].x2, 1.0)
        assert np.allclose(bbsoi.bounding_boxes[0].y2, 1.0)
        assert np.allclose(bbsoi.bounding_boxes[1].x1, 1.0)
        assert np.allclose(bbsoi.bounding_boxes[1].y1, 2.0)
        assert np.allclose(bbsoi.bounding_boxes[1].x2, 3.0)
        assert np.allclose(bbsoi.bounding_boxes[1].y2, 4.0)
        assert bbsoi.shape == (40, 50, 3) 
Example #16
Source File: test_blend.py    From imgaug with MIT License 6 votes vote down vote up
def test_zero_sized_axes(self):
        shapes = [
            (0, 0),
            (0, 1),
            (1, 0),
            (0, 1, 0),
            (1, 0, 0),
            (0, 1, 1),
            (1, 0, 1)
        ]

        for shape in shapes:
            with self.subTest(shape=shape):
                bbs = [ia.BoundingBox(x1=1, y1=1, x2=5, y2=5, label="bb1"),
                       ia.BoundingBox(x1=-3, y1=4, x2=20, y2=8, label="bb2"),
                       ia.BoundingBox(x1=2, y1=2, x2=10, y2=10, label="bb3")]
                bbsoi = ia.BoundingBoxesOnImage(bbs, shape=shape)
                batch = _BatchInAugmentation(bounding_boxes=[bbsoi])
                gen = iaa.BoundingBoxesMaskGen("bb1")

                mask = gen.draw_masks(batch)[0]

                assert mask.shape == shape[0:2]
                assert mask.dtype.name == "float32"
                assert np.allclose(mask, 0.0) 
Example #17
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_from_point_soups__2d_array(self):
        xy = np.float32([
            [7, 3,
             11, 5,
             1, 7,
             12, 19]
        ])

        bbsoi = ia.BoundingBoxesOnImage.from_point_soups(
            xy, shape=(40, 50, 3))

        assert len(bbsoi.bounding_boxes) == 1
        assert bbsoi.bounding_boxes[0].x1 == 1
        assert bbsoi.bounding_boxes[0].y1 == 3
        assert bbsoi.bounding_boxes[0].x2 == 12
        assert bbsoi.bounding_boxes[0].y2 == 19
        assert bbsoi.shape == (40, 50, 3) 
Example #18
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_from_point_soups__2d_list(self):
        xy = [
            [7, 3,
             11, 5,
             1, 7,
             12, 19]
        ]

        bbsoi = ia.BoundingBoxesOnImage.from_point_soups(
            xy, shape=(40, 50, 3))

        assert len(bbsoi.bounding_boxes) == 1
        assert bbsoi.bounding_boxes[0].x1 == 1
        assert bbsoi.bounding_boxes[0].y1 == 3
        assert bbsoi.bounding_boxes[0].x2 == 12
        assert bbsoi.bounding_boxes[0].y2 == 19
        assert bbsoi.shape == (40, 50, 3) 
Example #19
Source File: test_blend.py    From imgaug with MIT License 6 votes vote down vote up
def test_draw_masks__fixed_labels(self):
        bbs = [ia.BoundingBox(x1=1, y1=1, x2=5, y2=5, label="bb1"),
               ia.BoundingBox(x1=-3, y1=4, x2=20, y2=8, label="bb2"),
               ia.BoundingBox(x1=2, y1=2, x2=10, y2=10, label="bb3")]
        bbsoi = ia.BoundingBoxesOnImage(bbs, shape=(10, 14, 3))

        batch = _BatchInAugmentation(bounding_boxes=[bbsoi])
        gen = iaa.BoundingBoxesMaskGen(["bb1", "bb2"])

        mask = gen.draw_masks(batch, random_state=1)[0]

        expected = np.zeros((10, 14), dtype=np.float32)
        expected[1:5, 1:5] = 1.0  # bb1
        expected[4:8, 0:14] = 1.0  # bb2 clipped to image shape
        assert mask.shape == (10, 14)
        assert mask.dtype.name == "float32"
        assert np.allclose(mask, expected) 
Example #20
Source File: test_blend.py    From imgaug with MIT License 6 votes vote down vote up
def test_draw_masks__labels_is_none(self):
        bbs = [ia.BoundingBox(x1=1, y1=1, x2=5, y2=5, label="bb1"),
               ia.BoundingBox(x1=-3, y1=4, x2=20, y2=8, label="bb2"),
               ia.BoundingBox(x1=2, y1=2, x2=10, y2=10, label="bb3")]
        bbsoi = ia.BoundingBoxesOnImage(bbs, shape=(10, 14, 3))

        batch = _BatchInAugmentation(bounding_boxes=[bbsoi])
        gen = iaa.BoundingBoxesMaskGen()

        mask = gen.draw_masks(batch, random_state=1)[0]

        expected = np.zeros((10, 14), dtype=np.float32)
        expected[1:5, 1:5] = 1.0  # bb1
        expected[4:8, 0:14] = 1.0  # bb2 clipped to image shape
        expected[2:10, 2:10] = 1.0  # bb3
        assert mask.shape == (10, 14)
        assert mask.dtype.name == "float32"
        assert np.allclose(mask, expected) 
Example #21
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_shift(self):
        bb1 = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
        bb2 = ia.BoundingBox(y1=15, x1=25, y2=35, x2=51)
        bbsoi = ia.BoundingBoxesOnImage([bb1, bb2], shape=(40, 50, 3))

        bbsoi_shifted = bbsoi.shift(y=2)

        assert len(bbsoi_shifted.bounding_boxes) == 2
        assert bbsoi_shifted.bounding_boxes[0].y1 == 10 + 2
        assert bbsoi_shifted.bounding_boxes[0].x1 == 20
        assert bbsoi_shifted.bounding_boxes[0].y2 == 30 + 2
        assert bbsoi_shifted.bounding_boxes[0].x2 == 40
        assert bbsoi_shifted.bounding_boxes[1].y1 == 15 + 2
        assert bbsoi_shifted.bounding_boxes[1].x1 == 25
        assert bbsoi_shifted.bounding_boxes[1].y2 == 35 + 2
        assert bbsoi_shifted.bounding_boxes[1].x2 == 51
        assert bbsoi_shifted is not bbsoi 
Example #22
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_to_xy_array(self):
        xyxy = np.float32([
            [0.0, 0.0, 1.0, 1.0],
            [1.0, 2.0, 3.0, 4.0]
        ])
        bbsoi = ia.BoundingBoxesOnImage.from_xyxy_array(xyxy, shape=(40, 50, 3))

        xy_out = bbsoi.to_xy_array()

        expected = np.float32([
            [0.0, 0.0],
            [1.0, 1.0],
            [1.0, 2.0],
            [3.0, 4.0]
        ])
        assert xy_out.shape == (4, 2)
        assert np.allclose(xy_out, expected)
        assert xy_out.dtype.name == "float32" 
Example #23
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_shift_(self):
        bb1 = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
        bb2 = ia.BoundingBox(y1=15, x1=25, y2=35, x2=51)
        bbsoi = ia.BoundingBoxesOnImage([bb1, bb2], shape=(40, 50, 3))

        bbsoi_shifted = bbsoi.shift_(y=2)

        assert len(bbsoi_shifted.bounding_boxes) == 2
        assert bbsoi_shifted.bounding_boxes[0].y1 == 10 + 2
        assert bbsoi_shifted.bounding_boxes[0].x1 == 20
        assert bbsoi_shifted.bounding_boxes[0].y2 == 30 + 2
        assert bbsoi_shifted.bounding_boxes[0].x2 == 40
        assert bbsoi_shifted.bounding_boxes[1].y1 == 15 + 2
        assert bbsoi_shifted.bounding_boxes[1].x1 == 25
        assert bbsoi_shifted.bounding_boxes[1].y2 == 35 + 2
        assert bbsoi_shifted.bounding_boxes[1].x2 == 51
        assert bbsoi_shifted is bbsoi 
Example #24
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_fill_from_xyxy_array___array_with_two_coords(self):
        xyxy = np.array(
            [(100, 101, 102, 103),
             (200, 201, 202, 203)], dtype=np.float32)
        bbsoi = ia.BoundingBoxesOnImage(
            [ia.BoundingBox(1, 2, 3, 4),
             ia.BoundingBox(10, 20, 30, 40)],
            shape=(2, 2, 3))

        bbsoi = bbsoi.fill_from_xyxy_array_(xyxy)

        assert len(bbsoi.bounding_boxes) == 2
        assert bbsoi.bounding_boxes[0].x1 == 100
        assert bbsoi.bounding_boxes[0].y1 == 101
        assert bbsoi.bounding_boxes[0].x2 == 102
        assert bbsoi.bounding_boxes[0].y2 == 103
        assert bbsoi.bounding_boxes[1].x1 == 200
        assert bbsoi.bounding_boxes[1].y1 == 201
        assert bbsoi.bounding_boxes[1].x2 == 202
        assert bbsoi.bounding_boxes[1].y2 == 203 
Example #25
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_string_conversion(self):
        bb1 = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
        bb2 = ia.BoundingBox(y1=15, x1=25, y2=35, x2=51)
        bbsoi = ia.BoundingBoxesOnImage([bb1, bb2], shape=(40, 50, 3))

        bb1_expected = "BoundingBox(x1=20.0000, y1=10.0000, " \
                       "x2=40.0000, y2=30.0000, label=None)"
        bb2_expected = "BoundingBox(x1=25.0000, y1=15.0000, " \
                       "x2=51.0000, y2=35.0000, label=None)"
        expected = "BoundingBoxesOnImage([%s, %s], shape=(40, 50, 3))" % (
            bb1_expected, bb2_expected)
        assert (
            bbsoi.__repr__()
            == bbsoi.__str__()
            == expected
        ) 
Example #26
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_fill_from_xy_array___array_with_two_coords(self):
        xy = np.array(
            [(100, 101),
             (102, 103),
             (200, 201),
             (202, 203)], dtype=np.float32)
        bbsoi = ia.BoundingBoxesOnImage(
            [ia.BoundingBox(1, 2, 3, 4),
             ia.BoundingBox(10, 20, 30, 40)],
            shape=(2, 2, 3))

        bbsoi = bbsoi.fill_from_xy_array_(xy)

        assert len(bbsoi.bounding_boxes) == 2
        assert bbsoi.bounding_boxes[0].x1 == 100
        assert bbsoi.bounding_boxes[0].y1 == 101
        assert bbsoi.bounding_boxes[0].x2 == 102
        assert bbsoi.bounding_boxes[0].y2 == 103
        assert bbsoi.bounding_boxes[1].x1 == 200
        assert bbsoi.bounding_boxes[1].y1 == 201
        assert bbsoi.bounding_boxes[1].x2 == 202
        assert bbsoi.bounding_boxes[1].y2 == 203 
Example #27
Source File: test_bbs.py    From imgaug with MIT License 6 votes vote down vote up
def test_from_xyxy_array_int32(self):
        xyxy = np.int32([
            [0, 0, 1, 1],
            [1, 2, 3, 4]
        ])

        bbsoi = ia.BoundingBoxesOnImage.from_xyxy_array(xyxy, shape=(40, 50, 3))

        assert len(bbsoi.bounding_boxes) == 2
        assert np.allclose(bbsoi.bounding_boxes[0].x1, 0.0)
        assert np.allclose(bbsoi.bounding_boxes[0].y1, 0.0)
        assert np.allclose(bbsoi.bounding_boxes[0].x2, 1.0)
        assert np.allclose(bbsoi.bounding_boxes[0].y2, 1.0)
        assert np.allclose(bbsoi.bounding_boxes[1].x1, 1.0)
        assert np.allclose(bbsoi.bounding_boxes[1].y1, 2.0)
        assert np.allclose(bbsoi.bounding_boxes[1].x2, 3.0)
        assert np.allclose(bbsoi.bounding_boxes[1].y2, 4.0)
        assert bbsoi.shape == (40, 50, 3) 
Example #28
Source File: test_bbs.py    From imgaug with MIT License 5 votes vote down vote up
def test_deepcopy_bounding_boxes_set(self):
        bb1 = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
        bb2 = ia.BoundingBox(y1=15, x1=25, y2=35, x2=51)
        bb3 = ia.BoundingBox(y1=15+1, x1=25+1, y2=35+1, x2=51+1)
        bbsoi = ia.BoundingBoxesOnImage([bb1, bb2], shape=(40, 50, 3))

        bbsoi_copy = bbsoi.deepcopy(bounding_boxes=[bb3])

        assert bbsoi_copy is not bbsoi
        assert bbsoi_copy.shape == (40, 50, 3)
        assert bbsoi_copy.bounding_boxes == [bb3] 
Example #29
Source File: test_bbs.py    From imgaug with MIT License 5 votes vote down vote up
def test_copy_shape_set(self):
        bb1 = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
        bb2 = ia.BoundingBox(y1=15, x1=25, y2=35, x2=51)
        bbsoi = ia.BoundingBoxesOnImage([bb1, bb2], shape=(40, 50, 3))

        bbsoi_copy = bbsoi.copy(shape=(40+1, 50+1, 3))

        assert bbsoi_copy is not bbsoi
        assert bbsoi_copy.shape == (40+1, 50+1, 3)
        assert bbsoi_copy.bounding_boxes == [bb1, bb2] 
Example #30
Source File: test_bbs.py    From imgaug with MIT License 5 votes vote down vote up
def test___iter___empty(self):
        cbasoi = ia.BoundingBoxesOnImage([], shape=(40, 50, 3))
        i = 0
        for _cba in cbasoi:
            i += 1
        assert i == 0