24ed4007 by 周伟奇

Merge branch 'feature/slice4' into feature/1119

2 parents ebc29c21 a10caee4
......@@ -64,6 +64,7 @@ class Command(BaseCommand, LoggerMixin):
# ocr相关
self.ocr_1_urls = conf.get_namespace('OCR_URL_1_')
self.ocr_url_2 = conf.OCR_URL_2
self.ocr_url_2_bc = conf.OCR_URL_2_BC
self.ocr_url_3 = conf.BC_URL
self.ocr_url_4 = conf.IC_URL
# EDMS web_service_api
......@@ -1212,11 +1213,12 @@ class Command(BaseCommand, LoggerMixin):
"pid": str(pid),
"filedata": file_data
}
ocr_url_2 = self.ocr_url_2_bc if classify == consts.BC_CLASSIFY else self.ocr_url_2
for times in range(consts.RETRY_TIMES):
try:
start_time = time.time()
ocr_2_response = requests.post(self.ocr_url_2, data=json_data_2)
ocr_2_response = requests.post(ocr_url_2, data=json_data_2)
if ocr_2_response.status_code != 200:
raise OCR2Exception('ocr_2 status code: {0}'.format(ocr_2_response.status_code))
except Exception as e:
......@@ -1232,20 +1234,81 @@ class Command(BaseCommand, LoggerMixin):
self.log_base, img_path, speed_time))
if classify == consts.BC_CLASSIFY:
name = '有'
json_data_3 = {
"file": file_data,
'card_res': ocr_2_res
}
card_name_response = requests.post(self.ocr_url_3, json_data_3)
if card_name_response.status_code == 200:
card_name_res = card_name_response.json()
if isinstance(card_name_res, dict) and \
card_name_res.get('data', {}).get('is_exists_name') == 0:
name = '无'
ocr_2_res['Name'] = name
self.license2_process(ocr_2_res, license_summary, pid, classify,
new_ocr_2_res = {}
position_dict = {}
get_info = False
bc_image_data = ''
position = {}
angle = 0
for page_info in ocr_2_res.get('PageInfo', []):
if get_info:
break
if page_info.get('ErrorCode', 1) in consts.SUCCESS_CODE_SET:
for bc_res_all in page_info.get('Result', []):
if get_info:
break
if bc_res_all.get('ErrorCode', 1) in consts.SUCCESS_CODE_SET:
for bc_res in bc_res_all.get('ResultList', []):
if get_info:
break
get_info = True
bc_image_data = bc_res.get('image_data', '')
position = bc_res.get('position', {})
angle = bc_res.get('angle', 0)
for field_info in bc_res.get('FieldList', []):
new_ocr_2_res[field_info.get('key', '')] = field_info.get('value', '')
position_dict[field_info.get('key', '')] = {
consts.FIELD_POSITION_KEY: field_info.get('position', {}),
consts.FIELD_QUAD_KEY: field_info.get('quad', []),
}
if get_info:
pre, suf = os.path.splitext(img_path)
if len(bc_image_data) > 0:
position = {}
angle = 0
section_img_path = '{0}_{1}_0{2}'.format(pre, part_idx, suf)
try:
with open(section_img_path, "wb") as fh:
fh.write(base64.b64decode(bc_image_data.encode()))
except Exception as e:
self.online_log.warn(
'{0} [bc section img save failed] [img_path={1}]'
' [part_idx={2}]]'.format(self.log_base, img_path, part_idx))
else:
section_img_path = img_path if ocr_data.get('section_img') is None else '{0}_{1}{2}'.format(pre, part_idx, suf)
if ocr_data.get('section_img') is not None:
try:
with open(section_img_path, "wb") as fh:
fh.write(base64.b64decode(ocr_data.get('section_img').encode()))
except Exception as e:
self.online_log.warn(
'{0} [bc section img save failed] [img_path={1}]'
' [part_idx={2}]'.format(self.log_base,
img_path, part_idx))
new_ocr_2_res['ErrorCode'] = 0
position_dict[consts.POSITION_KEY] = position
position_dict[consts.ANGLE_KEY] = angle
new_ocr_2_res[consts.SECTION_IMG_PATH_KEY] = section_img_path
new_ocr_2_res[consts.ALL_POSITION_KEY] = position_dict
name = '有'
json_data_3 = {
"file": file_data,
'card_res': new_ocr_2_res
}
card_name_response = requests.post(self.ocr_url_3, json_data_3)
if card_name_response.status_code == 200:
card_name_res = card_name_response.json()
if isinstance(card_name_res, dict) and \
card_name_res.get('data', {}).get('is_exists_name') == 0:
name = '无'
new_ocr_2_res['Name'] = name
else:
new_ocr_2_res = ocr_2_res
self.license2_process(new_ocr_2_res, license_summary, pid, classify,
res_list, pno, ino, part_idx, img_path,
do_dda, dda_id_bc_mapping, file_data=ocr_data.get('section_img'))
break
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!