【发布时间】:2020-03-18 15:02:28
【问题描述】:
我有图像中给出的这两个边界框。框坐标如下:
框 1 = [0.23072851 0.44545859 0.56389928 0.67707491] 框 2 = [0.22677664 0.38237819 0.85152483 0.75449795]
坐标是这样的:ymin, xmin, ymax, xmax
我按如下方式计算 IOU:
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