【发布时间】:2023-02-03 22:43:18
【问题描述】:
我有两个包含图像边界框信息的列表,如下所示:
Image_1 = [(10,5,2,8),(1,5,9,5),(6,1,8,0)...]
Image_2 = [(11,4,1,7),(1,6,10,6),(6,1,9,1)...]
Image_1 中的值是图像中对象的真实边界框位置,Image_2 中的值是 OCR 程序输出的边界框。我需要将 Image_1 数组中的边界框与 Image_2 数组中最接近的匹配项进行匹配。由于值会略有不同,我使用一个函数来返回并集计算的交集,如下所示:
def bb_intersection_over_union(boxA, boxB):
# determine the (x, y)-coordinates of the intersection rectangle
xA = max(boxA[0], boxB[0])
yA = max(boxA[1], boxB[1])
xB = min(boxA[2], boxB[2])
yB = min(boxA[3], boxB[3])
# compute the area of intersection rectangle
interArea = max(0, xB - xA + 1) * max(0, yB - yA + 1)
# compute the area of both the prediction and ground-truth
# rectangles
boxAArea = (boxA[2] - boxA[0] + 1) * (boxA[3] - boxA[1] + 1)
boxBArea = (boxB[2] - boxB[0] + 1) * (boxB[3] - boxB[1] + 1)
# compute the intersection over union by taking the intersection
# area and dividing it by the sum of prediction + ground-truth
# areas - the interesection area
iou = interArea / float(boxAArea + boxBArea - interArea)
# return the intersection over union value
return iou
最大的 IOU 值表示最接近的匹配。如何遍历 Image_1 和 Image_2 数组并匹配值?
【问题讨论】:
标签: python loops set-intersection