def compute_overlap(mat1, mat2):
s1 = mat1.shape[0]
s2 = mat2.shape[0]
area1 = (mat1[:, 2] - mat1[:, 0]) * (mat1[:, 3] - mat1[:, 1])
if mat2.shape[1] == 5:
area2 = mat2[:, 4]
else:
area2 = (mat2[:, 2] - mat2[:, 0]) * (mat2[:, 3] - mat2[:, 1])
x1 = cartesian([mat1[:, 0], mat2[:, 0]])
x1 = np.amax(x1, axis=1)
x2 = cartesian([mat1[:, 2], mat2[:, 2]])
x2 = np.amin(x2, axis=1)
com_zero = np.zeros(x2.shape[0])
w = x2 - x1
w = w - 1
w = np.maximum(com_zero, w)
y1 = cartesian([mat1[:, 1], mat2[:, 1]])
y1 = np.amax(y1, axis=1)
y2 = cartesian([mat1[:, 3], mat2[:, 3]])
y2 = np.amin(y2, axis=1)
h = y2 - y1
h = h - 1
h = np.maximum(com_zero, h)
oo = w * h
aa = cartesian([area1[:], area2[:]])
aa = np.sum(aa, axis=1)
ooo = oo / (aa - oo)
overlap = np.transpose(ooo.reshape(s1, s2), (1, 0))
return overlap
评论列表
文章目录