我正在阅读论文:Ferrari et al.在“亲和力测量”部分。我明白法拉利等人。试图获得亲和力:
但是,我有两个主要问题:
对上述问题的任何建议或解决方案?谢谢你,非常感谢你的帮助。
1)您有两个重叠的边界框。您计算框的交集,这是重叠的区域。您计算重叠框的并集,即整个框的面积减去重叠面积的总和。然后用联合划分交叉点。计算机视觉系统工具箱中有一个名为bboxOverlapRatio的功能。
2)通常,您不希望连接颜色通道。您想要的是3D直方图,其中尺寸为H,S和V.
尝试在Union上交叉
Union on Union是一种评估指标,用于衡量特定数据集上对象检测器的准确性。
更正式地说,为了应用Intersection over Union来评估(任意)对象检测器,我们需要:
下面我已经包含了一个地面真实边界框与预测边界框的视觉示例:
预测的边界框用红色绘制,而地面实况(即手工标记)边界框用绿色绘制。
在上图中,我们可以看到我们的物体探测器已经检测到图像中存在停止符号。
因此,可以通过以下方式确定计算联盟的交叉点:
只要我们有这两组边界框,我们就可以在Union上应用Intersection。
这是Python代码
# import the necessary packages
from collections import namedtuple
import numpy as np
import cv2
# define the `Detection` object
Detection = namedtuple("Detection", ["image_path", "gt", "pred"])
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 = (xB - xA) * (yB - yA)
# compute the area of both the prediction and ground-truth
# rectangles
boxAArea = (boxA[2] - boxA[0]) * (boxA[3] - boxA[1])
boxBArea = (boxB[2] - boxB[0]) * (boxB[3] - boxB[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
gt
和pred
是
gt
:真实的边界框。pred
:我们模型中预测的边界框。有关更多信息,请单击this post
目前的答案已经清楚地解释了这个问题。所以在这里我提供了一个更好的IoU版本与Python,当两个边界框不相交时不会破坏。
import numpy as np
def IoU(box1: np.ndarray, box2: np.ndarray):
"""
calculate intersection over union cover percent
:param box1: box1 with shape (N,4) or (N,2,2) or (2,2) or (4,). first shape is preferred
:param box2: box2 with shape (N,4) or (N,2,2) or (2,2) or (4,). first shape is preferred
:return: IoU ratio if intersect, else 0
"""
# first unify all boxes to shape (N,4)
if box1.shape[-1] == 2 or len(box1.shape) == 1:
box1 = box1.reshape(1, 4) if len(box1.shape) <= 2 else box1.reshape(box1.shape[0], 4)
if box2.shape[-1] == 2 or len(box2.shape) == 1:
box2 = box2.reshape(1, 4) if len(box2.shape) <= 2 else box2.reshape(box2.shape[0], 4)
point_num = max(box1.shape[0], box2.shape[0])
b1p1, b1p2, b2p1, b2p2 = box1[:, :2], box1[:, 2:], box2[:, :2], box2[:, 2:]
# mask that eliminates non-intersecting matrices
base_mat = np.ones(shape=(point_num,))
base_mat *= np.all(np.greater(b1p2 - b2p1, 0), axis=1)
base_mat *= np.all(np.greater(b2p2 - b1p1, 0), axis=1)
# I area
intersect_area = np.prod(np.minimum(b2p2, b1p2) - np.maximum(b1p1, b2p1), axis=1)
# U area
union_area = np.prod(b1p2 - b1p1, axis=1) + np.prod(b2p2 - b2p1, axis=1) - intersect_area
# IoU
intersect_ratio = intersect_area / union_area
return base_mat * intersect_ratio