Ejemplo n.º 1
0
def test_convert_bboxes_from_albumentations():
    bboxes = [[0.2, 0.3, 0.6, 0.8], [0.3, 0.4, 0.7, 0.9, 99]]
    image = np.ones((100, 100, 3))
    converted_bboxes = convert_bboxes_to_albumentations(bboxes, rows=image.shape[0], cols=image.shape[1],
                                                        source_format='coco')
    converted_bbox_1 = convert_bbox_to_albumentations(bboxes[0], rows=image.shape[0], cols=image.shape[1],
                                                      source_format='coco')
    converted_bbox_2 = convert_bbox_to_albumentations(bboxes[1], rows=image.shape[0], cols=image.shape[1],
                                                      source_format='coco')
    assert converted_bboxes == [converted_bbox_1, converted_bbox_2]
Ejemplo n.º 2
0
def test_imagaug_fliplr_transform_bboxes(image):
    aug = IAAFliplr(p=1)
    mask = np.copy(image)
    bboxes = [(10, 10, 20, 20), (20, 10, 30, 40)]
    expect = [(79, 10, 89, 20), (69, 10, 79, 40)]
    bboxes = convert_bboxes_to_albumentations(bboxes, 'pascal_voc', rows=image.shape[0], cols=image.shape[1])
    data = aug(image=image, mask=mask, bboxes=bboxes)
    actual = convert_bboxes_from_albumentations(data['bboxes'], 'pascal_voc', rows=image.shape[0], cols=image.shape[1])
    assert np.array_equal(data['image'], data['mask'])
    assert np.allclose(actual, expect)
Ejemplo n.º 3
0
def test_convert_bboxes_to_albumentations():
    bboxes = [[20, 30, 40, 50], [30, 40, 50, 60, 99]]
    image = np.ones((100, 100, 3))
    converted_bboxes = convert_bboxes_to_albumentations(bboxes, rows=image.shape[0], cols=image.shape[1],
                                                        source_format='coco')
    converted_bbox_1 = convert_bbox_to_albumentations(bboxes[0], rows=image.shape[0], cols=image.shape[1],
                                                      source_format='coco')
    converted_bbox_2 = convert_bbox_to_albumentations(bboxes[1], rows=image.shape[0], cols=image.shape[1],
                                                      source_format='coco')
    assert converted_bboxes == [converted_bbox_1, converted_bbox_2]
Ejemplo n.º 4
0
def test_imagaug_fliplr_transform_bboxes(image):
    aug = IAAFliplr(p=1)
    mask = np.copy(image)
    bboxes = [(10, 10, 20, 20), (20, 10, 30, 40)]
    expect = [(80, 10, 90, 20), (70, 10, 80, 40)]
    bboxes = convert_bboxes_to_albumentations(bboxes, "pascal_voc", rows=image.shape[0], cols=image.shape[1])
    data = aug(image=image, mask=mask, bboxes=bboxes)
    actual = convert_bboxes_from_albumentations(data["bboxes"], "pascal_voc", rows=image.shape[0], cols=image.shape[1])
    assert np.array_equal(data["image"], data["mask"])
    assert np.allclose(actual, expect)
Ejemplo n.º 5
0
    def boxes_preprocessing(self, data):
        if 'bboxes' not in data:
            raise Exception('Please name field with bounding boxes `bboxes`')
        if self.label_fields:
            for field in self.label_fields:
                bboxes_with_added_field = []
                for bbox, field_value in zip(data['bboxes'], data[field]):
                    bboxes_with_added_field.append(list(bbox) + [field_value])
                data['bboxes'] = bboxes_with_added_field

        rows, cols = data['image'].shape[:2]
        data['bboxes'] = convert_bboxes_to_albumentations(data['bboxes'],
                                                          self.bbox_format,
                                                          rows,
                                                          cols,
                                                          check_validity=True)

        return data
Ejemplo n.º 6
0
def convert_bboxes_format(bboxes, src_format, tgt_format, image_h, image_w):
    image_params = {'rows': image_h, 'cols': image_w, 'check_validity': True}
    bboxes = bbox_utils.convert_bboxes_to_albumentations(bboxes, src_format, **image_params)
    bboxes = bbox_utils.convert_bboxes_from_albumentations(bboxes, tgt_format, **image_params)
    return bboxes
Ejemplo n.º 7
0
 def __call__(self, **args):
     if args.get('bboxes') is None: return args
     args['bboxes'] = np.array(convert_bboxes_to_albumentations(args.get('bboxes'), 'coco', args['image'].shape[0], args['image'].shape[1]))
     return args