def getnotassociatedindex(len_sub, len_tr, del_tr, del_sub): non_tr = [] non_sub = [] non_sub = np.array(range(len_sub)) non_tr = np.array(range(len_tr)) non_sub = np.delete(non_sub, del_sub) non_tr = np.delete(non_tr, del_tr) non_sub = non_sub.tolist() non_tr = non_tr.tolist() return non_sub, non_tr
def trackmerge(tr, new_tr_copy, non_tr, loss, threshold, res): threshold_ = threshold + (2 * threshold / 3) # margin new_tr = new_tr_copy for ii in range(len(non_tr)): a = loss[non_tr[ii], :] b = a[a < threshold_] if len(b) > 0: if len(b) > 1: b = [b.min()] # Get merging track overlapped subject's index idx_b = np.argwhere(a == b) # Get parent track's index idx_new_tr = np.argwhere(res[:, 1] == idx_b[0, 0]) # Merge tracks try: # Maybe wrong hungarian as we expected # Only associate locked tracks if tr[ii].state is 2 and new_tr[idx_new_tr[0, 0]].state is 2: new_tr[idx_new_tr[0, 0]].associatetrack(tr[ii]) tr = np.delete(tr, ii) tr = tr.tolist() except: pass return new_tr, tr
def hungarianassociation(loss, threshold): print loss # SKLEARN association method res = _hungarian(loss) del_index = [] for ii in range(len(res)): y, x = res[ii] """ if(loss[y, x] > threshold): del_index.append(ii) """ new_res = np.delete(res, del_index, 0) return new_res
def hungarianassociation(loss, distance, threshold): loss = postproc(loss, threshold) debug_flag = 0 if debug_flag: print loss # SKLEARN association method res = _hungarian(loss) del_index = [] for ii in range(len(res)): y, x = res[ii] if(loss [y, x] > threshold): del_index.append(ii) new_res = np.delete(res, del_index, 0) #print new_res return new_res
def hungarianassociation(loss, distance, threshold): loss = postproc(loss, threshold) debug_flag = 0 if debug_flag: print loss # SKLEARN association method res = _hungarian(loss) del_index = [] for ii in range(len(res)): y, x = res[ii] if (loss[y, x] > threshold): del_index.append(ii) new_res = np.delete(res, del_index, 0) #print new_res return new_res
def tracksplit(new_tr, sub, threshold): # usage of appareance model might be a good option # for distance calculation in this section threshold_ = threshold + (2 * threshold / 3) # margin del_idx = [] for ii in range(len(sub)): for tr in new_tr: if tr.group and tr.calculatesubjectdistance(sub[ii], threshold_): n_tr = tr.deassociatetrack() n_tr.updatetrack(sub[ii]) new_tr.append(n_tr) del_idx.append(ii) break if del_idx: sub = np.delete(sub, del_idx) sub = sub.tolist() return new_tr, sub
def tracksplit(new_tr, sub, threshold): # usage of appareance model might be a good option # for distance calculation in this section threshold_ = threshold + (2 * threshold / 3) # margin del_idx = [] for ii in range(len(sub)): for tr in new_tr: if tr.group and tr.calculatesubjectdistance(sub[ii], threshold_): n_tr = tr.deassociatetrack() score = lossfunction(tr, sub[ii]) n_tr.updatetrack(sub[ii], score[0]) new_tr.append(n_tr) del_idx.append(ii) break if del_idx: sub = np.delete(sub, del_idx) sub = sub.tolist() return new_tr, sub
def trackupdate(tr, sub, res, loss, threshold): new_track = [] del_index_sub = [] del_index_tr = [] init_tr = tr init_sub = sub threshold_distance = 100 aux_res = res # Update successful associations for ii in range(len(res)): y, x = res[ii] aux_res = np.delete(aux_res, 0, axis=0) new_tr = assignsubjecttoexistingtrack(tr[y], sub[x]) new_track.append(new_tr) del_index_sub.append(x) del_index_tr.append(y) sub = np.delete(sub, del_index_sub) tr = np.delete(tr, del_index_tr) sub = sub.tolist() tr = tr.tolist() # Update missed associations --> where merge should act non_index_sub, non_index_tr = getnotassociatedindex( len(init_sub), len(init_tr), del_index_tr, del_index_sub) new_track, tr = trackmerge( tr, new_track, non_index_tr, loss, threshold_distance, res) del_index = [] for ii in range(len(tr)): tr[ii].updatetrack() # In case track got lost if tr[ii].state == 4: del_index.append(ii) if del_index: tr = np.delete(tr, del_index) tr = tr.tolist() for n in new_track: tr.append(n) # Update new subjects --> where split should act tr, sub = tracksplit(new_track, sub, threshold_distance) """ TODO ---- - Only assign new tracks in outer positions of the image """ for s in sub: t = assignsubjecttonewtrack(s) tr.append(t) return tr
def trackupdate(tr, sub, res, loss, threshold): new_track = [] del_index_sub = [] del_index_tr = [] init_tr = tr init_sub = sub threshold_distance = 100 aux_res = res # Update successful associations for ii in range(len(res)): y, x = res[ii] aux_res = np.delete(aux_res, 0, axis=0) new_tr = assignsubjecttoexistingtrack(tr[y], sub[x]) new_track.append(new_tr) del_index_sub.append(x) del_index_tr.append(y) sub = np.delete(sub, del_index_sub) tr = np.delete(tr, del_index_tr) sub = sub.tolist() tr = tr.tolist() # Update missed associations --> where merge should act non_index_sub, non_index_tr = getnotassociatedindex( len(init_sub), len(init_tr), del_index_tr, del_index_sub) new_track, tr = trackmerge(tr, new_track, non_index_tr, loss, threshold_distance, res) del_index = [] for ii in range(len(tr)): tr[ii].updatetrack() # In case track got lost if tr[ii].state == 4: del_index.append(ii) if del_index: tr = np.delete(tr, del_index) tr = tr.tolist() for n in new_track: tr.append(n) # Update new subjects --> where split should act tr, sub = tracksplit(new_track, sub, threshold_distance) """ TODO ---- - Only assign new tracks in outer positions of the image """ for s in sub: t = assignsubjecttonewtrack(s) tr.append(t) return tr