两个Bounding Box的IOU计算代码

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

 

     

 

posted @ 2019-02-28 23:52  HOU_JUN  阅读(3677)  评论(0编辑  收藏  举报