From 353e8572ef111e8f5cd6363dc43f48f10621be48 Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Thu, 25 Jul 2024 16:05:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B6=82=E6=8A=B9=E7=B2=BE?= =?UTF-8?q?=E5=BA=A6=E6=8F=90=E5=8D=87=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- photo_mask/photo_mask.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/photo_mask/photo_mask.py b/photo_mask/photo_mask.py index c0f15e5..be062d5 100644 --- a/photo_mask/photo_mask.py +++ b/photo_mask/photo_mask.py @@ -13,7 +13,7 @@ from ucloud import BUCKET, ufile from util import image_util, util -def find_boxes(content, layout, offset=0, length=None, improve=False, image_path=None): +def find_boxes(content, layout, offset=0, length=None, improve=False, image_path=None, extra_content=None): full_box = layout[0] x_len = full_box[2] - full_box[0] y_len = full_box[3] - full_box[1] @@ -67,16 +67,22 @@ def find_boxes(content, layout, offset=0, length=None, improve=False, image_path except Exception as e: # 如果出现其他错误,抛出 raise e + if extra_content: + contents = extra_content.append(content) + else: + contents = [content] for layout in layouts: - if content in layout[1]: - temp_box = find_boxes(content, layout)[0] - if temp_box: - boxes.append([ - temp_box[0] + capture_box[0] - offset_x, - temp_box[1] + capture_box[1] - offset_y, - temp_box[2] + capture_box[0] - offset_x, - temp_box[3] + capture_box[1] - offset_y, - ]) + for c in contents: + if c in layout[1]: + temp_box = find_boxes(content, layout)[0] + if temp_box: + boxes.append([ + temp_box[0] + capture_box[0] - offset_x, + temp_box[1] + capture_box[1] - offset_y, + temp_box[2] + capture_box[0] - offset_x, + temp_box[3] + capture_box[1] - offset_y, + ]) + break util.delete_temp_file(temp_file.name) if not boxes: @@ -130,7 +136,8 @@ def get_mask_layout(image, name, id_card_num): matches = re.findall(r, layout[1]) for match in matches: if match in layout[1]: - result += find_boxes(match, layout, improve=True, image_path=temp_file.name) + result += find_boxes(match, layout, improve=True, image_path=temp_file.name, + extra_content=name_list) find_name_by_key = False break if id_card_num in layout[1]: