-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
103 lines (83 loc) · 2.28 KB
/
test.py
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
import cv2
from time import sleep
import mrzscanner
from mrz.checker.td1 import TD1CodeChecker
from mrz.checker.td2 import TD2CodeChecker
from mrz.checker.td3 import TD3CodeChecker
from mrz.checker.mrva import MRVACodeChecker
from mrz.checker.mrvb import MRVBCodeChecker
def check(lines):
try:
td1_check = TD1CodeChecker(lines)
if bool(td1_check):
return "TD1", td1_check.fields()
except Exception as err:
pass
try:
td2_check = TD2CodeChecker(lines)
if bool(td2_check):
return "TD2", td2_check.fields()
except Exception as err:
pass
try:
td3_check = TD3CodeChecker(lines)
if bool(td3_check):
return "TD3", td3_check.fields()
except Exception as err:
pass
try:
mrva_check = MRVACodeChecker(lines)
if bool(mrva_check):
return "MRVA", mrva_check.fields()
except Exception as err:
pass
try:
mrvb_check = MRVBCodeChecker(lines)
if bool(mrvb_check):
return "MRVB", mrvb_check.fields()
except Exception as err:
pass
return 'No valid MRZ information found'
# set license
print('Version : ', mrzscanner.__version__)
mrzscanner.initLicense(
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
# initialize mrz scanner
scanner = mrzscanner.createInstance()
# # load MRZ model
scanner.loadModel(mrzscanner.load_settings('MRZ.json'))
# decodeFile()
print('')
print('Test decodeFile()')
s = ""
results = scanner.decodeFile("images/1.png")
for result in results:
print(result.text)
s += result.text + '\n'
print('')
print(check(s[:-1]))
# decodeMat()
print('')
print('Test decodeMat()')
s = ""
image = cv2.imread("images/2.png")
results = scanner.decodeMat(image)
for result in results:
print(result.text)
s += result.text + '\n'
print('')
print(check(s[:-1]))
# decodeMatAsync()
print('')
print('Test decodeMatAsync()')
def callback(results):
s = ""
for result in results:
print(result.text)
s += result.text + '\n'
print('')
print(check(s[:-1]))
image = cv2.imread("images/3.jpg")
scanner.addAsyncListener(callback)
scanner.decodeMatAsync(image)
sleep(1)