612221a4 by 王聪

接口 update

1 parent d825a562
......@@ -179,11 +179,18 @@ class PosHandler:
@staticmethod
def de_mortgage_ocr_process(img_base64):
result_obj = {}
result_obj = {
'customerName': '',
'application': '',
'deMortgageDate': ''
}
url = 'http://file-classification.situdata.com/bs/all'
json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY}
json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "version": "green"}
try:
response = requests.post(url, json=json_data)
if response.status_code != 200:
return result_obj
response.encoding = 'unicode_escape'
ocr_res = response.json()
results = ocr_res.get('results')
if ocr_res.get('page', '') == 'VehicleRegArea':
......@@ -199,10 +206,41 @@ class PosHandler:
info = results.get('1.机动车所有人/身份证名称/号码', {})
result_obj['customerName'] = info.get('words', '').split('/')[0]
except Exception as e:
LoggerMixin.running_log.error('[PosHandler de_mortgage_ocr_process] [error={0}]'.format(e.format_exc()))
result_obj = {
'customerName': '',
'application': '',
'deMortgageDate': ''
}
LoggerMixin.running_log.error("[PosHandler de_mortgage_ocr_process] error", exc_info=1)
return result_obj
@staticmethod
def de_mortgage_ocr_process1(img_base64):
result_obj = {
'customerName': '',
'application': '',
'deMortgageDate': ''
}
url = 'http://file-classification.situdata.com/bs/all'
json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "version": "green"}
try:
response = requests.post(url, json=json_data)
if response.status_code != 200:
return result_obj
# unicode转中文
response.encoding = 'unicode_escape'
ocr_res = response.json()
if ocr_res.get('page', '') == 'page_34':
words_result = ocr_res.get('words_result', [])
registration_bar = words_result.get('registration_bar', [])
for registration in registration_bar:
if registration.get('register_type', '') == '抵押登记':
register_info = registration.get('register_info', {})
result_obj['application'] = register_info.get('抵押权人姓名/名称', '')
elif registration.get('register_type', '') == '解除抵押':
register_info = registration.get('register_info', {})
result_obj['deMortgageDate'] = register_info.get('解除抵押日期', '')
elif ocr_res.get('page', '') == 'page_12':
words_result = ocr_res.get('words_result', [])
for _, word_result in words_result.items():
if word_result.get('chinese_key', '') == '1.机动车所有人/身份证名称/号码':
result_obj['customerName'] = word_result.get('words', '').split('/')[0]
except Exception as e:
LoggerMixin.running_log.error("[PosHandler de_mortgage_ocr_process] error", exc_info=1)
return result_obj
......
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)
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!