modify byte.trackerupdate, add list first_finded

This commit is contained in:
王庆刚
2024-05-25 18:35:53 +08:00
parent d6f3693d3f
commit dff029de20
17 changed files with 132 additions and 80 deletions

View File

@ -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))