-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiou.py
More file actions
27 lines (23 loc) · 1.04 KB
/
iou.py
File metadata and controls
27 lines (23 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def bb_intersection_over_union(boxA, boxB):
# determine the (x, y)-coordinates of the intersection rectangle
xA = max(boxA[0][0], boxB[0][0])
yA = max(boxA[0][1], boxB[0][1])
xB = min(boxA[1][0], boxB[1][0])
yB = min(boxA[1][1], boxB[1][1])
# compute the area of intersection rectangle
interArea = abs(max((xB - xA, 0)) * max((yB - yA), 0))
if interArea == 0:
return 0
# compute the area of both the prediction and ground-truth
# rectangles
boxAArea = abs((boxA[1][0] - boxA[0][0]) * (boxA[1][1] - boxA[0][1]))
boxBArea = abs((boxB[1][0] - boxB[0][0]) * (boxB[1][1] - boxB[0][1]))
# compute the intersection over union by taking the intersection
# area and dividing it by the sum of prediction + ground-truth
# areas - the interesection area
iou = interArea / float(boxAArea + boxBArea - interArea)
# return the intersection over union value
return iou
if __name__=="__main__":
x=bb_intersection_over_union([[1233, 1804], [1447, 1972]], [[1233, 2328], [1447, 2496]])
print(x)