我有两个以上的边界框,我想在其中计算联合的交点。我已经为两个边界框做到了,但是有没有办法容纳两个以上边界框?
我尝试了两个边界框
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
我想检查humanRegion_bbs
与belongings_bbs
数组之间的并集交集。 belongings_bbs
的数组长度为4。
我应该如何解决这个问题?