def compute_iou(gt_box,b_box):
'''
计算iou
:param gt_box: ground truth gt_box = [x0,y0,x1,y1](x0,y0)为左上角的坐标(x1,y1)为右下角的坐标
:param b_box: bounding box b_box 表示形式同上
:return:
'''
width0=gt_box[2]-gt_box[0]
height0 = gt_box[3] - gt_box[1]
width1 = b_box[2] - b_box[0]
height1 = b_box[3] - b_box[1]
max_x =max(gt_box[2],b_box[2])
min_x = min(gt_box[0],b_box[0])
width = width0 + width1 -(max_x-min_x)
max_y = max(gt_box[3],b_box[3])
min_y = min(gt_box[1],b_box[1])
height = height0 + height1 - (max_y - min_y)
interArea = width * height
boxAArea = width0 * height0
boxBArea = width1 * height1
iou = interArea / (boxAArea + boxBArea - interArea)
return iou
目标检测中IOU的计算,python代码
最新推荐文章于 2023-06-05 11:31:33 发布