slice part 2
Showing
3 changed files
with
45 additions
and
23 deletions
... | @@ -1542,9 +1542,12 @@ BC_FIELD_ORDER_2 = (('BankName', '发卡行名称'), | ... | @@ -1542,9 +1542,12 @@ BC_FIELD_ORDER_2 = (('BankName', '发卡行名称'), |
1542 | 1542 | ||
1543 | IMG_PATH_KEY = 'uniq_img_path_key' | 1543 | IMG_PATH_KEY = 'uniq_img_path_key' |
1544 | IMG_PATH_KEY_2 = 'uniq_img_path_key_2' | 1544 | IMG_PATH_KEY_2 = 'uniq_img_path_key_2' |
1545 | SECTION_IMG_PATH_KEY = 'uniq_section_img_path_key' | ||
1546 | ALL_POSITION_KEY = 'uniq_all_position_key' | ||
1545 | POSITION_KEY = 'uniq_position_key' | 1547 | POSITION_KEY = 'uniq_position_key' |
1546 | SECTION_KEY = 'uniq_section_key' | ||
1547 | ANGLE_KEY = 'uniq_angle_key' | 1548 | ANGLE_KEY = 'uniq_angle_key' |
1549 | FIELD_POSITION_KEY = 'position' | ||
1550 | FIELD_QUAD_KEY = 'quad' | ||
1548 | 1551 | ||
1549 | INFO_SOURCE = ['POS', 'CMS'] | 1552 | INFO_SOURCE = ['POS', 'CMS'] |
1550 | 1553 | ... | ... |
... | @@ -373,7 +373,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -373,7 +373,7 @@ class Command(BaseCommand, LoggerMixin): |
373 | license_summary.setdefault(classify, []).extend(license_data) | 373 | license_summary.setdefault(classify, []).extend(license_data) |
374 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) | 374 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) |
375 | 375 | ||
376 | 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): | 376 | 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): |
377 | if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET: | 377 | if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET: |
378 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) | 378 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) |
379 | if pid == consts.BC_PID: | 379 | if pid == consts.BC_PID: |
... | @@ -389,19 +389,51 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -389,19 +389,51 @@ class Command(BaseCommand, LoggerMixin): |
389 | dda_id_bc_mapping.setdefault(consts.BC_FIELD, []).append((bc_no, img_path)) | 389 | dda_id_bc_mapping.setdefault(consts.BC_FIELD, []).append((bc_no, img_path)) |
390 | else: | 390 | else: |
391 | # 营业执照等 | 391 | # 营业执照等 |
392 | for result_dict in ocr_res_2.get('ResultList', []): | 392 | pre, suf = os.path.splitext(img_path) |
393 | position = result_dict.get('position', {}) | 393 | src_section_img_path = img_path if file_data is None else '{0}_{1}{2}'.format(pre, part_idx, suf) |
394 | angle = result_dict.get('angle', 0) | 394 | |
395 | is_save = False | ||
396 | for res_idx, result_dict in enumerate(ocr_res_2.get('ResultList', [])): | ||
397 | image_data = result_dict.get('image_data', '') | ||
398 | if len(image_data) > 0: | ||
399 | position = {} | ||
400 | angle = 0 | ||
401 | section_img_path = '{0}_{1}_{2}{3}'.format(pre, part_idx, res_idx, suf) | ||
402 | try: | ||
403 | with open(section_img_path, "wb") as fh: | ||
404 | fh.write(base64.b64decode(image_data.encode())) | ||
405 | except Exception as e: | ||
406 | self.online_log.warn( | ||
407 | '{0} [section img save failed] [img_path={1}]' | ||
408 | ' [part_idx={2}] [res_idx={3}]'.format(self.log_base, img_path, part_idx, res_idx)) | ||
409 | else: | ||
410 | is_save = True | ||
411 | section_img_path = src_section_img_path | ||
412 | position = result_dict.get('position', {}) | ||
413 | angle = result_dict.get('angle', 0) | ||
395 | res_dict = {} | 414 | res_dict = {} |
396 | position_dict = {} | 415 | position_dict = {} |
397 | for field_dict in result_dict.get('FieldList', []): | 416 | for field_dict in result_dict.get('FieldList', []): |
398 | res_dict[field_dict.get('chn_key', '')] = field_dict.get('value', '') | 417 | res_dict[field_dict.get('chn_key', '')] = field_dict.get('value', '') |
399 | position_dict[field_dict.get('chn_key', '')] = field_dict.get('position', []) | 418 | position_dict[field_dict.get('chn_key', '')] = { |
400 | position_dict[consts.SECTION_KEY] = position | 419 | consts.FIELD_POSITION_KEY: field_dict.get('position', {}), |
420 | consts.FIELD_QUAD_KEY: field_dict.get('quad', []), | ||
421 | } | ||
422 | position_dict[consts.POSITION_KEY] = position | ||
401 | position_dict[consts.ANGLE_KEY] = angle | 423 | position_dict[consts.ANGLE_KEY] = angle |
402 | res_dict[consts.IMG_PATH_KEY] = section_img_path if isinstance(section_img_path, str) else img_path | 424 | res_dict[consts.IMG_PATH_KEY] = img_path |
403 | res_dict[consts.POSITION_KEY] = position_dict | 425 | res_dict[consts.SECTION_IMG_PATH_KEY] = section_img_path |
426 | res_dict[consts.ALL_POSITION_KEY] = position_dict | ||
404 | license_summary.setdefault(classify, []).append(res_dict) | 427 | license_summary.setdefault(classify, []).append(res_dict) |
428 | |||
429 | if is_save and file_data is not None: | ||
430 | try: | ||
431 | with open(src_section_img_path, "wb") as fh: | ||
432 | fh.write(base64.b64decode(file_data.encode())) | ||
433 | except Exception as e: | ||
434 | self.online_log.warn( | ||
435 | '{0} [section img save failed] [img_path={1}]' | ||
436 | ' [part_idx={2}]'.format(self.log_base, img_path, part_idx)) | ||
405 | else: | 437 | else: |
406 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) | 438 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) |
407 | 439 | ||
... | @@ -980,22 +1012,9 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -980,22 +1012,9 @@ class Command(BaseCommand, LoggerMixin): |
980 | name = '无' | 1012 | name = '无' |
981 | ocr_2_res['Name'] = name | 1013 | ocr_2_res['Name'] = name |
982 | 1014 | ||
983 | section_img_path = None | ||
984 | try: | ||
985 | if ocr_2_res.get('ErrorCode') in consts.SUCCESS_CODE_SET: | ||
986 | pre, suf = os.path.splitext(img_path) | ||
987 | section_img_path = '{0}_{1}{2}'.format(pre, part_idx, suf) | ||
988 | with open(section_img_path, "wb") as fh: | ||
989 | fh.write(base64.b64decode(file_data.encode())) | ||
990 | except Exception as e: | ||
991 | self.online_log.warn( | ||
992 | '{0} [section img save failed] [img_path={1}]' | ||
993 | ' [part_idx={2}]'.format(self.log_base, img_path, part_idx)) | ||
994 | |||
995 | self.license2_process(ocr_2_res, license_summary, pid, classify, | 1015 | self.license2_process(ocr_2_res, license_summary, pid, classify, |
996 | res_list, pno, ino, part_idx, img_path, | 1016 | res_list, pno, ino, part_idx, img_path, |
997 | do_dda, dda_id_bc_mapping, | 1017 | do_dda, dda_id_bc_mapping, file_data=ocr_data.get('section_img')) |
998 | section_img_path=section_img_path) | ||
999 | break | 1018 | break |
1000 | else: | 1019 | else: |
1001 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) | 1020 | 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