1、概念
IOU(Intersection-over-Union)是目标检测中使用的一个概念,是产生的候选框(candidate bounding box)与真实标记的框(ground truth bounding box)的重叠程度,候选框与真实框之间交集与并集的比值叫IOU
2、图示
3、计算公式
4、IOU计算的Python实现
def cacluteIOU(candidateBbox,groundBbox):
cx1 = candidateBbox[0]
cx2 = candidateBbox[1]
cy1 = candidateBbox[2]
cy2 = candidateBbox[3]
gx1 = groundBbox[0]
gx2 = groundBbox[1]
gy1 = groundBbox[2]
gy2 = groundBbox[3]
areaC = (cx2 - cx1)*(cy2 - cy1)
areaG = (gx2 - gx1)*(gy2 - gy1)
# C&G area
w = max(0,(min(cx2,gx2) - max(cx1,gx1)))
h = max(0,(min(cy2,gy2) - max(cy1,gy1)))
area = w*h
iou = area/(areaC+areaG - area)
return iou