dotrack haved modified!
This commit is contained in:
Binary file not shown.
Binary file not shown.
@ -87,20 +87,29 @@ def draw_all_trajectories(vts, edgeline, save_dir, filename):
|
||||
# edgeline2 = edgeline1.copy()
|
||||
# edgeline = np.concatenate((edgeline1, edgeline2), exis = 1)
|
||||
|
||||
# =============================================================================
|
||||
# '''1. tracks 5点轨迹'''
|
||||
# trackpth = save_dir.parent /Path("trajectory")/ Path(f"{file}")
|
||||
# if not trackpth.exists():
|
||||
# trackpth.mkdir(parents=True, exist_ok=True)
|
||||
# for track in vts.tracks:
|
||||
# # if track.cls != 0:
|
||||
# img = edgeline.copy()
|
||||
# img = draw5points(track, img)
|
||||
#
|
||||
# pth = trackpth.joinpath(f"{track.tid}.png")
|
||||
# cv2.imwrite(str(pth), img)
|
||||
#
|
||||
# =============================================================================
|
||||
'''1. tracks 5点轨迹'''
|
||||
trackpth = save_dir.parent /Path("trajectory")/ Path(f"{file}")
|
||||
if not trackpth.exists():
|
||||
trackpth.mkdir(parents=True, exist_ok=True)
|
||||
for track in vts.tracks:
|
||||
# if track.cls != 0:
|
||||
img = edgeline.copy()
|
||||
img = draw5points(track, img)
|
||||
|
||||
pth = trackpth.joinpath(f"{track.tid}.png")
|
||||
cv2.imwrite(str(pth), img)
|
||||
|
||||
for track in vts.merged_tracks:
|
||||
# if track.cls != 0:
|
||||
img = edgeline.copy()
|
||||
img = draw5points(track, img)
|
||||
|
||||
pth = trackpth.joinpath(f"{track.tid}_.png")
|
||||
cv2.imwrite(str(pth), img)
|
||||
|
||||
|
||||
|
||||
|
||||
'''2. all tracks 中心轨迹'''
|
||||
img1, img2 = edgeline.copy(), edgeline.copy()
|
||||
|
||||
@ -139,7 +148,7 @@ def draw_all_trajectories(vts, edgeline, save_dir, filename):
|
||||
def drawFeatures(allvts, save_dir):
|
||||
# [trajlen_min, trajdist_max, trajlen_rate, trajist_rate]]
|
||||
|
||||
feats = [track.feature for vts in allvts for track in vts.tracks]
|
||||
feats = [track.TrajFeat for vts in allvts for track in vts.tracks]
|
||||
feats = np.array(feats)
|
||||
fig, ax = plt.subplots()
|
||||
ax.scatter(feats[:,3], feats[:, 1], s=10)
|
||||
@ -269,7 +278,7 @@ def draw5points(track, img):
|
||||
trajstd = 0
|
||||
|
||||
|
||||
trajlen_min, trajlen_max, trajdist_min, trajdist_max, trajlen_rate, trajdist_rate = track.feature
|
||||
trajlen_min, trajlen_max, trajdist_min, trajdist_max, trajlen_rate, trajdist_rate = track.TrajFeat
|
||||
|
||||
for i in range(boxes.shape[0]):
|
||||
cv2.circle(img, (int(cornpoints[i, 0]), int(cornpoints[i, 1])), 6, (255, 255, 255), 2)
|
||||
|
@ -31,12 +31,19 @@ def readDict(boxes, TracksDict):
|
||||
|
||||
|
||||
|
||||
def track_equal_track(atrack, btrack, TracksDict):
|
||||
def track_equal_track(atrack, btrack):
|
||||
# boxes: [x, y, w, h, track_id, score, cls, frame_index, box_index]
|
||||
# 0 1 2 3 4 5 6 7 8
|
||||
aboxes = atrack.boxes
|
||||
bboxes = btrack.boxes
|
||||
|
||||
afeat = atrack.features
|
||||
bfeat = btrack.features
|
||||
|
||||
# afeat = readDict(aboxes, TracksDict)
|
||||
# bfeat = readDict(bboxes, TracksDict)
|
||||
|
||||
|
||||
''' 1. 判断轨迹在时序上是否有交集 '''
|
||||
afids = aboxes[:, 7].astype(np.int_)
|
||||
bfids = bboxes[:, 7].astype(np.int_)
|
||||
@ -50,8 +57,6 @@ def track_equal_track(atrack, btrack, TracksDict):
|
||||
return False
|
||||
|
||||
''' 2. 轨迹特征相似度判断'''
|
||||
afeat = readDict(aboxes, TracksDict)
|
||||
bfeat = readDict(bboxes, TracksDict)
|
||||
feat = np.concatenate((afeat, bfeat), axis=0)
|
||||
|
||||
emb_simil = 1-np.maximum(0.0, cdist(feat, feat, 'cosine'))
|
||||
@ -82,9 +87,15 @@ def track_equal_track(atrack, btrack, TracksDict):
|
||||
idx_pair.append((a_idx, b_idx))
|
||||
|
||||
ious = []
|
||||
embs = []
|
||||
for a, b in idx_pair:
|
||||
abox, bbox = aboxes[a, :], bboxes[b, :]
|
||||
|
||||
af, bf = afeat[a, :], bfeat[b, :]
|
||||
|
||||
emb_ab = 1-cdist(af[None, :], bf[None, :], 'cosine')
|
||||
|
||||
|
||||
xa1, ya1 = abox[0] - abox[2]/2, abox[1] - abox[3]/2
|
||||
xa2, ya2 = abox[0] + abox[2]/2, abox[1] + abox[3]/2
|
||||
|
||||
@ -101,12 +112,15 @@ def track_equal_track(atrack, btrack, TracksDict):
|
||||
union = box1_area + box2_area - inter + 1e-6
|
||||
|
||||
ious.append(inter/union)
|
||||
embs.append(emb_ab[0, 0])
|
||||
|
||||
|
||||
cont = False if len(interfid) else True
|
||||
# cont2 = emb_[0, 0]>0.75
|
||||
# cont3 = all(iou>0.5 for iou in ious)
|
||||
cont = False if len(interfid) else True # fid 无交集
|
||||
cont1 = all(emb > 0.5 for emb in embs)
|
||||
cont2 = all(iou > 0.5 for iou in ious)
|
||||
# cont = cont and cont2 and cont3
|
||||
|
||||
cont = cont and cont1 and cont2
|
||||
|
||||
|
||||
return cont
|
||||
|
Reference in New Issue
Block a user