Spaces:
Runtime error
Runtime error
File size: 1,472 Bytes
2366e36 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import mmocr.datasets.pipelines.dbnet_transforms as transforms
def test_imgaug():
args = [['Fliplr', 0.5],
dict(cls='Affine', rotate=[-10, 10]), ['Resize', [0.5, 3.0]]]
imgaug = transforms.ImgAug(args)
img = np.random.rand(3, 100, 200)
poly = np.array([[[0, 0, 50, 0, 50, 50, 0, 50]],
[[20, 20, 50, 20, 50, 50, 20, 50]]])
box = np.array([[0, 0, 50, 50], [20, 20, 50, 50]])
results = dict(img=img, masks=poly, bboxes=box)
results['mask_fields'] = ['masks']
results['bbox_fields'] = ['bboxes']
results = imgaug(results)
assert np.allclose(results['bboxes'][0],
results['masks'].masks[0][0][[0, 1, 4, 5]])
assert np.allclose(results['bboxes'][1],
results['masks'].masks[1][0][[0, 1, 4, 5]])
def test_eastrandomcrop():
crop = transforms.EastRandomCrop(target_size=(60, 60), max_tries=100)
img = np.random.rand(3, 100, 200)
poly = np.array([[[0, 0, 50, 0, 50, 50, 0, 50]],
[[20, 20, 50, 20, 50, 50, 20, 50]]])
box = np.array([[0, 0, 50, 50], [20, 20, 50, 50]])
results = dict(img=img, gt_masks=poly, bboxes=box)
results['mask_fields'] = ['gt_masks']
results['bbox_fields'] = ['bboxes']
results = crop(results)
assert np.allclose(results['bboxes'][0],
results['gt_masks'].masks[0][0][[0, 2]].flatten())
|