计算边界框预测的IOU

问题描述 投票:1回答:1

enter image description here

我有图像中给出的这两个边界框。框坐标如下:

框1 = [0.23072851 0.44545859 0.56389928 0.67707491]框2 = [0.22677664 0.38237819 0.85152483 0.75449795]

坐标是这样的:ymin,xmin,ymax,xmax

我正在计算欠条如下:

def get_iou(box1, box2):
"""Implement the intersection over union (IoU) between box1 and box2
    
    Arguments:
    box1 -- first box, numpy array with coordinates (ymin, xmin, ymax, xmax)
    box2 -- second box, numpy array with coordinates (ymin, xmin, ymax, xmax)
    """
# ymin, xmin, ymax, xmax = box

y11, x11, y21, x21 = box1
y12, x12, y22, x22 = box2

yi1 = max(y11, y12)
xi1 = max(x11, x12)
yi2 = min(y21, y22)
xi2 = min(x21, x22)
inter_area = max(((xi2 - xi1) * (yi2 - yi1)), 0)
# Calculate the Union area by using Formula: Union(A,B) = A + B - Inter(A,B)
box1_area = (x21 - x11) * (y21 - y11)
box2_area = (x22 - x12) * (y22 - y12)
union_area = box1_area + box2_area - inter_area
# compute the IoU
iou = inter_area / union_area
return iou

基于我的理解,这两个方框完全重叠,因此IOU应该为1。但是我得到的IOU为0.33193138665968164。是否有我做错的事情或以错误的方式解释了它。在这方面的任何建议都将有所帮助。

object-detection
1个回答
0
投票

您正在以错误的方式解释IoU。

如果注意您的示例,您会注意到两个边界框的面积的并集比面积的相交要大得多。因此,IoU(实际上是交叉点/联合)比一个小得多是有道理的。

© www.soinside.com 2019 - 2024. All rights reserved.