-
-
Save ppushp7/a3bdafb19acc9ed20c6d0b4ad1f15b48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def iou(box1, box2): | |
""" | |
box1 -- first box, list object with coordinates (x1, y1, x2, y2) | |
box2 -- second box, list object with coordinates (x1, y1, x2, y2) | |
""" | |
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 = (yi2-yi1)*(xi2-xi1) | |
box1_area = (box1[2]-box1[0])*(box1[3]-box1[1]) | |
box2_area = (box2[2]-box2[0])*(box2[3]-box2[1]) | |
union_area = box1_area+box2_area-inter_area | |
# compute the IoU | |
iou = inter_area/union_area | |
return iou | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment