计算两个边界框集合的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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2022-01-17
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
猜你喜欢
  • 2022-01-07
  • 2022-02-08
  • 2021-07-01
  • 2022-01-13
  • 2021-09-28
  • 2021-11-13
  • 2021-05-21
相关资源
相似解决方案