def iou_rotate_calculate(boxs1, boxs2):
ious = []
for i in range(len(boxs1)):
box1= boxs1[i]
box2 = boxs2[i]
area1 = box1[2] * box1[3]
area2 = box2[2] * box2[3]
#r1 = ((int(box1[0] * 100), int(box1[1] * 100)), (int(box1[2] * 100), int(box1[3] * 100)), int(box1[4] * 100))
r1 = ((int(box1[0] ), int(box1[1] )), (int(box1[2] ), int(box1[3] )), int(box1[4] ))
r2 = ((int(box2[0]), int(box2[1])), (int(box2[2]), int(box2[3])), int(box2[4]))
int_pts = cv2.rotatedRectangleIntersection(r1, r2)[1]
if int_pts is not None:
order_pts = cv2.convexHull(int_pts, returnPoints=True)
intersec = cv2.contourArea(order_pts)
union = area1 + area2 - intersec
iou = intersec * 1.0 / union
else:
iou = 0.0
ious.append(iou)
return 1-torch.tensor(sum(ious)/8)
输入中心点,宽高,角度