两个Bounding Box的IOU计算代码

本文介绍了一种计算两个边界框(BoundingBox)交并比(IOU)的方法,使用numpy进行高效运算,确保了输入边界框坐标尺寸正确,并通过实例代码展示了计算过程。

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

Bounding Box的数据结构为(xmin,ymin,xmax,ymax)

输入:box1,box2

输出:IOU值

import numpy as np
def iou(box1,box2):
    assert box1.size()==4 and box2.size()==4,"bounding box coordinate size must be 4"
      bxmin = np.max(box1[0],box2[0])
      bymin = np.max(box1[1],box2[1])
      bxmax = np.min(box1[2],box2[2])
      bymax = np.min(box1[3],box2[3])
      bwidth = bxmax-bxmin
      bhight = bymax-bxmin
      inter = bwidth*bhight
      union = (box1[2]-box1[0])*(box1[3]-box1[1])+(box2[2]-box2[0])*(box2[3]-box2[1])-inter
      return inter/union

 

     

 

转载于:https://www.cnblogs.com/houjun/p/10454166.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值