zoukankan      html  css  js  c++  java
  • numpy版本iou计算

    计算两个边界框集合的iou
     1 import numpy as np
     2 
     3 
     4 def iou(gtboxes, dtboxes):
     5     '''numpy version of calculating IoU between two set of 2D bboxes.
     6 
     7     Args:
     8         gtboxes (np.ndarray): Shape (B,4) of ..,  4 present [x1,y1,x2,y2]
     9         dtboxes,np.ndarray,shape:(N,4), 4 present [x1,y1,x2,y2].
    10 
    11     Returns:
    12         np.ndarray: Shape (B,N)  .
    13     '''
    14     gtboxes = gtboxes[:, np.
    15                       newaxis, :]  #converse gtboxes:(B,4) to gtboxes:(B,1,4)
    16     ixmin = np.maximum(gtboxes[:, :, 0], dtboxes[:, 0])
    17     iymin = np.maximum(gtboxes[:, :, 1], dtboxes[:, 1])
    18     ixmax = np.minimum(gtboxes[:, :, 2], dtboxes[:, 2])
    19     iymax = np.minimum(gtboxes[:, :, 3], dtboxes[:, 3])
    20     intersection = (ixmax - ixmin + 1) * (iymax - iymin + 1)
    21     union = (gtboxes[:,:,2]-gtboxes[:,:,0]+1)*(gtboxes[:,:,3]-gtboxes[:,:,1]+1)
    22             +(dtboxes[:,2]-dtboxes[:,0]+1)*(dtboxes[:,3]-dtboxes[:,1]+1)-intersection
    23     return intersection / union
    手与大脑的距离决定了理想与现实的相似度
  • 相关阅读:
    SCCM 2007 部署软件更新
    WPF开发工具
    体验Windows Live Writer写Blog
    图像的灰度和黑白处理算法
    很有用的Sql总结转载
    WPF 体验导航窗口
    WPF 一周练
    WPF 图表
    也说Linq 分组
    WPF 体验对话框调用
  • 原文地址:https://www.cnblogs.com/houjun/p/15132898.html
Copyright © 2011-2022 走看看