优化涂抹精度提升算法

This commit is contained in:
2024-07-25 16:05:18 +08:00
parent 3538e9d19d
commit 353e8572ef

View File

@@ -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]: