• 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
    手与大脑的距离决定了理想与现实的相似度
  • 相关阅读:
    浅谈python web三大框架
    Mysql异常
    格式化时间转换
    MySql存储日期为long型,判断时间大小
    Linux下部署项目
    excel
    Tomcate的启动问题
    计算时间差
    地图系的转换
    关于获取本机真实IP
  • 原文地址:https://www.cnblogs.com/houjun/p/15132898.html
Copyright © 2020-2023  润新知