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]
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]
def test_convert_bbox_to_albumentations_and_back(bbox, bbox_format): image = np.ones((100, 100, 3)) converted_bbox = convert_bbox_to_albumentations(bbox, rows=image.shape[0], cols=image.shape[1], source_format=bbox_format) converted_back_bbox = convert_bbox_from_albumentations(converted_bbox, rows=image.shape[0], cols=image.shape[1], target_format=bbox_format) assert converted_back_bbox == bbox
def apply_to_bbox(self, bbox, **params): if self.source_format == self.target_format: return bbox rows = params['rows'] cols = params['cols'] if self.source_format == 'albumentations': return convert_bbox_from_albumentations( bbox, self.target_format, rows, cols, self.check_validity) elif self.target_format == 'albumentations': return convert_bbox_to_albumentations( bbox, self.source_format, rows, cols, self.check_validity) else: if self.check_validity: check_bbox(bbox) if self.target_format == 'pascal_voc': return self._convert_to_pascal_voc(bbox, rows, cols) elif self.target_format == 'coco': return self._convert_to_coco(bbox, rows, cols) elif self.target_format == 'yolo': return self._convert_to_yolo(bbox, rows, cols) return bbox
def test_convert_bbox_to_albumentations(bbox, source_format, expected): image = np.ones((100, 100, 3)) converted_bbox = convert_bbox_to_albumentations( bbox, rows=image.shape[0], cols=image.shape[1], source_format=source_format ) assert np.all(np.isclose(converted_bbox, expected))