优化关键词涂抹的判断

This commit is contained in:
2024-07-25 15:47:31 +08:00
parent d0407d568e
commit 3538e9d19d

View File

@@ -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)