如图所示的空间内的两个obb,如何求它们的交并比?
采用以下方法求解,发现结果并不对(可能以下方法求oobb是对的):
def naive_iou(box1,box2):
'''
3D IoU计算
box表示形式:[x1,y1,z1,x2,y2,z2] 分别是两对角点的坐标
'''
in_w = min(box1[3],box2[3]) - max(box1[0],box2[0])
in_l = min(box1[4],box2[4]) - max(box1[1],box2[1])
in_h = min(box1[5],box2[5]) - max(box1[2],box2[2])
inter = 0 if in_w < 0 or in_l < 0 or in_h < 0 else in_w * in_l * in_h
union = (box1[3] - box1[0]) * (box1[4] - box1[1]) * (box1[5] - box1[2]) + (box2[3] - box2[0]) * (box2[4] - box2[1]) * (box2[5] - box2[2]) - inter
iou = inter / union
return iou
两个三维矩形包围框求交集和并集,难度不是一般的大。