a | b/utils.py | ||
---|---|---|---|
1 | def iou(boxA, boxB): |
||
2 | xA = max(boxA[0], boxB[0]) |
||
3 | yA = max(boxA[1], boxB[1]) |
||
4 | xB = min(boxA[2], boxB[2]) |
||
5 | yB = min(boxA[3], boxB[3]) |
||
6 | |||
7 | interArea = (xB - xA + 1) * (yB - yA + 1) |
||
8 | |||
9 | if interArea < 0: |
||
10 | interArea = 0 |
||
11 | |||
12 | boxAArea = (boxA[2] - boxA[0] + 1) * (boxA[3] - boxA[1] + 1) |
||
13 | boxBArea = (boxB[2] - boxB[0] + 1) * (boxB[3] - boxB[1] + 1) |
||
14 | |||
15 | return interArea / float(boxAArea + boxBArea - interArea) |