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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
import cv2
import unittest
from dyda_utils import tools
from dyda_utils import tinycv
from dyda_utils import lab_tools
from dyda_utils import dict_comparator
from dyda.components.determinator import DeterminatorSizeThreshold
input_data = {
"folder": None,
"filename": None,
"size": {
"width": 100,
"height": 50
},
"annotations": [
{"top": 0, "bottom": 5, "left": 0, "right": 15, "id": 0},
{"top": 20, "bottom": 30, "left": 0, "right": 20, "id": 1},
{"top": 30, "bottom": 50, "left": 20, "right": 50, "id": 2}
]
}
output_data = {
"folder": None,
"filename": None,
"size": {
"width": 100,
"height": 50
},
"annotations": [
{"top": 20, "bottom": 30, "left": 0, "right": 20, "id": 0},
{"top": 30, "bottom": 50, "left": 20, "right": 50, "id": 1}
]
}
dyda_config_digit = {
"DeterminatorSizeThreshold": {"threshold": 0.1}}
dyda_config_pixel = {
"DeterminatorSizeThreshold": {"threshold": 10}}
class TestDeterminatorSizeThreshold_dict_thres_digit(unittest.TestCase):
""" Test case of inputting a dictionary with treshold less than one. """
def test_main_process(self):
""" Main process of unit test. """
# initialization
comp = DeterminatorSizeThreshold(
dyda_config_path=dyda_config_digit)
# run component
comp.reset()
comp.input_data = input_data
comp.run()
# compare output_data with reference
ref_data = output_data
tar_data = comp.results
report = dict_comparator.get_diff(ref_data, tar_data)
self.assertEqual(report['extra_field'], [])
self.assertEqual(report['missing_field'], [])
self.assertEqual(report['mismatch_val'], [])
class TestDeterminatorSizeThreshold_dict_thres_pixel(unittest.TestCase):
""" Test case of inputting a dictionary with threshold greater than one. """
def test_main_process(self):
""" Main process of unit test. """
# initialization
comp = DeterminatorSizeThreshold(
dyda_config_path=dyda_config_pixel)
# run component
comp.reset()
comp.input_data = input_data
comp.run()
# compare output_data with reference
ref_data = output_data
tar_data = comp.results
report = dict_comparator.get_diff(ref_data, tar_data)
self.assertEqual(report['extra_field'], [])
self.assertEqual(report['missing_field'], [])
self.assertEqual(report['mismatch_val'], [])
class TestDeterminatorSizeThreshold_list_thres_digit(unittest.TestCase):
""" Test case of inputting a list of dictionaries with threshold less than one. """
def test_main_process(self):
""" Main process of unit test. """
# initialization
comp = DeterminatorSizeThreshold(
dyda_config_path=dyda_config_digit)
# run component
comp.reset()
comp.input_data = [input_data]
comp.run()
# compare output_data with reference
ref_data = [output_data]
tar_data = comp.results
report = dict_comparator.get_diff(ref_data, tar_data)
self.assertEqual(report['extra_field'], [])
self.assertEqual(report['missing_field'], [])
self.assertEqual(report['mismatch_val'], [])
class TestDeterminatorSizeThreshold_list_thres_pixel(unittest.TestCase):
""" Test case of inputting a list of dictionaries with threshold greater than one. """
def test_main_process(self):
""" Main process of unit test. """
# initialization
comp = DeterminatorSizeThreshold(
dyda_config_path=dyda_config_pixel)
# run component
comp.reset()
comp.input_data = [input_data]
comp.run()
# compare output_data with reference
ref_data = [output_data]
tar_data = comp.results
report = dict_comparator.get_diff(ref_data, tar_data)
self.assertEqual(report['extra_field'], [])
self.assertEqual(report['missing_field'], [])
self.assertEqual(report['mismatch_val'], [])
if __name__ == '__main__':
unittest.main()
|