intersection = 박스끼리 교차 부위 있으면 출력
# 만들 식.
intersection_x = min(max_x1, max_x2) - max(min_x1, min_x2);
intersection_y = min(max_y1, max_y2) - max(min_y1, min_y2);
# prev는 이전 박스.
# out_zone에 겹쳐지는 이전 박스 서칭.
prev = []
if len(tracking_dict[model_idx]):
tracking_out_zone = torch.tensor(list(yaml_file[cafe_id]['tracking_out_zone'].values()))
t_x1, t_y1, t_x2, t_y2 = tracking_out_zone
prev = [torch.tensor([*t_boxes[-1], t_count, t_key]) for t_key, (t_boxes, t_count) in tracking_dict[model_idx].items()]
prev = torch.stack(prev, dim=0)
prev = prev[prev[:, 4] >= limit_frame]
x1 = prev[:, 0]
y1 = prev[:, 1]
x2 = prev[:, 2]
y2 = prev[:, 3]
intersection_x = (torch.min(torch.max(x1, x2), torch.max(t_x1, t_x2)) - torch.max(torch.min(x1, x2), torch.min(t_x1, t_x2))).reshape(-1, 1)
intersection_y = (torch.min(torch.max(y1, y2), torch.max(t_y1, t_y2)) - torch.max(torch.min(y1, y2), torch.min(t_y1, t_y2))).reshape(-1, 1)
intersection = torch.cat([intersection_x, intersection_y], dim=1)
intersection = torch.cat([intersection, prev[:, 4:]], dim=1)
intersection = intersection[intersection[:, 0] >= 0]
intersection = intersection[intersection[:, 1] >= 0]
Union은 각 박스의 넓이 - Intersection 계산 하면 됨.
Intersection / Union