pipeline.py 等更新
This commit is contained in:
59
pipeline.py
59
pipeline.py
@ -103,14 +103,16 @@ def pipeline(
|
||||
|
||||
# if pf_path.exists():
|
||||
# return
|
||||
|
||||
|
||||
|
||||
'''====================== 构造 ShoppingDict 模块 ======================='''
|
||||
ShoppingDict = {"eventPath": eventpath,
|
||||
"eventName": evtname,
|
||||
"barcode": barcode,
|
||||
"eventType": '', # "input", "output", "other"
|
||||
"frontCamera": {},
|
||||
"backCamera": {},
|
||||
"one2n": []
|
||||
"one2n": [] #
|
||||
}
|
||||
|
||||
|
||||
@ -121,7 +123,7 @@ def pipeline(
|
||||
|
||||
|
||||
for vpath in vpaths:
|
||||
'''相机事件字典构造'''
|
||||
'''================= 1. 构造相机事件字典 ================='''
|
||||
CameraEvent = {"cameraType": '', # "front", "back"
|
||||
"videoPath": '',
|
||||
"imagePaths": [],
|
||||
@ -140,21 +142,21 @@ def pipeline(
|
||||
if bname.split('_')[0] == "1" or bname.find('front')>=0:
|
||||
CameraEvent["cameraType"] = "front"
|
||||
|
||||
'''事件结果存储文件夹'''
|
||||
|
||||
'''================= 2. 事件结果存储文件夹 ================='''
|
||||
if isinstance(vpath, list):
|
||||
savepath_pipeline_imgs = savepath_pipeline / Path("images")
|
||||
else:
|
||||
savepath_pipeline_imgs = savepath_pipeline / Path(str(Path(vpath).stem))
|
||||
|
||||
if not savepath_pipeline_imgs.exists():
|
||||
savepath_pipeline_imgs.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
savepath_pipeline_imgs.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
savepath_pipeline_subimgs = savepath_pipeline / Path("subimgs")
|
||||
if not savepath_pipeline_subimgs.exists():
|
||||
savepath_pipeline_subimgs.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
'''Yolo + Resnet + Tracker'''
|
||||
'''================= 3. Yolo + Resnet + Tracker ================='''
|
||||
optdict["source"] = vpath
|
||||
optdict["save_dir"] = savepath_pipeline_imgs
|
||||
|
||||
@ -162,11 +164,8 @@ def pipeline(
|
||||
|
||||
CameraEvent["yoloResnetTracker"] = yrtOut
|
||||
|
||||
|
||||
# bboxes = np.empty((0, 9), dtype = np.float32)
|
||||
# for frameDict in yrtOut:
|
||||
# bboxes = np.concatenate([bboxes, frameDict["tboxes"]], axis=0)
|
||||
|
||||
'''================= 4. tracking ================='''
|
||||
'''(1) 生成用于 tracking 模块的 boxes、feats'''
|
||||
trackerboxes = np.empty((0, 9), dtype=np.float64)
|
||||
trackefeats = {}
|
||||
for frameDict in yrtOut:
|
||||
@ -179,7 +178,7 @@ def pipeline(
|
||||
trackefeats.update({f"{fid}_{bid}": ffeats[f"{fid}_{bid}"]})
|
||||
|
||||
|
||||
'''tracking'''
|
||||
'''(2) tracking, 后摄'''
|
||||
if CameraEvent["cameraType"] == "back":
|
||||
vts = doBackTracks(trackerboxes, trackefeats)
|
||||
vts.classify()
|
||||
@ -187,7 +186,8 @@ def pipeline(
|
||||
|
||||
CameraEvent["tracking"] = vts
|
||||
ShoppingDict["backCamera"] = CameraEvent
|
||||
|
||||
|
||||
'''(2) tracking, 前摄'''
|
||||
if CameraEvent["cameraType"] == "front":
|
||||
vts = doFrontTracks(trackerboxes, trackefeats)
|
||||
vts.classify()
|
||||
@ -196,11 +196,12 @@ def pipeline(
|
||||
CameraEvent["tracking"] = vts
|
||||
ShoppingDict["frontCamera"] = CameraEvent
|
||||
|
||||
|
||||
'''========================== 保存模块 ================================='''
|
||||
'''(1) 保存 ShoppingDict 事件'''
|
||||
with open(str(pf_path), 'wb') as f:
|
||||
pickle.dump(ShoppingDict, f)
|
||||
|
||||
|
||||
|
||||
'''(2) 保存 Tracking 输出的运动轨迹子图,并记录相似度'''
|
||||
for CamerType, vts in event_tracks:
|
||||
if len(vts.tracks)==0: continue
|
||||
if CamerType == 'front':
|
||||
@ -215,16 +216,14 @@ def pipeline(
|
||||
imgdict.update(y["imgs"])
|
||||
featdict.update(y["feats"])
|
||||
simidict.update(y["featsimi"])
|
||||
|
||||
|
||||
|
||||
for track in vts.Residual:
|
||||
if isinstance(track, np.ndarray):
|
||||
save_subimgs(imgdict, track, savepath_pipeline_subimgs, ctype, featdict)
|
||||
else:
|
||||
save_subimgs(imgdict, track.slt_boxes, savepath_pipeline_subimgs, ctype, featdict)
|
||||
|
||||
|
||||
'''轨迹显示模块'''
|
||||
'''(3) 轨迹显示与保存'''
|
||||
illus = [None, None]
|
||||
for CamerType, vts in event_tracks:
|
||||
if len(vts.tracks)==0: continue
|
||||
@ -279,15 +278,15 @@ def main():
|
||||
if item.is_dir():
|
||||
# item = evtdir/Path("20241209-160201-b97f7a0e-7322-4375-9f17-c475500097e9_6926265317292")
|
||||
parmDict["eventpath"] = item
|
||||
pipeline(**parmDict)
|
||||
# pipeline(**parmDict)
|
||||
|
||||
# try:
|
||||
# pipeline(**parmDict)
|
||||
# except Exception as e:
|
||||
# errEvents.append(str(item))
|
||||
k+=1
|
||||
if k==2:
|
||||
break
|
||||
try:
|
||||
pipeline(**parmDict)
|
||||
except Exception as e:
|
||||
errEvents.append(str(item))
|
||||
# k+=1
|
||||
# if k==100:
|
||||
# break
|
||||
|
||||
errfile = os.path.join(parmDict["savepath"], f'error_events.txt')
|
||||
with open(errfile, 'w', encoding='utf-8') as f:
|
||||
|
Reference in New Issue
Block a user