def get_iou(dets_corners, track_corners, flag): if flag == 1: dets_standup = box_np_ops.corner_to_standup_nd(dets_corners) track_standup = box_np_ops.corner_to_standup_nd(track_corners) else: dets_standup = box_np_ops.corner_to_standup_nd(dets_corners) track_standup = dets_standup standup_iou = box_np_ops.iou_jit(dets_standup, track_standup, eps=0.0) standup_iou_new = standup_iou if flag != 1: for i in range(standup_iou.shape[0]): standup_iou[i][i] = 0 re_cal = np.where(standup_iou > 0) no_care = [] if re_cal[0].shape[0] == 0: return standup_iou, standup_iou_new for i in range(re_cal[0].shape[0]): if re_cal[0][i] == re_cal[1][i]: continue if re_cal[0][i] in no_care: continue # # #####***** 调用模块进行IOU计算 *****##### # IOU = intersection(dets_corners[re_cal[0][i]].tolist(), trackers_corners[re_cal[1][i]].tolist()) # #####***** 调用自定义函数进行IOU计算耗时稍微小一些 *****##### interpoly = [] b = cal_iou.PolygonClip(dets_corners[re_cal[0][i]].tolist(), track_corners[re_cal[1][i]].tolist(), interpoly) if b: list2 = [] for num_i in range(len(interpoly)): list2.append(interpoly[num_i]) for num_i in range(len(list2) - 1): for num_j in range(num_i + 1, len(list2)): if operator.eq(list2[num_i], list2[num_j]): interpoly.pop(num_j) area = cal_iou.CalArea(interpoly) area1 = cal_iou.CalArea(dets_corners[re_cal[0][i]].tolist()) area2 = cal_iou.CalArea(track_corners[re_cal[1][i]].tolist()) IOU = area / (area2 + area1 - area) IOU_new = area / area1 else: IOU = 0 IOU_new = 0 no_care.append(re_cal[1][i]) if flag: standup_iou[re_cal[0][i]][re_cal[1][i]] = IOU standup_iou_new[re_cal[0][i]][re_cal[1][i]] = IOU_new else: standup_iou[re_cal[0][i]][re_cal[1][i]] = IOU standup_iou[re_cal[1][i]][re_cal[0][i]] = IOU standup_iou_new[re_cal[0][i]][re_cal[1][i]] = IOU_new standup_iou_new[re_cal[1][i]][re_cal[0][i]] = IOU_new return standup_iou, standup_iou_new
def fusion_box(dets_corners, track_corners, flag): if flag == 1: dets_standup = box_np_ops.corner_to_standup_nd(dets_corners) track_standup = box_np_ops.corner_to_standup_nd(track_corners) else: dets_standup = box_np_ops.corner_to_standup_nd(dets_corners) track_standup = dets_standup standup_iou = box_np_ops.iou_jit(dets_standup, track_standup, eps=0.0) if flag != 1: for i in range(standup_iou.shape[0]): standup_iou[i][i] = 0 re_cal = np.where(standup_iou > 0) no_care = [] if re_cal[0].shape[0] == 0: return np.empty((0, 2), dtype=int), np.arange(len(dets_corners)), np.empty( (0, 5), dtype=int), 0 for i in range(re_cal[0].shape[0]): if re_cal[0][i] == re_cal[1][i]: continue if re_cal[0][i] in no_care: continue # # #####***** 调用模块进行IOU计算 *****##### # IOU = intersection(dets_corners[re_cal[0][i]].tolist(), trackers_corners[re_cal[1][i]].tolist()) # #####***** 调用自定义函数进行IOU计算耗时稍微小一些 *****##### interpoly = [] b = cal_iou.PolygonClip(dets_corners[re_cal[0][i]].tolist(), track_corners[re_cal[1][i]].tolist(), interpoly) if b: list2 = [] for num_i in range(len(interpoly)): list2.append(interpoly[num_i]) for num_i in range(len(list2) - 1): for num_j in range(num_i + 1, len(list2)): if operator.eq(list2[num_i], list2[num_j]): interpoly.pop(num_j) area = cal_iou.CalArea(interpoly) area1 = cal_iou.CalArea(dets_corners[re_cal[0][i]].tolist()) area2 = cal_iou.CalArea(track_corners[re_cal[1][i]].tolist()) IOU = area / (area2 + area1 - area) else: IOU = 0 no_care.append(re_cal[1][i]) if flag: standup_iou[re_cal[0][i]][re_cal[1][i]] = IOU else: standup_iou[re_cal[0][i]][re_cal[1][i]] = IOU standup_iou[re_cal[1][i]][re_cal[0][i]] = IOU iou_threshold = 0.000001 matched_indices = linear_assignment(-standup_iou) unmatched_detections = [] for d, det in enumerate(dets_corners): if (d not in matched_indices[:, 0]): unmatched_detections.append(d) unmatched_trackers = [] for t, trk in enumerate(track_corners): if (t not in matched_indices[:, 1]): unmatched_trackers.append(t) matches = [] for m in matched_indices: if standup_iou[m[0], m[1]] < iou_threshold: unmatched_detections.append(m[0]) unmatched_trackers.append(m[1]) else: matches.append(m.reshape(1, 2)) if (len(matches) == 0): matches = np.empty((0, 2), dtype=int) else: matches = np.concatenate(matches, axis=0) return matches, np.array(unmatched_detections), np.array( unmatched_trackers), standup_iou