添加涂抹关键词自定义偏移量功能

This commit is contained in:
2024-07-26 14:12:43 +08:00
parent 22fa38525f
commit 1dcb4aadd2
2 changed files with 6 additions and 2 deletions

View File

@@ -14,12 +14,16 @@ SEND_ERROR_EMAIL = True
关键词配置
"""
# 使用正则匹配
# key: 正则表达式
# length: 涂抹的长度
# offset: 涂抹的偏移量,基于正则匹配的开头偏移。如果不写,默认偏移量为匹配到的字符串长度,即从匹配到的字符串结尾开始涂抹
NAME_KEYS = [
{"key": "^名[:|]$", "length": 3}, # 可能误涂
{"key": "^名[:|]$", "length": 3},
{"key": "[姓|娃|生]名", "length": 4},
{"key": "款人", "length": 4},
{"key": "[交|文][^病]?人", "length": 4},
{"key": "购买方名称", "length": 4},
{"key": "[|(]个人[|)]", "length": 3, "offset": -3},
]
ID_CARD_NUM_KEYS = [
{"key": "[身]?份证号", "length": 19},

View File

@@ -150,7 +150,7 @@ def get_mask_layout(image, name, id_card_num):
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"])
boxes += find_boxes(m, layout, offset=key.get("offset", len(m)), length=key["length"])
if match_list:
break
return boxes