From 312f35f832136b7706ba4f846425e6b4aabf76f2 Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Wed, 10 Jul 2024 14:14:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=9A=E8=BF=87=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E8=AF=8D=E5=AF=BB=E6=89=BE=E6=B6=82=E6=8A=B9=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=B6=82=E6=8A=B9=E7=9A=84=E5=86=97=E4=BD=99=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- photo_mask.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/photo_mask.py b/photo_mask.py index c696855..0cddb1e 100644 --- a/photo_mask.py +++ b/photo_mask.py @@ -192,7 +192,22 @@ def find_box_of_content(content, layout): return ( full_box[0] + index * char_len, full_box[1], - full_box[0] + (index + len(content)) * char_len, + full_box[0] + (index + len(content) + 1) * char_len, + full_box[3], + ) + + +def find_box_of_value(key, layout): + full_box = layout[0] + box_len = full_box[2] - full_box[0] + text = layout[1] + text_len = len(text) + char_len = box_len / text_len + index = text.index(key) + return ( + full_box[0] + (index + len(key)) * char_len, + full_box[1], + full_box[0] + (index + len(key) + 4) * char_len, full_box[3], ) @@ -212,6 +227,12 @@ def get_mask_layout(image, content): for layout in layouts: if content in layout[1]: result.append(find_box_of_content(content, layout)) + if "姓名" in layout[1]: + result.append(find_box_of_value("姓名", layout)) + if "交款人" in layout[1]: + result.append(find_box_of_value("交款人", layout)) + if "文款人" in layout[1]: + result.append(find_box_of_value("文款人", layout)) return result except Exception as e: logging.error("涂抹时出错", exc_info=e)