-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathtest_OCR.py
More file actions
111 lines (84 loc) · 3.58 KB
/
test_OCR.py
File metadata and controls
111 lines (84 loc) · 3.58 KB
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
import unittest
from OCR import OCR
from Screen import *
def dummy_cb(msg, body=None):
pass
class OCRTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
from ED_AP import EDAutopilot
cls.ed_ap = EDAutopilot(cb=dummy_cb)
def test_simple_OCR(self):
""" Simple check of OCR to bring back text of a know image. """
ocr = OCR(self.ed_ap, screen=None)
# Load image
image_path = 'test/ocr/ocr-test1.png'
orig_image = cv2.imread(image_path)
ocr_textlist = ocr.image_simple_ocr(orig_image, 'test')
actual = str(ocr_textlist)
expected = "['DESTINATION', 'SIRIUS ATMOSPHERICS']"
self.assertEqual(actual, expected) # add assertion here
def test_OCR(self):
""" Simple check of OCR to bring back text of a know image. """
ocr = OCR(self.ed_ap, screen=None)
# Load image
image_path = 'test/ocr/6-selected_item.png'
orig_image = cv2.imread(image_path)
ocr_data, ocr_textlist = ocr.image_ocr(orig_image, 'test')
actual = str(ocr_textlist)
expected = "['NAVIGATION']"
self.assertEqual(actual, expected) # add assertion here
def test_simple_OCR_2(self):
""" Simple check of OCR to bring back text of a know image. """
ocr = OCR(self.ed_ap, screen=None)
# Load image
image_path = 'test/disengage/Screenshot 2024-08-13 21-32-58.png'
orig_image = cv2.imread(image_path)
ocr_textlist = ocr.image_simple_ocr(orig_image, 'test')
s1 = str(ocr_textlist)
s2 = "['PRESS TO DISENGAGE']"
actual = ocr.string_similarity(s1, s2)
print(f"Dice: {actual}")
self.assertGreater(actual, 0.35) # add assertion here
def test_get_highlighted_item(self):
""" Simple check of OCR to bring back text of a know image. """
ocr = OCR(self.ed_ap, screen=None)
# Load image
image_path = 'test/ocr/tab_bar.png'
image_path = 'test/ocr/nav_panel_location_panel.png'
orig_image = cv2.imread(image_path)
# im, _, _ = ocr.get_highlighted_item_in_image(orig_image, 0.23, 0.7)
im, _ = ocr.get_highlighted_item_in_image(orig_image, 1.0, 0.08)
cv2.imwrite('test/ocr/tab_bar_out.png', im)
self.assertEqual(True, True) # add assertion here
def test_similarity_test1(self):
ocr = OCR(self.ed_ap, screen=None)
s1 = "Orbital Construction Site: Wingrove's Inheritance"
s2 = "Wingrove's Inheritance (Orbital Construction Site)"
actual = ocr.string_similarity(s1, s2)
print(f"Dice: {actual}")
self.assertGreater(actual, 0.9) # add assertion here
def test_similarity_test2(self):
ocr = OCR(self.ed_ap, screen=None)
s1 = "STAR BLAZE V2V-65W"
s2 = "STAR BLAZE (V2V-65W)"
actual = ocr.string_similarity(s1, s2)
print(f"Dice: {actual}")
self.assertGreater(actual, 0.8) # add assertion here
def test_similarity_test3(self):
ocr = OCR(self.ed_ap, screen=None)
s1 = "['STAR BLAZE V2V-65W']"
s2 = "['<STARBLAZEV2V-65W>']"
actual = ocr.string_similarity(s1, s2)
print(f"Dice: {actual}")
self.assertGreater(actual, 0.8) # add assertion here
def test_similarity_test4e(self):
ocr = OCR(self.ed_ap,
screen=None)
s1 = "['NAV BEACON']"
s2 = "['<NAVBEACON>']"
actual = ocr.string_similarity(s1, s2)
print(f"Dice: {actual}")
self.assertGreater(actual, 0.8) # add assertion here
if __name__ == '__main__':
unittest.main()