#计算IOU

法一:

def compute_iou(rec1, rec2):
    """
    computing IoU
    :param rec1: (y0, x0, y1, x1), which reflects (bottom,left,top,right)
    :param rec2: (y0, x0, y1, x1)
    :return: value of IoU
    """
    # computing area of each rectangles
    S_rec1 = (rec1[2] - rec1[0]) * (rec1[3] - rec1[1])
    S_rec2 = (rec2[2] - rec2[0]) * (rec2[3] - rec2[1])
    # computing the sum_area
    sum_area = S_rec1 + S_rec2
    print(sum_area)
    # find the each edge of intersect rectangle
    left_line = max(rec1[1], rec2[1])
    right_line = min(rec1[3], rec2[3])
    bottom_line = max(rec1[0], rec2[0])
    top_line = min(rec1[2], rec2[2])
    print(left_line)
    print(right_line)
    print(bottom_line)
    print(top_line)
    # judge if there is an intersect
    if left_line >= right_line or bottom_line >= top_line:
        return 0
    else:
        intersect = (right_line - left_line) * (top_line - bottom_line)
        print(intersect)
        return ( intersect / (sum_area - intersect))
rect1 = [661, 23, 679, 57]
rect2 = [662, 27, 682, 47]
print(compute_iou(rect1, rect2))

法二:看两个矩形框的左上角和右下角坐标值,其实也异曲同工

IOU_W = min(x1, x2, x3, x4) + w1 + w2 - max(x1, x2, x3, x4)
IOU_H = min(y1, y2, y3, y4) + h1 + h2 - max(y1, y2, y3, y4)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值