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)