def batch_iou(proposals, gt):
bboxes = np.transpose(proposals).reshape((4, -1, 1))
bboxes_x1 = bboxes[0]
bboxes_x2 = bboxes[0]+bboxes[2]
bboxes_y1 = bboxes[1]
bboxes_y2 = bboxes[1]+bboxes[3]
gt = np.transpose(gt).reshape((4, 1, -1))
gt_x1 = gt[0]
gt_x2 = gt[0]+gt[2]
gt_y1 = gt[1]
gt_y2 = gt[1]+gt[3]
widths = np.maximum(0, np.minimum(bboxes_x2, gt_x2) -
np.maximum(bboxes_x1, gt_x1))
heights = np.maximum(0, np.minimum(bboxes_y2, gt_y2) -
np.maximum(bboxes_y1, gt_y1))
intersection = widths*heights
union = bboxes[2]*bboxes[3] + gt[2]*gt[3] - intersection
return (intersection / union)
评论列表
文章目录