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)