in ocr/utils/word_to_line.py [0:0]
def _get_rect_overlap_percentage(x1, y1, w1, h1, x2, y2, w2, h2):
'''
Calculate how much (in percentage) that rect2 overlaps with rect1
'''
# Check if rect overlaps
x_overlap = (x1 + w1 >= x2 and x2 >= x1) or (x2 + w2 >= x1 and x1 >= x2)
y_overlap = (y1 + h1 >= y2 and y2 >= y1) or (y2 + h2 >= y1 and y1 >= y2)
if x_overlap and y_overlap:
intersect_size = max(0, min(x1 + w1, x2 + w2) - min(x1, x2)) * max(0, min(y1 + h1, y2 + h2) - max(y1, y2))
s1 = w1 * h1
return intersect_size / s1
else:
return 0