IOU

Notes.

IOU: Intersection over Union, Intersection/Union

# pred_bbox = np.array([20,30,40,50]) top-left (20,30), bottom_right(40,50)

ixmin = max(pred_bbox[0], gt_bbox[0])
iymin = max(pred_bbox[1], gt_bbox[1])

ixmax = min(pred_bbox[2], gt_bbox[2])
iymax = min(pred_bbox[3], gt_bbox[3])

iw = np.maximum(ixmax - ixmin + 1.0, 0.0)
ih = np.maximum(iymax - iymin + 1.0, 0.0)

inters = iw * ih
uni = ((gt_bbox[2] - gt_bbox[0] + 1.0) * (gt_bbox[3] - gt_bbox[1] + 1.0) + (pred_bbox[2] - gt_bbox[0] + 1.0) * (gt_bbox[3] - gt_bbox[1] + 1.0))

iou = inters / uni

https://github.com/humengdoudou/object_detection_mAP/blob/master/IoU_demo.py