612221a4 by 王聪

接口 update

1 parent d825a562
...@@ -179,11 +179,18 @@ class PosHandler: ...@@ -179,11 +179,18 @@ class PosHandler:
179 179
180 @staticmethod 180 @staticmethod
181 def de_mortgage_ocr_process(img_base64): 181 def de_mortgage_ocr_process(img_base64):
182 result_obj = {} 182 result_obj = {
183 'customerName': '',
184 'application': '',
185 'deMortgageDate': ''
186 }
183 url = 'http://file-classification.situdata.com/bs/all' 187 url = 'http://file-classification.situdata.com/bs/all'
184 json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY} 188 json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "version": "green"}
185 try: 189 try:
186 response = requests.post(url, json=json_data) 190 response = requests.post(url, json=json_data)
191 if response.status_code != 200:
192 return result_obj
193 response.encoding = 'unicode_escape'
187 ocr_res = response.json() 194 ocr_res = response.json()
188 results = ocr_res.get('results') 195 results = ocr_res.get('results')
189 if ocr_res.get('page', '') == 'VehicleRegArea': 196 if ocr_res.get('page', '') == 'VehicleRegArea':
...@@ -199,10 +206,41 @@ class PosHandler: ...@@ -199,10 +206,41 @@ class PosHandler:
199 info = results.get('1.机动车所有人/身份证名称/号码', {}) 206 info = results.get('1.机动车所有人/身份证名称/号码', {})
200 result_obj['customerName'] = info.get('words', '').split('/')[0] 207 result_obj['customerName'] = info.get('words', '').split('/')[0]
201 except Exception as e: 208 except Exception as e:
202 LoggerMixin.running_log.error('[PosHandler de_mortgage_ocr_process] [error={0}]'.format(e.format_exc())) 209 LoggerMixin.running_log.error("[PosHandler de_mortgage_ocr_process] error", exc_info=1)
203 result_obj = {
204 'customerName': '',
205 'application': '',
206 'deMortgageDate': ''
207 }
208 return result_obj 210 return result_obj
211
212 @staticmethod
213 def de_mortgage_ocr_process1(img_base64):
214 result_obj = {
215 'customerName': '',
216 'application': '',
217 'deMortgageDate': ''
218 }
219 url = 'http://file-classification.situdata.com/bs/all'
220 json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "version": "green"}
221 try:
222 response = requests.post(url, json=json_data)
223 if response.status_code != 200:
224 return result_obj
225 # unicode转中文
226 response.encoding = 'unicode_escape'
227 ocr_res = response.json()
228 if ocr_res.get('page', '') == 'page_34':
229 words_result = ocr_res.get('words_result', [])
230 registration_bar = words_result.get('registration_bar', [])
231 for registration in registration_bar:
232 if registration.get('register_type', '') == '抵押登记':
233 register_info = registration.get('register_info', {})
234 result_obj['application'] = register_info.get('抵押权人姓名/名称', '')
235 elif registration.get('register_type', '') == '解除抵押':
236 register_info = registration.get('register_info', {})
237 result_obj['deMortgageDate'] = register_info.get('解除抵押日期', '')
238 elif ocr_res.get('page', '') == 'page_12':
239 words_result = ocr_res.get('words_result', [])
240 for _, word_result in words_result.items():
241 if word_result.get('chinese_key', '') == '1.机动车所有人/身份证名称/号码':
242 result_obj['customerName'] = word_result.get('words', '').split('/')[0]
243 except Exception as e:
244 LoggerMixin.running_log.error("[PosHandler de_mortgage_ocr_process] error", exc_info=1)
245 return result_obj
246
......
1 import json
2
3 import requests
4 import logging
5 import base64
6
7 logger = logging.getLogger()
8
9
10 def de_mortgage_ocr_process(img_base64):
11 result_obj = {
12 'customerName': '',
13 'application': '',
14 'deMortgageDate': ''
15 }
16 url = 'http://file-classification.situdata.com/bs/all'
17 json_data = {"file": img_base64, "classify": 28, "version": "green"}
18 try:
19 response = requests.post(url, json=json_data)
20 response.encoding = 'unicode_escape'
21 ocr_res = response.json()
22 print(ocr_res)
23 # ocr_res = ocr_res.decode('unicode_escape')
24 data = ocr_res.get('data', [])
25 for classify_data in data:
26 result_data = classify_data.get('data', {})
27 results = result_data.get('results')
28 if result_data.get('page', '') == 'VehicleRegArea':
29 if results.get('register_type', -1) == 1:
30 info = results.get('解除抵押日期', {})
31 result_obj['deMortgageDate'] = info.get('words', '')
32 elif results.get('register_type', -1) == 0:
33 info = results.get('抵押权人姓名/名称', {})
34 result_obj['application'] = info.get('words', '')
35
36 elif result_data.get('page', '') == 'VehicleRCI':
37 print('----------------------')
38 info = results.get('1.机动车所有人/身份证名称/号码', {})
39 result_obj['customerName'] = info.get('words', '').split('/')[0]
40
41 except Exception as e:
42 logger.error(e)
43 # LoggerMixin.running_log.error('[PosHandler de_mortgage_ocr_process] [error={0}]'.format(e.format_exc()))
44 result_obj = {
45 'customerName': '',
46 'application': '',
47 'deMortgageDate': ''
48 }
49 return result_obj
50
51
52 de_mortgage_comments = {
53 'customerName': ('机动车所有人识别不一致', ),
54 'application': ('抵押权人姓名/名称识别不一致', ),
55 'deMortgageDate': ('解除抵押日期不一致', )
56 }
57
58
59 def view(args):
60 img_files = args.get('file_base64', [])
61 customer_name = args.get('customerName', '')
62 application = args.get('application', '')
63 de_mortgage_date = args.get('deMortgageDate')
64
65 fields_input = {
66 'customerName': customer_name,
67 'application': application,
68 'deMortgageDate': de_mortgage_date
69 }
70 de_mortgage_info = {}
71 # 绿本必须分开ocr
72 for img_file in img_files:
73 info = de_mortgage_ocr_process(img_file)
74 de_mortgage_info.update(info)
75
76 request_pass = True
77 fields_result = []
78 for field_name, input_val in fields_input.items():
79 field_result = {
80 "name": field_name,
81 "input": input_val,
82 "ocr": de_mortgage_info.get(field_name, ''),
83 "field_is_pass": False,
84 "comments": ''
85 }
86 # result, _ = cp.common_compare(field_result['input'], field_result['ocr'])
87 # if result == cp.RESULT_Y:
88 # fields_result['field_is_pass'] = result
89 # else:
90 # request_pass = False
91 # fields_result['comments'] = de_mortgage_comments.get(field_name, '')
92
93 fields_result.append(field_result)
94
95 result = {
96 "is_pass": request_pass,
97 "fields": fields_result
98 }
99 print(result)
100
101
102 if __name__ == '__main__':
103 # print(u'编号'.encode('ascii'))
104 # print(b"\u7f16\u53f7".decode('unicode_escape'))
105 img_base64 = r'C:\Users\EDY\Desktop\1280X1280 (1).PNG'
106 # img_base64 = r'C:\Users\EDY\Desktop\1280X1280.PNG'
107 with open(img_base64, 'rb') as f:
108 content = f.read()
109 args = {
110 'file_base64': [str(base64.b64encode(content), 'utf-8')]
111 }
112 view(args)
113
114
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!