test.py
3.66 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
112
113
114
import json
import requests
import logging
import base64
logger = logging.getLogger()
def de_mortgage_ocr_process(img_base64):
result_obj = {
'customerName': '',
'application': '',
'deMortgageDate': ''
}
url = 'http://file-classification.situdata.com/bs/all'
json_data = {"file": img_base64, "classify": 28, "version": "green"}
try:
response = requests.post(url, json=json_data)
response.encoding = 'unicode_escape'
ocr_res = response.json()
print(ocr_res)
# ocr_res = ocr_res.decode('unicode_escape')
data = ocr_res.get('data', [])
for classify_data in data:
result_data = classify_data.get('data', {})
results = result_data.get('results')
if result_data.get('page', '') == 'VehicleRegArea':
if results.get('register_type', -1) == 1:
info = results.get('解除抵押日期', {})
result_obj['deMortgageDate'] = info.get('words', '')
elif results.get('register_type', -1) == 0:
info = results.get('抵押权人姓名/名称', {})
result_obj['application'] = info.get('words', '')
elif result_data.get('page', '') == 'VehicleRCI':
print('----------------------')
info = results.get('1.机动车所有人/身份证名称/号码', {})
result_obj['customerName'] = info.get('words', '').split('/')[0]
except Exception as e:
logger.error(e)
# LoggerMixin.running_log.error('[PosHandler de_mortgage_ocr_process] [error={0}]'.format(e.format_exc()))
result_obj = {
'customerName': '',
'application': '',
'deMortgageDate': ''
}
return result_obj
de_mortgage_comments = {
'customerName': ('机动车所有人识别不一致', ),
'application': ('抵押权人姓名/名称识别不一致', ),
'deMortgageDate': ('解除抵押日期不一致', )
}
def view(args):
img_files = args.get('file_base64', [])
customer_name = args.get('customerName', '')
application = args.get('application', '')
de_mortgage_date = args.get('deMortgageDate')
fields_input = {
'customerName': customer_name,
'application': application,
'deMortgageDate': de_mortgage_date
}
de_mortgage_info = {}
# 绿本必须分开ocr
for img_file in img_files:
info = de_mortgage_ocr_process(img_file)
de_mortgage_info.update(info)
request_pass = True
fields_result = []
for field_name, input_val in fields_input.items():
field_result = {
"name": field_name,
"input": input_val,
"ocr": de_mortgage_info.get(field_name, ''),
"field_is_pass": False,
"comments": ''
}
# result, _ = cp.common_compare(field_result['input'], field_result['ocr'])
# if result == cp.RESULT_Y:
# fields_result['field_is_pass'] = result
# else:
# request_pass = False
# fields_result['comments'] = de_mortgage_comments.get(field_name, '')
fields_result.append(field_result)
result = {
"is_pass": request_pass,
"fields": fields_result
}
print(result)
if __name__ == '__main__':
# print(u'编号'.encode('ascii'))
# print(b"\u7f16\u53f7".decode('unicode_escape'))
img_base64 = r'C:\Users\EDY\Desktop\1280X1280 (1).PNG'
# img_base64 = r'C:\Users\EDY\Desktop\1280X1280.PNG'
with open(img_base64, 'rb') as f:
content = f.read()
args = {
'file_base64': [str(base64.b64encode(content), 'utf-8')]
}
view(args)