在大图像中测试对象检测算法时,我们根据为地面实况矩形给出的坐标检查检测到的边界框。
根据 Pascal VOC 挑战,有这个:
A predicted bounding box is considered correct if it overlaps more than 50% with a ground-truth bounding box, otherwise the bounding box is considered a false positive detection. Multiple detections are penalized. If a system predicts several bounding boxes that overlap with a single ground-truth bounding box, only one prediction is considered correct, the others are considered false positives.
这意味着我们需要计算重叠的百分比。这是否意味着 ground truth box 被检测到的边界框覆盖了 50%?或者边界框的 50% 被地面实况框吸收了?
我已经搜索过,但我还没有找到一个标准算法 - 这令人惊讶,因为我认为这在计算机视觉中很常见。 (我是新来的)。我错过了吗?有谁知道这类问题的标准算法是什么?
最佳答案
对于轴对齐的边界框,它相对简单。 “轴对齐”意味着边界框没有旋转;或者换句话说,框线与轴平行。下面介绍如何计算两个轴对齐的边界框的 IoU。
def get_iou(bb1, bb2):
"""
Calculate the Intersection over Union (IoU) of two bounding boxes.
Parameters
----------
bb1 : dict
Keys: {'x1', 'x2', 'y1', 'y2'}
The (x1, y1) position is at the top left corner,
the (x2, y2) position is at the bottom right corner
bb2 : dict
Keys: {'x1', 'x2', 'y1', 'y2'}
The (x, y) position is at the top left corner,
the (x2, y2) position is at the bottom right corner
Returns
-------
float
in [0, 1]
"""
assert bb1['x1'] < bb1['x2']
assert bb1['y1'] < bb1['y2']
assert bb2['x1'] < bb2['x2']
assert bb2['y1'] < bb2['y2']
# determine the coordinates of the intersection rectangle
x_left = max(bb1['x1'], bb2['x1'])
y_top = max(bb1['y1'], bb2['y1'])
x_right = min(bb1['x2'], bb2['x2'])
y_bottom = min(bb1['y2'], bb2['y2'])
if x_right < x_left or y_bottom < y_top:
return 0.0
# The intersection of two axis-aligned bounding boxes is always an
# axis-aligned bounding box
intersection_area = (x_right - x_left) * (y_bottom - y_top)
# compute the area of both AABBs
bb1_area = (bb1['x2'] - bb1['x1']) * (bb1['y2'] - bb1['y1'])
bb2_area = (bb2['x2'] - bb2['x1']) * (bb2['y2'] - bb2['y1'])
# 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 = intersection_area / float(bb1_area + bb2_area - intersection_area)
assert iou >= 0.0
assert iou <= 1.0
return iou
解释
图片来自this answer
关于python - 计算边界框重叠的百分比,用于图像检测器评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25349178/