fix merge
Showing
3 changed files
with
49 additions
and
3 deletions
... | @@ -1568,6 +1568,12 @@ BC_FIELD_ORDER_2 = (('BankName', '发卡行名称'), | ... | @@ -1568,6 +1568,12 @@ BC_FIELD_ORDER_2 = (('BankName', '发卡行名称'), |
1568 | 1568 | ||
1569 | IMG_PATH_KEY = 'uniq_img_path_key' | 1569 | IMG_PATH_KEY = 'uniq_img_path_key' |
1570 | IMG_PATH_KEY_2 = 'uniq_img_path_key_2' | 1570 | IMG_PATH_KEY_2 = 'uniq_img_path_key_2' |
1571 | SECTION_IMG_PATH_KEY = 'uniq_section_img_path_key' | ||
1572 | ALL_POSITION_KEY = 'uniq_all_position_key' | ||
1573 | POSITION_KEY = 'uniq_position_key' | ||
1574 | ANGLE_KEY = 'uniq_angle_key' | ||
1575 | FIELD_POSITION_KEY = 'position' | ||
1576 | FIELD_QUAD_KEY = 'quad' | ||
1571 | 1577 | ||
1572 | INFO_SOURCE = ['POS', 'CMS'] | 1578 | INFO_SOURCE = ['POS', 'CMS'] |
1573 | 1579 | ... | ... |
... | @@ -378,7 +378,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -378,7 +378,7 @@ class Command(BaseCommand, LoggerMixin): |
378 | license_summary.setdefault(classify, []).extend(license_data) | 378 | license_summary.setdefault(classify, []).extend(license_data) |
379 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) | 379 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) |
380 | 380 | ||
381 | 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): | 381 | 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): |
382 | if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET: | 382 | if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET: |
383 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) | 383 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) |
384 | if pid == consts.BC_PID: | 384 | if pid == consts.BC_PID: |
... | @@ -394,12 +394,51 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -394,12 +394,51 @@ class Command(BaseCommand, LoggerMixin): |
394 | dda_id_bc_mapping.setdefault(consts.BC_FIELD, []).append((bc_no, img_path)) | 394 | dda_id_bc_mapping.setdefault(consts.BC_FIELD, []).append((bc_no, img_path)) |
395 | else: | 395 | else: |
396 | # 营业执照等 | 396 | # 营业执照等 |
397 | for result_dict in ocr_res_2.get('ResultList', []): | 397 | pre, suf = os.path.splitext(img_path) |
398 | src_section_img_path = img_path if file_data is None else '{0}_{1}{2}'.format(pre, part_idx, suf) | ||
399 | |||
400 | is_save = False | ||
401 | for res_idx, result_dict in enumerate(ocr_res_2.get('ResultList', [])): | ||
402 | image_data = result_dict.get('image_data', '') | ||
403 | if len(image_data) > 0: | ||
404 | position = {} | ||
405 | angle = 0 | ||
406 | section_img_path = '{0}_{1}_{2}{3}'.format(pre, part_idx, res_idx, suf) | ||
407 | try: | ||
408 | with open(section_img_path, "wb") as fh: | ||
409 | fh.write(base64.b64decode(image_data.encode())) | ||
410 | except Exception as e: | ||
411 | self.online_log.warn( | ||
412 | '{0} [section img save failed] [img_path={1}]' | ||
413 | ' [part_idx={2}] [res_idx={3}]'.format(self.log_base, img_path, part_idx, res_idx)) | ||
414 | else: | ||
415 | is_save = True | ||
416 | section_img_path = src_section_img_path | ||
417 | position = result_dict.get('position', {}) | ||
418 | angle = result_dict.get('angle', 0) | ||
398 | res_dict = {} | 419 | res_dict = {} |
420 | position_dict = {} | ||
399 | for field_dict in result_dict.get('FieldList', []): | 421 | for field_dict in result_dict.get('FieldList', []): |
400 | res_dict[field_dict.get('chn_key', '')] = field_dict.get('value', '') | 422 | res_dict[field_dict.get('chn_key', '')] = field_dict.get('value', '') |
423 | position_dict[field_dict.get('chn_key', '')] = { | ||
424 | consts.FIELD_POSITION_KEY: field_dict.get('position', {}), | ||
425 | consts.FIELD_QUAD_KEY: field_dict.get('quad', []), | ||
426 | } | ||
427 | position_dict[consts.POSITION_KEY] = position | ||
428 | position_dict[consts.ANGLE_KEY] = angle | ||
401 | res_dict[consts.IMG_PATH_KEY] = img_path | 429 | res_dict[consts.IMG_PATH_KEY] = img_path |
430 | res_dict[consts.SECTION_IMG_PATH_KEY] = section_img_path | ||
431 | res_dict[consts.ALL_POSITION_KEY] = position_dict | ||
402 | license_summary.setdefault(classify, []).append(res_dict) | 432 | license_summary.setdefault(classify, []).append(res_dict) |
433 | |||
434 | if is_save and file_data is not None: | ||
435 | try: | ||
436 | with open(src_section_img_path, "wb") as fh: | ||
437 | fh.write(base64.b64decode(file_data.encode())) | ||
438 | except Exception as e: | ||
439 | self.online_log.warn( | ||
440 | '{0} [section img save failed] [img_path={1}]' | ||
441 | ' [part_idx={2}]'.format(self.log_base, img_path, part_idx)) | ||
403 | else: | 442 | else: |
404 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) | 443 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) |
405 | 444 | ||
... | @@ -978,9 +1017,10 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -978,9 +1017,10 @@ class Command(BaseCommand, LoggerMixin): |
978 | card_name_res.get('data', {}).get('is_exists_name') == 0: | 1017 | card_name_res.get('data', {}).get('is_exists_name') == 0: |
979 | name = '无' | 1018 | name = '无' |
980 | ocr_2_res['Name'] = name | 1019 | ocr_2_res['Name'] = name |
1020 | |||
981 | self.license2_process(ocr_2_res, license_summary, pid, classify, | 1021 | self.license2_process(ocr_2_res, license_summary, pid, classify, |
982 | res_list, pno, ino, part_idx, img_path, | 1022 | res_list, pno, ino, part_idx, img_path, |
983 | do_dda, dda_id_bc_mapping) | 1023 | do_dda, dda_id_bc_mapping, file_data=ocr_data.get('section_img')) |
984 | break | 1024 | break |
985 | else: | 1025 | else: |
986 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) | 1026 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment