新增通过关键词寻找涂抹位置的方法,增加涂抹的冗余量
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user