def overlap_ratio_pair(boxes1, boxes2):
# find intersection bbox
x_int_bot = np.maximum(boxes1[:, 0], boxes2[:, 0])
x_int_top = np.minimum(boxes1[:, 0] + boxes1[:, 2], boxes2[:, 0] + boxes2[:, 2])
y_int_bot = np.maximum(boxes1[:, 1], boxes2[:, 1])
y_int_top = np.minimum(boxes1[:, 1] + boxes1[:, 3], boxes2[:, 1] + boxes2[:, 3])
# find intersection area
dx = x_int_top - x_int_bot
dy = y_int_top - y_int_bot
area_int = np.where(np.logical_and(dx>0, dy>0), dx * dy, np.zeros_like(dx))
# find union
area_union = boxes1[:,2] * boxes1[:,3] + boxes2[:, 2] * boxes2[:, 3] - area_int
# find overlap ratio
ratio = np.where(area_union > 0, area_int/area_union, np.zeros_like(area_int))
return ratio
评论列表
文章目录