修正文字分割时的方向问题

This commit is contained in:
2024-07-10 14:58:26 +08:00
parent 312f35f832
commit c11c0c0c6e

View File

@@ -184,32 +184,72 @@ def get_ocr_layout(ocr, img_path):
def find_box_of_content(content, layout):
full_box = layout[0]
box_len = full_box[2] - full_box[0]
x_len = full_box[2] - full_box[0]
y_len = full_box[3] - full_box[1]
if x_len >= y_len:
# 横向排布
box_len = x_len
direction = "x"
else:
# 纵向排布
box_len = y_len
direction = "y"
text = layout[1]
text_len = len(text)
char_len = box_len / text_len
index = text.index(content)
if direction == "x":
# 横向排布
return (
full_box[0] + index * char_len,
full_box[1],
full_box[0] + (index + len(content) + 1) * char_len,
full_box[3],
)
else:
# 纵向排布
return (
full_box[0],
full_box[1] + index * char_len,
full_box[2],
full_box[1] + (index + len(content) + 1) * char_len,
)
def find_box_of_value(key, layout):
full_box = layout[0]
box_len = full_box[2] - full_box[0]
x_len = full_box[2] - full_box[0]
y_len = full_box[3] - full_box[1]
if x_len >= y_len:
# 横向排布
box_len = x_len
direction = "x"
else:
# 纵向排布
box_len = y_len
direction = "y"
text = layout[1]
text_len = len(text)
char_len = box_len / text_len
index = text.index(key)
if direction == "x":
# 横向排布
return (
full_box[0] + (index + len(key)) * char_len,
full_box[1],
full_box[0] + (index + len(key) + 4) * char_len,
full_box[3],
)
else:
# 纵向排布
return (
full_box[0],
full_box[1] + (index + len(key)) * char_len,
full_box[2],
full_box[1] + (index + len(key) + 4) * char_len,
)
def get_mask_layout(image, content):