modify byte.trackerupdate, add list first_finded
This commit is contained in:
BIN
__pycache__/export.cpython-39.pyc
Normal file
BIN
__pycache__/export.cpython-39.pyc
Normal file
Binary file not shown.
@ -206,7 +206,12 @@ def run(
|
||||
handpose = hand_pose()
|
||||
handlocals_dict = {}
|
||||
|
||||
boxes_and_imgs = []
|
||||
boxes_and_imgs = []
|
||||
|
||||
BoxesFeats = []
|
||||
|
||||
|
||||
|
||||
track_boxes = np.empty((0, 9), dtype = np.float32)
|
||||
det_boxes = np.empty((0, 9), dtype = np.float32)
|
||||
|
||||
@ -263,28 +268,41 @@ def run(
|
||||
det = det.cpu().numpy()
|
||||
det = np.concatenate([det[:, :4], np.arange(nd).reshape(-1, 1), det[:, 4:]], axis=-1)
|
||||
|
||||
'''FeatFlag为相对于上一帧boxes,当前boxes是否为静止的标志。'''
|
||||
# def static_estimate(box1, box2, TH1=8, TH2=12):
|
||||
# dij_abs = max(np.abs(box1 - box2))
|
||||
# dij_euc = max([np.linalg.norm((box1[:2] - box2[:2])),
|
||||
# np.linalg.norm((box1[2:4] - box2[2:4]))
|
||||
# ])
|
||||
# if dij_abs < TH1 and dij_euc < TH2:
|
||||
# return True
|
||||
# else:
|
||||
# return False
|
||||
# FeatFlag = [-1] * nd
|
||||
# if len(boxes_and_imgs):
|
||||
# detj = boxes_and_imgs[-1][0]
|
||||
# frmj = boxes_and_imgs[-1][-1]
|
||||
# for ii in range(nd):
|
||||
# ## flag 中保存的是box索引
|
||||
# condt1 = frame-frmj==1
|
||||
# flag = [idx for jj, idx in enumerate(detj[:, 4]) if condt1 and static_estimate(det[ii, :4], detj[jj, :4])]
|
||||
# if len(flag) == 1:
|
||||
# FeatFlag[ii] = flag[0]
|
||||
# boxes_and_imgs.append((det, im0, frame))
|
||||
#
|
||||
def static_estimate(box1, box2, TH1=8, TH2=12):
|
||||
dij_abs = max(np.abs(box1 - box2))
|
||||
dij_euc = max([np.linalg.norm((box1[:2] - box2[:2])),
|
||||
np.linalg.norm((box1[2:4] - box2[2:4]))
|
||||
])
|
||||
if dij_abs < TH1 and dij_euc < TH2:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
nw = 3 # 向前递推检查的窗口大小
|
||||
nf = len(BoxesFeats) # 已经检测+特征提取的帧数
|
||||
feat_curr = [None] * nd # nd: 当前帧检测出的boxes数
|
||||
for ii in range(nd):
|
||||
box = det[ii, :4]
|
||||
|
||||
kk=1
|
||||
feat = None
|
||||
while kk <= nw and nf>=kk:
|
||||
ki = -1 * kk
|
||||
boxes_ = BoxesFeats[ki][0]
|
||||
feats_ = BoxesFeats[ki][1]
|
||||
|
||||
flag = [jj for jj in range(len(boxes_)) if static_estimate(box, boxes_[jj, :4])]
|
||||
if len(flag) == 1:
|
||||
feat = feats_[flag[0]]
|
||||
break
|
||||
kk += 1
|
||||
if feat is not None:
|
||||
feat_curr[ii] = feat
|
||||
|
||||
|
||||
|
||||
|
||||
## ================================================================ writed by WQG
|
||||
|
||||
'''tracks: [x1, y1, x2, y2, track_id, score, cls, frame_index, box_index]
|
||||
@ -301,6 +319,9 @@ def run(
|
||||
'''================== 1. 存储 dets/subimgs/features Dict ============='''
|
||||
imgs, features = inference_image(im0, tracks)
|
||||
|
||||
BoxesFeats.append((tracks, features))
|
||||
|
||||
|
||||
imgdict = {}
|
||||
boxdict = {}
|
||||
featdict = {}
|
||||
@ -504,17 +525,20 @@ def main_loop(opt):
|
||||
if os.path.isdir(p):
|
||||
files = find_files_in_nested_dirs(p)
|
||||
|
||||
# files = [#r"D:\datasets\ym\videos\标记视频\test_20240402-173935_6920152400975_back_174037372.mp4",
|
||||
# r"D:\datasets\ym\videos\标记视频\test_20240402-173935_6920152400975_front_174037379.mp4"]
|
||||
# files = [r"D:\datasets\ym\广告板遮挡测试\8\6926636301004_20240508-175300_back_addGood_70f754088050_215_17327712807.mp4",
|
||||
# r"D:\datasets\ym\videos\标记视频\test_20240402-173935_6920152400975_back_174037372.mp4",
|
||||
# r"D:\datasets\ym\videos\标记视频\test_20240402-173935_6920152400975_front_174037379.mp4",
|
||||
# r"D:\datasets\ym\广告板遮挡测试\8\2500441577966_20240508-175946_front_addGood_70f75407b7ae_155_17788571404.mp4"
|
||||
# ]
|
||||
|
||||
# files = [r"D:\datasets\ym\广告板遮挡测试\8\2500441577966_20240508-175946_front_addGood_70f75407b7ae_155_17788571404.mp4"]
|
||||
files = [r"D:\datasets\ym\videos\标记视频\test_20240402-173935_6920152400975_back_174037372.mp4"]
|
||||
for file in files:
|
||||
optdict["source"] = file
|
||||
run(**optdict)
|
||||
|
||||
k += 1
|
||||
if k == 3:
|
||||
break
|
||||
# k += 1
|
||||
# if k == 3:
|
||||
# break
|
||||
elif os.path.isfile(p):
|
||||
optdict["source"] = p
|
||||
run(**vars(opt))
|
||||
|
BIN
tracking/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
tracking/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -216,7 +216,7 @@ class Track:
|
||||
trajdist_min, trajdist_max,
|
||||
trajlen_rate, trajdist_rate]
|
||||
|
||||
def compute_static_fids(self, det_y, STATIC_THRESH = 8):
|
||||
def pt_state_fids(self, det_y, STATIC_THRESH = 8):
|
||||
'''
|
||||
前摄时,y一般选择为 box 的 y1 坐标,且需限定商品在购物车内。
|
||||
inputs:
|
||||
@ -324,12 +324,15 @@ class doTracks:
|
||||
for t_id in self.trackID:
|
||||
# print(f"The ID is: {t_id}")
|
||||
idx = np.where(track_ids == t_id)[0]
|
||||
box = self.bboxes[idx, :]
|
||||
box = self.bboxes[idx, :]
|
||||
|
||||
assert len(set(box[:, 7])) == len(box), "Please check!!!"
|
||||
|
||||
lboxes.append(box)
|
||||
|
||||
return lboxes
|
||||
|
||||
'''
|
||||
def classify(self):
|
||||
|
||||
tracks = self.tracks
|
||||
@ -354,10 +357,11 @@ class doTracks:
|
||||
self.Static.extend(static_tracks)
|
||||
|
||||
|
||||
'''剔除静止目标后的 tracks'''
|
||||
# 剔除静止目标后的 tracks
|
||||
tracks = self.sub_tracks(tracks, static_tracks)
|
||||
|
||||
return tracks
|
||||
'''
|
||||
|
||||
|
||||
|
||||
|
@ -51,41 +51,29 @@ class doBackTracks(doTracks):
|
||||
# return lboxes
|
||||
# =============================================================================
|
||||
|
||||
|
||||
|
||||
def classify(self):
|
||||
'''
|
||||
功能:对 tracks 中元素分类
|
||||
|
||||
'''
|
||||
tracks = super().classify()
|
||||
|
||||
# tracks = self.tracks
|
||||
# shopcart = self.shopcart
|
||||
'''功能:对 tracks 中元素分类 '''
|
||||
|
||||
# # 提取手的frame_id,并和动目标的frame_id 进行关联
|
||||
# hand_tracks = [t for t in tracks if t.cls==0]
|
||||
# self.Hands.extend(hand_tracks)
|
||||
# tracks = self.sub_tracks(tracks, hand_tracks)
|
||||
tracks = self.tracks
|
||||
# 提取手的frame_id,并和动目标的frame_id 进行关联
|
||||
hand_tracks = [t for t in tracks if t.cls==0]
|
||||
self.Hands.extend(hand_tracks)
|
||||
|
||||
|
||||
|
||||
# # 提取小孩的track,并计算状态:left, right, incart
|
||||
# kid_tracks = [t for t in tracks if t.cls==9]
|
||||
# kid_states = [self.kid_state(t) for t in kid_tracks]
|
||||
# self.Kids = [x for x in zip(kid_tracks, kid_states)]
|
||||
|
||||
# tracks = self.sub_tracks(tracks, kid_tracks)
|
||||
tracks = self.sub_tracks(tracks, hand_tracks)
|
||||
|
||||
# 提取小孩的track,并计算状态:left, right, incart
|
||||
kid_tracks = [t for t in tracks if t.cls==9]
|
||||
kid_states = [self.kid_state(t) for t in kid_tracks]
|
||||
self.Kids = [x for x in zip(kid_tracks, kid_states)]
|
||||
|
||||
tracks = self.sub_tracks(tracks, kid_tracks)
|
||||
|
||||
# static_tracks = [t for t in tracks if t.frnum>1 and t.is_static()]
|
||||
# self.Static.extend(static_tracks)
|
||||
|
||||
|
||||
# '''剔除静止目标后的 tracks'''
|
||||
# tracks = self.sub_tracks(tracks, static_tracks)
|
||||
|
||||
static_tracks = [t for t in tracks if t.frnum>1 and t.is_static()]
|
||||
self.Static.extend(static_tracks)
|
||||
|
||||
'''剔除静止目标后的 tracks'''
|
||||
tracks = self.sub_tracks(tracks, static_tracks)
|
||||
|
||||
|
||||
'''购物框边界外具有运动状态的干扰目标'''
|
||||
out_trcak = [t for t in tracks if t.is_OutTrack()]
|
||||
|
@ -31,7 +31,7 @@ class backTrack(Track):
|
||||
'''运动点帧索引(运动帧两端的静止帧索引)'''
|
||||
self.moving_index = self.compute_dynamic_fids()
|
||||
|
||||
self.static_dynamic_fids = self.compute_static_dynamic_fids()
|
||||
# self.static_index, self.moving_index = self.compute_static_dynamic_fids()
|
||||
|
||||
'''该函数依赖项: self.cornpoints,定义 4 个商品位置变量:
|
||||
self.Cent_isIncart, self.LB_isIncart, self.RB_isIncart
|
||||
@ -250,13 +250,35 @@ class backTrack(Track):
|
||||
return moving_index
|
||||
|
||||
def compute_static_dynamic_fids(self):
|
||||
static_dynamic_fids = []
|
||||
for traj in self.trajectory:
|
||||
static, dynamic = self.compute_static_fids(traj)
|
||||
|
||||
idx2 = self.trajlens.index(min(self.trajlens))
|
||||
trajmin = self.trajectory[idx2]
|
||||
|
||||
static, dynamic = self.pt_state_fids(trajmin)
|
||||
|
||||
static = np.array(static)
|
||||
dynamic = np.array(dynamic)
|
||||
|
||||
if static.size:
|
||||
indx = np.argsort(static[:, 0])
|
||||
static = static[indx]
|
||||
if dynamic.size:
|
||||
indx = np.argsort(dynamic[:, 0])
|
||||
dynamic = dynamic[indx]
|
||||
|
||||
static_dynamic_fids.append((static, dynamic))
|
||||
|
||||
return static_dynamic_fids
|
||||
return static, dynamic
|
||||
|
||||
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# static_dynamic_fids = []
|
||||
# for traj in self.trajectory:
|
||||
# static, dynamic = self.pt_state_fids(traj)
|
||||
# static_dynamic_fids.append((static, dynamic))
|
||||
#
|
||||
# return static_dynamic_fids
|
||||
# =============================================================================
|
||||
|
||||
|
||||
|
||||
@ -270,6 +292,10 @@ class backTrack(Track):
|
||||
trajlen_rate, trajdist_rate]
|
||||
'''
|
||||
|
||||
# print(f"TrackID: {self.tid}")
|
||||
boxes = self.boxes
|
||||
|
||||
|
||||
condt1 = self.feature[5] < 0.2 or self.feature[3] < 120
|
||||
|
||||
'''静态情况 2: 目标初始状态为静止,适当放宽关键点最小相对运动轨迹 < 0.5'''
|
||||
|
@ -31,8 +31,8 @@ class frontTrack(Track):
|
||||
'''y1、y2静止状态区间,值是 boxes 中对 axis=0 的索引,不是帧索引'''
|
||||
det_y1 = np.diff(boxes[:, 1], axis=0)
|
||||
det_y2 = np.diff(boxes[:, 3], axis=0)
|
||||
self.static_y1, self.dynamic_y1 = self.compute_static_fids(det_y1)
|
||||
self.static_y2, self.dynamic_y2 = self.compute_static_fids(det_y2)
|
||||
self.static_y1, self.dynamic_y1 = self.pt_state_fids(det_y1)
|
||||
self.static_y2, self.dynamic_y2 = self.pt_state_fids(det_y2)
|
||||
|
||||
self.isCornpoint = self.is_left_or_right_cornpoint()
|
||||
self.isBotmpoint = self.is_bottom_cornpoint()
|
||||
|
@ -90,7 +90,7 @@ def have_tracked():
|
||||
k = 0
|
||||
gt = Profile()
|
||||
for filename in os.listdir(trackdict):
|
||||
filename = 'test_20240402-173935_6920152400975_front_174037379.pkl'
|
||||
filename = 'test_20240402-173935_6920152400975_back_174037372.pkl'
|
||||
file, ext = os.path.splitext(filename)
|
||||
filepath = os.path.join(trackdict, filename)
|
||||
TracksDict = np.load(filepath, allow_pickle=True)
|
||||
@ -121,9 +121,9 @@ def have_tracked():
|
||||
|
||||
|
||||
|
||||
# k += 1
|
||||
# if k==1:
|
||||
# break
|
||||
k += 1
|
||||
if k==1:
|
||||
break
|
||||
|
||||
if len(alltracks):
|
||||
drawFeatures(alltracks, save_dir)
|
||||
|
Binary file not shown.
@ -214,6 +214,8 @@ class BYTETracker:
|
||||
refind_stracks = []
|
||||
lost_stracks = []
|
||||
removed_stracks = []
|
||||
|
||||
first_finded = []
|
||||
|
||||
scores = results.conf
|
||||
cls = results.cls
|
||||
@ -328,6 +330,9 @@ class BYTETracker:
|
||||
continue
|
||||
track.activate(self.kalman_filter, self.frame_id)
|
||||
activated_stracks.append(track)
|
||||
|
||||
first_finded.append(track)
|
||||
|
||||
# Step 5: Update state
|
||||
for track in self.lost_stracks:
|
||||
if self.frame_id - track.end_frame > self.max_time_lost:
|
||||
@ -359,7 +364,7 @@ class BYTETracker:
|
||||
for x in self.tracked_stracks if x.is_activated]
|
||||
|
||||
output2 = [x.tlwh_to_tlbr(x._tlwh).tolist() + [x.track_id, x.score, x.cls, x.frame_id, x.idx]
|
||||
for x in activated_stracks if x.first_find]
|
||||
for x in first_finded if x.first_find]
|
||||
|
||||
output = np.asarray(output1+output2, dtype=np.float32)
|
||||
|
||||
|
Binary file not shown.
@ -11,6 +11,7 @@ import matplotlib.pyplot as plt
|
||||
from sklearn.decomposition import PCA
|
||||
from utils.annotator import TrackAnnotator
|
||||
from utils.plotting import colors
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def plot_frameID_y2(vts):
|
||||
@ -88,14 +89,18 @@ def draw_all_trajectories(vts, edgeline, save_dir, filename):
|
||||
|
||||
# =============================================================================
|
||||
# '''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 = save_dir.joinpath(f"{file}_{track.tid}.png")
|
||||
# cv2.imwrite(pth, img)
|
||||
# # 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()
|
||||
|
||||
|
Reference in New Issue
Block a user