From 3538e9d19d232df43fe4da9b41594a0336f4b991 Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Thu, 25 Jul 2024 15:47:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=B3=E9=94=AE=E8=AF=8D?= =?UTF-8?q?=E6=B6=82=E6=8A=B9=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- photo_mask/photo_mask.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/photo_mask/photo_mask.py b/photo_mask/photo_mask.py index 0352c67..c0f15e5 100644 --- a/photo_mask/photo_mask.py +++ b/photo_mask/photo_mask.py @@ -137,16 +137,22 @@ def get_mask_layout(image, name, id_card_num): result += find_boxes(id_card_num, layout, improve=True, image_path=temp_file.name) find_id_card_num_by_key = False - keys = [] + def _find_boxes_by_keys(keys): + boxes = [] + for key in keys: + match_list = re.findall(key["key"], layout[1]) + for m in match_list: + if m in layout[1]: + boxes += find_boxes(m, layout, offset=len(m), length=key["length"]) + if matches: + break + return boxes + if find_name_by_key: - keys += NAME_KEYS + result += _find_boxes_by_keys(NAME_KEYS) if find_id_card_num_by_key: - keys += ID_CARD_NUM_KEYS - for key in keys: - matches = re.findall(key["key"], layout[1]) - for match in matches: - if match in layout[1]: - result += find_boxes(match, layout, offset=len(match), length=key["length"]) + result += _find_boxes_by_keys(ID_CARD_NUM_KEYS) + return result except Exception as e: logging.error("涂抹时出错!", exc_info=e)