From 45669bcde1b7aeee8901a74093422353bd1a41a1 Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Wed, 24 Jul 2024 16:48:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=85=B3=E9=94=AE=E8=AF=8D?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E4=B8=BA=E6=AD=A3=E5=88=99=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- photo_mask/__init__.py | 6 ++++-- photo_mask/photo_mask.py | 11 +++++------ photo_mask_error_check.py | 5 +++++ 3 files changed, 14 insertions(+), 8 deletions(-) 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)