def rotate_nms_cc(dets, trackers): trackers_corners = box_np_ops.center_to_corner_box2d( trackers[:, :2], trackers[:, 2:4], trackers[:, 4]) trackers_standup = box_np_ops.corner_to_standup_nd(trackers_corners) dets_corners = box_np_ops.center_to_corner_box2d(dets[:, :2], dets[:, 2:4], dets[:, 4]) dets_standup = box_np_ops.corner_to_standup_nd(dets_corners) standup_iou = box_np_ops.iou_jit(dets_standup, trackers_standup, eps=0.0) return standup_iou
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 rotate_nms_cc(dets, thresh): scores = dets[:, 5] order = scores.argsort()[::-1].astype(np.int32) # highest->lowest dets_corners = box_np_ops.center_to_corner_box2d(dets[:, :2], dets[:, 2:4], dets[:, 4]) dets_standup = box_np_ops.corner_to_standup_nd(dets_corners) standup_iou = box_np_ops.iou_jit(dets_standup, dets_standup, eps=0.0) # print(dets_corners.shape, order.shape, standup_iou.shape) return rotate_non_max_suppression_cpu(dets_corners, order, standup_iou, thresh)
def _compare(self, boxes1, boxes2): """Compute matrix of (negated) sq distances. Args: boxlist1: BoxList holding N boxes. boxlist2: BoxList holding M boxes. Returns: A tensor with shape [N, M] representing negated pairwise squared distance. """ boxes1_bv = box_np_ops.rbbox2d_to_near_bbox(boxes1) boxes2_bv = box_np_ops.rbbox2d_to_near_bbox(boxes2) ret = box_np_ops.iou_jit(boxes1_bv, boxes2_bv, eps=0.0) return ret
def rotate_nms_cc(dets, trackers, usespeed=0): '''数据形式:x,y,l,w,vx,vy,theta''' trackers_corners = box_np_ops.center_to_corner_box2d( trackers[:, :2], trackers[:, 2:4], trackers[:, 6]) trackers_standup = box_np_ops.corner_to_standup_nd(trackers_corners) dets_corners = box_np_ops.center_to_corner_box2d(dets[:, :2], dets[:, 2:4], dets[:, 6]) dets_standup = box_np_ops.corner_to_standup_nd(dets_corners) standup_iou = box_np_ops.iou_jit(dets_standup, trackers_standup, eps=0.0) #位置iou # print('standup_iou',standup_iou) # 速度的iou if usespeed == 1: trackers_boxlist = IOU_Calculation.point_to_box( trackers[:, 4:6], 0.4, 0.2) #vx,vy,vx_width,vy_width dets_boxlist = IOU_Calculation.point_to_box(dets[:, 4:6], 0.4, 0.2) speed_iou = IOU_Calculation.iou_matrix(dets_boxlist, trackers_boxlist) # print('speed_iou', speed_iou) IOU_matrix = standup_iou * 0.8 + speed_iou * 0.2 #分配权重 return IOU_matrix else: return standup_iou
def rotate_nms_merge(dets, thresh): ''' input dets_corners, order, standup_iou,thresh return bbox_list ( not inds, cause we merges the bboxes, new boxes is not in the original boxlist) we can use score or centerness as weight to get better merge method parameter for merge nms iou_thresh : > thresh hold , then we add those bboxes to same list, and merge them intersect_bbox_nums_thresh : numbers of intersection bboxes > threshold , including itself, if the number is too small, we can ignore the bboxes TODO: score weight : with or without centerness.sigmoid ''' scores = dets[:, 5] order = scores.argsort()[::-1].astype(np.int32) # highest->lowest dets_corners = box_np_ops.center_to_corner_box2d(dets[:, :2], dets[:, 2:4], dets[:, 4]) dets_standup = box_np_ops.corner_to_standup_nd(dets_corners) standup_iou = box_np_ops.iou_jit(dets_standup, dets_standup, eps=0.0) unmerged_boxlist = [] while order.size > 0: i = order[0] merged_boxes_ind = np.where(standup_iou[i] > thresh) unmerged_boxlist.append(merged_boxes_ind[0]) # filter out the merge inds in the order for ele in merged_boxes_ind[0]: if ele in order: remove_inds = np.where(order == ele)[0] order = np.delete(order, remove_inds[0]) return unmerged_boxlist #depreciate : moving anchor to absord the bbox merged_boxes_num = 0 rounds = 0 thresh = 0.1 intersect_bbox_nums_thresh = 1 start = 0 while order.size > 0: print('we have {} bboxes in round {}'.format(order.size, rounds)) i = order[0] merged_boxes_ind = np.where(standup_iou[i] >= thresh) # we can set a thresh hold for intersetction number, if intersetion bbox num too small, we give up the bbox if merged_boxes_ind[0].size > intersect_bbox_nums_thresh: print('round {} have intersection{} nums'.format( rounds, merged_boxes_ind[0].size)) if not merged_boxes_num in unmerged_boxlist: unmerged_boxlist[merged_boxes_num] = merged_boxes_ind unmerged_boxes_inds = np.where(standup_iou[i] < thresh) else: unmerged_boxlist[merged_boxes_num] = np.concatenate( (unmerged_boxlist[merged_boxes_num], merged_boxes_ind[1:]), axis=0) unmerged_boxes_inds = np.where(standup_iou[i] < thresh) else: order = order[unmerged_boxes_inds + 1] #rounds+=1 final_bboxes_list = [] total_box_check = 0 for key, bboxes in unmerged_boxlist.items(): final_bboxes_list.append(bboxes.mean(axis=0)) total_box_check += unmerged_boxlist[key].shape[0] embed() return final_bboxes_list
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