# 中心点坐标、矩形的宽和高、旋转角(单位是角度,不是弧度)
def iou_rotate_calculate(box1, box2):
    area1 = box1[2] * box1[3]
    area2 = box2[2] * box2[3]
    r1 = ((box1[0], box1[1]), (box1[2], box1[3]), box1[4])
    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)
        intersec = cv2.contourArea(order_pts)
        union = area1 + area2 - intersec
        iou = intersec * 1.0 / union
    else:
        iou = 0.0
    return iou

box1 = [30, 40, 40, 80, 0]
box2 = [30, 40, 40, 80, 90]
iou = iou_rotate_calculate(box1,box2)
print(iou)

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐