目标检测中IOU的计算,python代码

主宰稳场 提交于 2020-01-26 04:03:10


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!