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)
Exemple #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 = [(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)
    def boxes_postprocessing(self, data):
        rows, cols = data['image'].shape[:2]
        data['bboxes'] = filter_bboxes(data['bboxes'], rows, cols,
                                       self.min_area, self.min_visibility)

        data['bboxes'] = convert_bboxes_from_albumentations(
            data['bboxes'], self.bbox_format, rows, cols, check_validity=True)

        if self.label_fields:
            for idx, field in enumerate(self.label_fields):
                field_values = []
                for bbox in data['bboxes']:
                    field_values.append(bbox[4 + idx])
                data[field] = field_values
            data['bboxes'] = [bbox[:4] for bbox in data['bboxes']]
        return data
Exemple #4
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
 def __call__(self, **args):
     if args.get('bboxes') is None: return args
     args['bboxes'] = np.array(convert_bboxes_from_albumentations(args.get('bboxes'), 'pascal_voc', args['image'].shape[1], args['image'].shape[2]))
     return args