def IoU(box, bboxes):
"""
Caculate IoU between detect and ground truth boxes
:param box:numpy array (4, )
:param bboxes:numpy array (n, 4):x1, y1, x2, y2
:return:
numpy array, shape (n, ) Iou
"""
box_area = (box[2] - box[0] + 1) * (box[3] - box[1] + 1)
areas = (bboxes[:, 2] - bboxes[:, 0] + 1) * (bboxes[:, 3] - bboxes[:, 1] + 1)
xx1 = np.maximum(box[0], bboxes[:, 0])
yy1 = np.maximum(box[1], bboxes[:, 1])
xx2 = np.minimum(box[2], bboxes[:, 2])
yy2 = np.minimum(box[3], bboxes[:, 3])
# compute the width and height of the bounding box
w = np.maximum(0, xx2 - xx1 + 1)
h = np.maximum(0, yy2 - yy1 + 1)
inter = w * h
over = inter / (box_area + areas - inter)
return over
IOU
最新推荐文章于 2024-04-23 22:53:31 发布