1.需求
计算预测框与标签框的iou大小,并判断是否满足某一阈值
2.代码实现
def get_iou(bbox1, bbox2, threshold=0.3):
"""
bbox1与bbox2为列表
"""
a1 = (bbox1[2] - bbox1[0]) * (bbox1[3] - bbox1[1])
a2 = (bbox2[2] - bbox2[0]) * (bbox2[3] - bbox2[1])
xmin = max(bbox1[0], bbox2[0])
xmax = min(bbox1[2], bbox2[2])
ymin = max(bbox1[1], bbox2[1])
ymax = min(bbox1[3], bbox2[3])
w = xmax - xmin
h = ymax - ymin
if w <= 0 or h <= 0:
return False
iou = w * h / (a1 + a2 - w * h)
if iou > threshold:
return True
return False