diff --git a/photo_mask/__init__.py b/photo_mask/__init__.py index 8211fb0..42ad427 100644 --- a/photo_mask/__init__.py +++ b/photo_mask/__init__.py @@ -13,10 +13,12 @@ SEND_ERROR_EMAIL = True """ 关键词配置 """ +# 使用正则匹配 NAME_KEYS = [ - {"key": "姓名", "length": 4}, - {"key": "娃名", "length": 4}, + {"key": "^名[:|:]", "length": 3}, + {"key": "[姓|娃]名", "length": 4}, {"key": "款人", "length": 4}, + {"key": "交.人", "length": 4}, {"key": "购买方名称", "length": 4}, ] ID_CARD_NUM_KEYS = [{"key": "身份证号", "length": 19}, ] diff --git a/photo_mask/photo_mask.py b/photo_mask/photo_mask.py index fe3fae9..6657675 100644 --- a/photo_mask/photo_mask.py +++ b/photo_mask/photo_mask.py @@ -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) diff --git a/photo_mask_error_check.py b/photo_mask_error_check.py index f6b9ecb..f57801d 100644 --- a/photo_mask_error_check.py +++ b/photo_mask_error_check.py @@ -25,6 +25,11 @@ if __name__ == '__main__': ocr_error = (session.query(ZxIeOcrerror.pk_phrec, ZxIeOcrerror.cXm, ZxIeOcrerror.cSfzh, ZxIeOcrerror.cfjaddress) .filter(ZxIeOcrerror.checktime.is_(None)).order_by(ZxIeOcrerror.pk_phrec.desc()).limit(1).one()) session.close() + # ocr_error = ZxIeOcrerror() + # ocr_error.pk_phrec = 24594061 + # ocr_error.cXm = "" + # ocr_error.cSfzh = "" + # ocr_error.cfjaddress = "" final_img_url = ufile.get_private_url(ocr_error.cfjaddress, "drg100") final_image = image_util.read(final_img_url)