fix mvc slice
Showing
2 changed files
with
78 additions
and
14 deletions
... | @@ -452,14 +452,17 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -452,14 +452,17 @@ class Command(BaseCommand, LoggerMixin): |
452 | detail_dict.get('words', '')) | 452 | detail_dict.get('words', '')) |
453 | tmp_position_list = detail_dict.get('position', [0, 0, 0, 0]) | 453 | tmp_position_list = detail_dict.get('position', [0, 0, 0, 0]) |
454 | if len(tmp_position_list) == 4: | 454 | if len(tmp_position_list) == 4: |
455 | position_dict[cn_key] = { | 455 | position_dict.setdefault(cn_key, []).append( |
456 | consts.FIELD_POSITION_KEY: { | 456 | { |
457 | 'top': tmp_position_list[1], | 457 | consts.FIELD_POSITION_KEY: { |
458 | 'left': tmp_position_list[0], | 458 | 'top': tmp_position_list[1], |
459 | 'height': tmp_position_list[-1], | 459 | 'left': tmp_position_list[0], |
460 | 'width': tmp_position_list[2], | 460 | 'height': tmp_position_list[-1], |
461 | 'width': tmp_position_list[2], | ||
462 | } | ||
461 | } | 463 | } |
462 | } | 464 | ) |
465 | |||
463 | rebuild_data_dict[consts.ALL_POSITION_KEY_2] = position_dict | 466 | rebuild_data_dict[consts.ALL_POSITION_KEY_2] = position_dict |
464 | rebuild_data_dict[consts.IMG_PATH_KEY_2] = img_path | 467 | rebuild_data_dict[consts.IMG_PATH_KEY_2] = img_path |
465 | rebuild_data_dict[consts.SECTION_IMG_PATH_KEY_2] = section_img_path | 468 | rebuild_data_dict[consts.SECTION_IMG_PATH_KEY_2] = section_img_path | ... | ... |
... | @@ -373,8 +373,8 @@ def ca_compare_license(license_en, ocr_res_dict, field_list): | ... | @@ -373,8 +373,8 @@ def ca_compare_license(license_en, ocr_res_dict, field_list): |
373 | if ocr_res_str is not None: | 373 | if ocr_res_str is not None: |
374 | ocr_res_list = json.loads(ocr_res_str) | 374 | ocr_res_list = json.loads(ocr_res_str) |
375 | 375 | ||
376 | # 副页去除 TODO 3/4页去除 | 376 | # 副页去除 3/4页去除 |
377 | if ocr_field == consts.DL_OCR_FIELD: | 377 | if ocr_field == consts.DL_OCR_FIELD or ocr_field == consts.MVC_OCR_FIELD: |
378 | tmp_list = [] | 378 | tmp_list = [] |
379 | for res in ocr_res_list: | 379 | for res in ocr_res_list: |
380 | if compare_logic['vinNo'][0] in res: | 380 | if compare_logic['vinNo'][0] in res: |
... | @@ -1433,6 +1433,15 @@ def se_compare_license(license_en, ocr_res_dict, field_list): | ... | @@ -1433,6 +1433,15 @@ def se_compare_license(license_en, ocr_res_dict, field_list): |
1433 | ocr_res_str = ocr_res_dict.get(ocr_field) | 1433 | ocr_res_str = ocr_res_dict.get(ocr_field) |
1434 | if ocr_res_str is not None: | 1434 | if ocr_res_str is not None: |
1435 | ocr_res_list = json.loads(ocr_res_str) | 1435 | ocr_res_list = json.loads(ocr_res_str) |
1436 | |||
1437 | # 3/4页去除 | ||
1438 | if ocr_field == consts.MVC_OCR_FIELD: | ||
1439 | tmp_list = [] | ||
1440 | for res in ocr_res_list: | ||
1441 | if compare_logic['vinNo'][0] in res: | ||
1442 | tmp_list.append(res) | ||
1443 | ocr_res_list = tmp_list | ||
1444 | |||
1436 | length = len(ocr_res_list) | 1445 | length = len(ocr_res_list) |
1437 | 1446 | ||
1438 | # 身份证、居住证 过期期限特殊处理 | 1447 | # 身份证、居住证 过期期限特殊处理 |
... | @@ -1571,6 +1580,7 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list): | ... | @@ -1571,6 +1580,7 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list): |
1571 | 1580 | ||
1572 | is_find = False | 1581 | is_find = False |
1573 | result_field_list = [] | 1582 | result_field_list = [] |
1583 | field_img_path_dict = dict() | ||
1574 | 1584 | ||
1575 | if ocr_res_str is not None: | 1585 | if ocr_res_str is not None: |
1576 | ocr_res_list = json.loads(ocr_res_str) | 1586 | ocr_res_list = json.loads(ocr_res_str) |
... | @@ -1580,7 +1590,8 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list): | ... | @@ -1580,7 +1590,8 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list): |
1580 | first_res = None | 1590 | first_res = None |
1581 | for res_idx in range(length-1, -1, -1): | 1591 | for res_idx in range(length-1, -1, -1): |
1582 | if consts.TRANSFER_DATE in ocr_res_list[res_idx]: | 1592 | if consts.TRANSFER_DATE in ocr_res_list[res_idx]: |
1583 | img_path = ocr_res_list[res_idx].get(consts.IMG_PATH_KEY, '') | 1593 | img_path = ocr_res_list[res_idx].get(consts.IMG_PATH_KEY_2, '') |
1594 | section_img_path = ocr_res_list[res_idx].get(consts.SECTION_IMG_PATH_KEY_2, '') | ||
1584 | for idx, transfer_date in enumerate(ocr_res_list[res_idx].get(consts.TRANSFER_DATE, [])): | 1595 | for idx, transfer_date in enumerate(ocr_res_list[res_idx].get(consts.TRANSFER_DATE, [])): |
1585 | try: | 1596 | try: |
1586 | transfer_name = ocr_res_list[res_idx].get(consts.TRANSFER_NAME, [])[idx] | 1597 | transfer_name = ocr_res_list[res_idx].get(consts.TRANSFER_NAME, [])[idx] |
... | @@ -1590,11 +1601,32 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list): | ... | @@ -1590,11 +1601,32 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list): |
1590 | transfer_num = ocr_res_list[res_idx].get(consts.TRANSFER_NUM, [])[idx] | 1601 | transfer_num = ocr_res_list[res_idx].get(consts.TRANSFER_NUM, [])[idx] |
1591 | except Exception as e: | 1602 | except Exception as e: |
1592 | transfer_num = empty_str | 1603 | transfer_num = empty_str |
1604 | try: | ||
1605 | position_info_date = ocr_res_list[res_idx].get(consts.ALL_POSITION_KEY_2, dict()).get( | ||
1606 | consts.TRANSFER_DATE, [])[idx] | ||
1607 | except Exception as e: | ||
1608 | position_info_date = {} | ||
1609 | try: | ||
1610 | position_info_name = ocr_res_list[res_idx].get(consts.ALL_POSITION_KEY_2, dict()).get( | ||
1611 | consts.TRANSFER_NAME, [])[idx] | ||
1612 | except Exception as e: | ||
1613 | position_info_name = {} | ||
1614 | try: | ||
1615 | position_info_num = ocr_res_list[res_idx].get(consts.ALL_POSITION_KEY_2, dict()).get( | ||
1616 | consts.TRANSFER_NUM, [])[idx] | ||
1617 | except Exception as e: | ||
1618 | position_info_num = {} | ||
1593 | core_info = { | 1619 | core_info = { |
1594 | consts.TRANSFER_NAME: transfer_name, | 1620 | consts.TRANSFER_NAME: transfer_name, |
1595 | consts.TRANSFER_NUM: transfer_num, | 1621 | consts.TRANSFER_NUM: transfer_num, |
1596 | consts.TRANSFER_DATE: transfer_date, | 1622 | consts.TRANSFER_DATE: transfer_date, |
1597 | consts.IMG_PATH_KEY: img_path, | 1623 | consts.IMG_PATH_KEY_2: img_path, |
1624 | consts.SECTION_IMG_PATH_KEY_2: section_img_path, | ||
1625 | consts.ALL_POSITION_KEY: { | ||
1626 | consts.TRANSFER_NAME: position_info_name, | ||
1627 | consts.TRANSFER_NUM: position_info_num, | ||
1628 | consts.TRANSFER_DATE: position_info_date, | ||
1629 | }, | ||
1598 | } | 1630 | } |
1599 | page34_date_dict.setdefault(transfer_date, []).append(core_info) | 1631 | page34_date_dict.setdefault(transfer_date, []).append(core_info) |
1600 | if first_res is None: | 1632 | if first_res is None: |
... | @@ -1613,6 +1645,8 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list): | ... | @@ -1613,6 +1645,8 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list): |
1613 | if max_date is not None or first_res is not None: | 1645 | if max_date is not None or first_res is not None: |
1614 | is_find = True | 1646 | is_find = True |
1615 | ocr_res = first_res if max_date is None else page34_date_dict[time.strftime('%Y-%m-%d', max_date)][0] | 1647 | ocr_res = first_res if max_date is None else page34_date_dict[time.strftime('%Y-%m-%d', max_date)][0] |
1648 | failed_field = [] | ||
1649 | base_img_path = ocr_res.get(consts.IMG_PATH_KEY_2, '') | ||
1616 | for name, value in field_list: | 1650 | for name, value in field_list: |
1617 | ocr_str = ocr_res.get(compare_logic[name][0]) | 1651 | ocr_str = ocr_res.get(compare_logic[name][0]) |
1618 | if not isinstance(ocr_str, str): | 1652 | if not isinstance(ocr_str, str): |
... | @@ -1620,15 +1654,42 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list): | ... | @@ -1620,15 +1654,42 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list): |
1620 | ocr_str = empty_str | 1654 | ocr_str = empty_str |
1621 | else: | 1655 | else: |
1622 | result = getattr(cp, compare_logic[name][1])(value, ocr_str, **compare_logic[name][2]) | 1656 | result = getattr(cp, compare_logic[name][1])(value, ocr_str, **compare_logic[name][2]) |
1623 | img_path = ocr_res.get(consts.IMG_PATH_KEY, '') if result == consts.RESULT_N else empty_str | 1657 | img_path = base_img_path if result == consts.RESULT_N else empty_str |
1624 | error_type = empty_error_type if result == consts.RESULT_Y else ErrorType.OCR.value | 1658 | error_type = empty_error_type if result == consts.RESULT_Y else ErrorType.OCR.value |
1625 | result_field_list.append((name, value, result, ocr_str, img_path, error_type)) | 1659 | result_field_list.append((name, value, result, ocr_str, img_path, error_type)) |
1626 | 1660 | ||
1661 | if result == consts.RESULT_N: | ||
1662 | failed_field.append(name) | ||
1663 | |||
1664 | section_img_path = ocr_res.get(consts.SECTION_IMG_PATH_KEY_2, '') | ||
1665 | if len(failed_field) > 0 and os.path.exists(section_img_path): | ||
1666 | info = ocr_res.get(consts.ALL_POSITION_KEY, {}) | ||
1667 | try: | ||
1668 | last_img = img_process(section_img_path, {}, 0) | ||
1669 | except Exception as e: | ||
1670 | for field in failed_field: | ||
1671 | field_img_path_dict[field] = base_img_path | ||
1672 | else: | ||
1673 | pre, suf = os.path.splitext(section_img_path) | ||
1674 | for field in failed_field: | ||
1675 | try: | ||
1676 | res_field = compare_logic[field][0] | ||
1677 | is_valid, coord_tuple = field_build_coordinates(info.get(res_field, {})) | ||
1678 | if is_valid: | ||
1679 | save_path = '{0}_{1}{2}'.format(pre, field, suf) | ||
1680 | field_img = last_img[coord_tuple[0]:coord_tuple[1], coord_tuple[2]:coord_tuple[3], :] | ||
1681 | cv2.imwrite(save_path, field_img) | ||
1682 | field_img_path_dict[field] = save_path | ||
1683 | else: | ||
1684 | field_img_path_dict[field] = base_img_path | ||
1685 | except Exception as e: | ||
1686 | field_img_path_dict[field] = base_img_path | ||
1687 | |||
1627 | if not is_find: | 1688 | if not is_find: |
1628 | for name, value in field_list: | 1689 | for name, value in field_list: |
1629 | result_field_list.append((name, value, consts.RESULT_N, empty_str, empty_str, ErrorType.NF.value)) | 1690 | result_field_list.append((name, value, consts.RESULT_N, empty_str, empty_str, ErrorType.NF.value)) |
1630 | 1691 | ||
1631 | return result_field_list, dict() | 1692 | return result_field_list, field_img_path_dict |
1632 | 1693 | ||
1633 | 1694 | ||
1634 | def se_compare_process(compare_info, ocr_res_dict): | 1695 | def se_compare_process(compare_info, ocr_res_dict): | ... | ... |
-
Please register or sign in to post a comment