Open aissam-out opened 5 years ago
Correct Code -
### START CODE HERE ### (≈ 7 lines)
yi1 = max(box1[1], box2[1])
xi1 = max(box1[0], box2[0])
yi1 = max(box1[1], box2[1])
xi2 = min(box1[2], box2[2])
yi2 = min(box1[3], box2[3])
inter_area = (xi2 - xi1)*(yi2 - yi1)
inter_area = max((xi2 - xi1), 0)*max((yi2 - yi1), 0)
### END CODE HERE ###
It will give you following results :
iou for intersecting boxes = 0.14285714285714285 iou for non-intersecting boxes = 0.0 iou for boxes that only touch at vertices = 0.0 iou for boxes that only touch at edges = 0.0
In order to compute the intersection area, you need to make sure the height and width of the intersection are positive, otherwise the intersection area should be zero.