4d3ca7e0 by 周伟奇

slice part 2

1 parent 149b0899
......@@ -1542,9 +1542,12 @@ BC_FIELD_ORDER_2 = (('BankName', '发卡行名称'),
IMG_PATH_KEY = 'uniq_img_path_key'
IMG_PATH_KEY_2 = 'uniq_img_path_key_2'
SECTION_IMG_PATH_KEY = 'uniq_section_img_path_key'
ALL_POSITION_KEY = 'uniq_all_position_key'
POSITION_KEY = 'uniq_position_key'
SECTION_KEY = 'uniq_section_key'
ANGLE_KEY = 'uniq_angle_key'
FIELD_POSITION_KEY = 'position'
FIELD_QUAD_KEY = 'quad'
INFO_SOURCE = ['POS', 'CMS']
......
......@@ -373,7 +373,7 @@ class Command(BaseCommand, LoggerMixin):
license_summary.setdefault(classify, []).extend(license_data)
res_list.append((pno, ino, part_idx, consts.RES_SUCCESS))
def license2_process(self, ocr_res_2, license_summary, pid, classify, res_list, pno, ino, part_idx, img_path, do_dda, dda_id_bc_mapping, section_img_path=None):
def license2_process(self, ocr_res_2, license_summary, pid, classify, res_list, pno, ino, part_idx, img_path, do_dda, dda_id_bc_mapping, file_data):
if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET:
res_list.append((pno, ino, part_idx, consts.RES_SUCCESS))
if pid == consts.BC_PID:
......@@ -389,19 +389,51 @@ class Command(BaseCommand, LoggerMixin):
dda_id_bc_mapping.setdefault(consts.BC_FIELD, []).append((bc_no, img_path))
else:
# 营业执照等
for result_dict in ocr_res_2.get('ResultList', []):
pre, suf = os.path.splitext(img_path)
src_section_img_path = img_path if file_data is None else '{0}_{1}{2}'.format(pre, part_idx, suf)
is_save = False
for res_idx, result_dict in enumerate(ocr_res_2.get('ResultList', [])):
image_data = result_dict.get('image_data', '')
if len(image_data) > 0:
position = {}
angle = 0
section_img_path = '{0}_{1}_{2}{3}'.format(pre, part_idx, res_idx, suf)
try:
with open(section_img_path, "wb") as fh:
fh.write(base64.b64decode(image_data.encode()))
except Exception as e:
self.online_log.warn(
'{0} [section img save failed] [img_path={1}]'
' [part_idx={2}] [res_idx={3}]'.format(self.log_base, img_path, part_idx, res_idx))
else:
is_save = True
section_img_path = src_section_img_path
position = result_dict.get('position', {})
angle = result_dict.get('angle', 0)
res_dict = {}
position_dict = {}
for field_dict in result_dict.get('FieldList', []):
res_dict[field_dict.get('chn_key', '')] = field_dict.get('value', '')
position_dict[field_dict.get('chn_key', '')] = field_dict.get('position', [])
position_dict[consts.SECTION_KEY] = position
position_dict[field_dict.get('chn_key', '')] = {
consts.FIELD_POSITION_KEY: field_dict.get('position', {}),
consts.FIELD_QUAD_KEY: field_dict.get('quad', []),
}
position_dict[consts.POSITION_KEY] = position
position_dict[consts.ANGLE_KEY] = angle
res_dict[consts.IMG_PATH_KEY] = section_img_path if isinstance(section_img_path, str) else img_path
res_dict[consts.POSITION_KEY] = position_dict
res_dict[consts.IMG_PATH_KEY] = img_path
res_dict[consts.SECTION_IMG_PATH_KEY] = section_img_path
res_dict[consts.ALL_POSITION_KEY] = position_dict
license_summary.setdefault(classify, []).append(res_dict)
if is_save and file_data is not None:
try:
with open(src_section_img_path, "wb") as fh:
fh.write(base64.b64decode(file_data.encode()))
except Exception as e:
self.online_log.warn(
'{0} [section img save failed] [img_path={1}]'
' [part_idx={2}]'.format(self.log_base, img_path, part_idx))
else:
res_list.append((pno, ino, part_idx, consts.RES_FAILED_2))
......@@ -980,22 +1012,9 @@ class Command(BaseCommand, LoggerMixin):
name = '无'
ocr_2_res['Name'] = name
section_img_path = None
try:
if ocr_2_res.get('ErrorCode') in consts.SUCCESS_CODE_SET:
pre, suf = os.path.splitext(img_path)
section_img_path = '{0}_{1}{2}'.format(pre, part_idx, suf)
with open(section_img_path, "wb") as fh:
fh.write(base64.b64decode(file_data.encode()))
except Exception as e:
self.online_log.warn(
'{0} [section img save failed] [img_path={1}]'
' [part_idx={2}]'.format(self.log_base, img_path, part_idx))
self.license2_process(ocr_2_res, license_summary, pid, classify,
res_list, pno, ino, part_idx, img_path,
do_dda, dda_id_bc_mapping,
section_img_path=section_img_path)
do_dda, dda_id_bc_mapping, file_data=ocr_data.get('section_img'))
break
else:
res_list.append((pno, ino, part_idx, consts.RES_FAILED_2))
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!