旋转矩阵iou

本文详细描述了一个名为defiou_rotate_calculate的函数,用于计算两个旋转矩形之间的交并比(IntersectionoverUnion,IoU)。该函数通过OpenCV库进行几何操作,计算出IoU值,最后将平均IoU转换为PyTorch张量。这个功能可能在目标检测或图像处理的深度学习项目中有所应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)

输入中心点,宽高,角度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值