Beispiel #1
0
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
Beispiel #3
0
def test_convert_bbox_from_albumentations(bbox, target_format, expected):
    image = np.ones((100, 100, 3))
    converted_bbox = convert_bbox_from_albumentations(
        bbox,
        rows=image.shape[0],
        cols=image.shape[1],
        target_format=target_format)
    assert np.all(np.isclose(converted_bbox, expected))