# 如何对所有列组合的两个指标之间进行计算？

``````import numpy as np

class BboxUtils(object):
@staticmethod
def ious(bboxes1, bboxes2):
left1, top1, right1, bottom1 = BboxUtils.bbox_to_perimiters(bboxes1)
left2, top2, right2, bottom2 = BboxUtils.bbox_to_perimiters(bboxes2)

area1 = (right1 - left1) * (top1 - bottom1)
area2 = (right2 - left2) * (top2 - bottom2)

intersection_left = np.maximum(left1, left2)
intersection_right = np.minimum(right1, right2)
intersection_top = np.maximum(top1, top2)
intersection_bottom = np.minimum(bottom1, bottom2)
intersection_area = (intersection_right - intersection_left) * (intersection_top - intersection_bottom)
intersection_area[intersection_area < 0] = 0

iou = intersection_area / (area1 + area2 - intersection_area)

return iou

@staticmethod
def bbox_to_perimiters(bboxes):
left, w, top, h = np.split(bboxes.reshape(-1), 4)
right = left + w
bottom = top + h
return left, right, top, bottom

# example usage:
detections1 = my_detector.detect(frame1) #np.array of shape (n1, 4)
detections2 = my_detector.detect(frame2) #np.array of shape (n2, 4)
ious = BboxUtils.ious(detections1, detections2)
``````

1. The detections on the 2 frames (`bboxes1` and `bboxes2`) are of the same length
2. Each detection's index is the same in `bboxes1` and `bboxes2`

Notice `bboxes1` and `bboxes2` can be matrices of shape `(n1, 4)` and `(n2, 4)`, where `n1` is not necessarily equal `n2`.