Rotated_IoU 计算

两个旋转矩形的IOU计算方法

# 中心点 矩形的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)

box1=np.array([[2.5, 3.5, 4.242, 2.828, 0.785]])
# box2=np.array([[2.5, 3.5, 2.828, 4.242, -0.785]])  # 0.5
# box2=np.array([[3, 2, 3.16, 3.16, 0.32]])  # 0.27
# box2=np.array([[3.5, 2.5, 4.242, 2.828, 0.785]])  # 0.33
box2=np.array([[2.5, 3.5, 3, 3, 0]])  # 0.678

a=iou_rotate_calculate(box1,box2)
print(a)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值