-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_of_iou.py
37 lines (31 loc) · 1.24 KB
/
test_of_iou.py
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
28
29
30
31
32
33
34
35
36
37
import numpy as np
import cv2
# ÖÐÐĵ㠾ØÐεÄw h, ÐýתµÄtheta£¨½Ç¶È£¬²»ÊÇ»¡¶È£©
def iou_rotate_calculate(boxes1, boxes2):
area1 = boxes1[:, 2] * boxes1[:, 3]
area2 = boxes2[:, 2] * boxes2[:, 3]
ious = []
for i, box1 in enumerate(boxes1):
temp_ious = []
r1 = ((box1[0], box1[1]), (box1[2], box1[3]), box1[4])
for j, box2 in enumerate(boxes2):
r2 = ((box2[0], box2[1]), (box2[2], box2[3]), box2[4])
int_pts = cv2.rotatedRectangleIntersection(r1, r2)[1]
if int_pts is not None:
order_pts = cv2.convexHull(int_pts, returnPoints=True)
int_area = cv2.contourArea(order_pts)
inter = int_area * 1.0 / (area1[i] + area2[j] - int_area)
temp_ious.append(inter)
else:
temp_ious.append(0.0)
ious.append(temp_ious)
return np.array(ious, dtype=np.float32)
if __name__ == '__main__':
Cbox1 = [10, 10, 1, 6, 80]
Cbox2 = [10, 10, 1, 6, 85]
box1 = [10, 10, 3, 3, 80]
box2 = [10, 10, 3, 3, 85]
Cbox_IOU = iou_rotate_calculate(Cbox1, Cbox2)
box_IOU = iou_rotate_calculate(box1, box2)
print("Cbox_IOU", Cbox_IOU)
print("box_IOU", box_IOU)