File size: 2,245 Bytes
24c4def
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Copyright (c) OpenMMLab. All rights reserved.
from unittest import TestCase

import numpy as np

from mmocr.visualization import BaseLocalVisualizer


class TestBaseLocalVisualizer(TestCase):

    def test_get_labels_image(self):
        labels = ['a', 'b', 'c']
        image = np.zeros((40, 40, 3), dtype=np.uint8)
        bboxes = np.array([[0, 0, 10, 10], [10, 10, 20, 20], [20, 20, 30, 30]])
        labels_image = BaseLocalVisualizer().get_labels_image(
            image,
            labels,
            bboxes=bboxes,
            auto_font_size=True,
            colors=['r', 'r', 'r', 'r'])
        self.assertEqual(labels_image.shape, (40, 40, 3))

    def test_get_polygons_image(self):
        polygons = [np.array([0, 0, 10, 10, 20, 20, 30, 30]).reshape(-1, 2)]
        image = np.zeros((40, 40, 3), dtype=np.uint8)
        polygons_image = BaseLocalVisualizer().get_polygons_image(
            image, polygons, colors=['r', 'r', 'r', 'r'])
        self.assertEqual(polygons_image.shape, (40, 40, 3))

        polygons_image = BaseLocalVisualizer().get_polygons_image(
            image, polygons, colors=['r', 'r', 'r', 'r'], filling=True)
        self.assertEqual(polygons_image.shape, (40, 40, 3))

    def test_get_bboxes_image(self):
        bboxes = np.array([[0, 0, 10, 10], [10, 10, 20, 20], [20, 20, 30, 30]])
        image = np.zeros((40, 40, 3), dtype=np.uint8)
        bboxes_image = BaseLocalVisualizer().get_bboxes_image(
            image, bboxes, colors=['r', 'r', 'r', 'r'])
        self.assertEqual(bboxes_image.shape, (40, 40, 3))

        bboxes_image = BaseLocalVisualizer().get_bboxes_image(
            image, bboxes, colors=['r', 'r', 'r', 'r'], filling=True)
        self.assertEqual(bboxes_image.shape, (40, 40, 3))

    def test_cat_images(self):
        image1 = np.zeros((40, 40, 3), dtype=np.uint8)
        image2 = np.zeros((40, 40, 3), dtype=np.uint8)
        image = BaseLocalVisualizer()._cat_image([image1, image2], axis=1)
        self.assertEqual(image.shape, (40, 80, 3))

        image = BaseLocalVisualizer()._cat_image([], axis=0)
        self.assertIsNone(image)

        image = BaseLocalVisualizer()._cat_image([image1, None], axis=0)
        self.assertEqual(image.shape, (40, 40, 3))