I have more than two bounding boxes where I want to calculate the intersection over union. I have done it for two bounding boxes but is there a way to accommodate more than two bounding boxes?
I have tried this with two bounding boxes
def intersection_over_union(self,image,humanRegion_bbs, belongings_bbs):
"""
Calculate overlap between two bounding boxes [x, y, w, h] as
the area of intersection over the area of unity
"""
if len(humanRegion_bbs)== 4 and len(belongings_bbs) == 4 :
x1, y1, w1, h1 = (humanRegion_bbs[0], humanRegion_bbs[1],
humanRegion_bbs[2], humanRegion_bbs[3])
x2, y2, w2, h2 = (belongings_bbs[0], belongings_bbs[1],
belongings_bbs[2], belongings_bbs[3])
w_I = min(x1 + w1, x2 + w2) - max(x1, x2)
h_I = min(y1 + h1, y2 + h2) - max(y1, y2)
if w_I <= 0 or h_I <= 0: # no overlap
return 0
intersection_area = w_I * h_I
union = w1 * h1 + w2 * h2 - intersection_area
# intersection over union
iou = intersection_area / union
return iou
I want to check the intersection over union between humanRegion_bbs
and an array of belongings_bbs
. The array of belongings_bbs
is of length 4.
How should I apporach this problem?
intersection
andunion
when there are multiplebelongings_bbs
rectangles? – Deliquescence