File size: 2,369 Bytes
40a6098
 
aaa1b64
40a6098
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aaa1b64
40a6098
 
 
 
aaa1b64
40a6098
 
 
aaa1b64
40a6098
 
 
aaa1b64
40a6098
 
 
aaa1b64
40a6098
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
from app.custom_mmcv.color import color_val
from app.custom_mmcv.main import imshow_det_bboxes
from app.constants import class_names
import mmcv
import cv2
import numpy as np
import pytest
class TestCustomMMCV():
    def test_color_var(self):
        assert color_val("black") == (0, 0, 0)
        with pytest.raises(KeyError):
            color_val("purple")
        with pytest.raises(AssertionError):
            color_val(300)
        assert color_val(255) == (255,255,255)
        with pytest.raises(AssertionError):
            color_val(300)
        assert color_val(np.array([20,255,40])) == (20,255,40)
        with pytest.raises(AssertionError):
            color_val(np.array([20,350,40]))
        with pytest.raises(AssertionError):
            color_val(np.array([0,200,40,40]))
        with pytest.raises(AssertionError):
            color_val(np.array([-30,0,40,40]))
        with pytest.raises(AssertionError):
            color_val(np.zeros((1,3)))
        with pytest.raises(TypeError):
            color_val(30.5)
    def test_imshow_det_bboxes(self):
        image = mmcv.imread('demo.jpg')
        bboxes = np.ones((1,5))
        labels = np.zeros(1, dtype=np.int32)
        result = imshow_det_bboxes(image, bboxes, labels, class_names=class_names, bbox_color="red", text_color='red')
        assert (result[1,1,:] == (0,0,255)).all()
        with pytest.raises(AssertionError):
            bboxes = np.ones((1,3))
            labels = np.zeros(1, dtype=np.int32)
            result = imshow_det_bboxes(image, bboxes, labels, class_names=class_names, bbox_color="red",text_color="red")
        with pytest.raises(AssertionError):
            bboxes = np.ones((1,7))
            labels = np.zeros(1, dtype=np.int32)
            result = imshow_det_bboxes(image, bboxes, labels, class_names=class_names, bbox_color="red",text_color="red")
        with pytest.raises(AssertionError):
            bboxes = np.ones((1,5))
            labels = np.zeros(4, dtype=np.int32)
            result = imshow_det_bboxes(image, bboxes, labels, class_names=class_names, bbox_color="red",text_color="red")
        with pytest.raises(AssertionError):
            bboxes = np.ones((2,5))
            labels = np.zeros(1, dtype=np.int32)
            result = imshow_det_bboxes(image, bboxes, labels, class_names=class_names, bbox_color="red",text_color="red")