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

被折叠的 条评论
为什么被折叠?



