调整关键词匹配为正则匹配

This commit is contained in:
2024-07-24 16:48:35 +08:00
parent 9198f5ee66
commit 45669bcde1
3 changed files with 14 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
import logging.config
import re
import tempfile
from time import sleep
@@ -127,15 +128,13 @@ def get_mask_layout(image, name, id_card_num):
keys = []
if find_name_by_key:
keys += NAME_KEYS
if layout[1].startswith("名:"):
result += find_boxes("名:", layout, offset=2, length=3)
if layout[1].startswith("名:"):
result += find_boxes("名:", layout, offset=2, length=3)
if find_id_card_num_by_key:
keys += ID_CARD_NUM_KEYS
for key in keys:
if key["key"] in layout[1]:
result += find_boxes(key["key"], layout, offset=len(key["key"]), length=key["length"])
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"])
return result
except Exception as e:
logging.error("涂抹时出错!", exc_info=e)