modify at output data format
This commit is contained in:
138
pipeline.py
138
pipeline.py
@ -45,7 +45,7 @@ def get_interbcd_inputenents():
|
||||
|
||||
def pipeline(
|
||||
eventpath,
|
||||
savepath,
|
||||
savepath = '',
|
||||
SourceType = "image", # video
|
||||
stdfeat_path = None
|
||||
):
|
||||
@ -53,47 +53,120 @@ def pipeline(
|
||||
vpaths = get_video_pairs(eventpath)
|
||||
elif SourceType == "image":
|
||||
vpaths = get_image_pairs(eventpath)
|
||||
|
||||
'''
|
||||
eventpath: 单个事件的存储路径
|
||||
|
||||
'''
|
||||
|
||||
'''======== 函数 yolo_resnet_tracker() 的参数字典 ========'''
|
||||
opt = parse_opt()
|
||||
optdict = vars(opt)
|
||||
|
||||
|
||||
optdict["weights"] = r'D:\DetectTracking\ckpts\best_cls10_0906.pt'
|
||||
optdict["is_save_img"] = True
|
||||
optdict["is_save_video"] = True
|
||||
|
||||
event_tracks = []
|
||||
|
||||
## 构造购物事件字典
|
||||
evtname = Path(eventpath).stem
|
||||
barcode = evtname.split('_')[-1] if len(evtname.split('_'))>=2 \
|
||||
and len(evtname.split('_')[-1])>=8 \
|
||||
and evtname.split('_')[-1].isdigit() else ''
|
||||
'''事件结果存储文件夹'''
|
||||
if not savepath:
|
||||
savepath = Path(__file__).resolve().parents[0] / "evtresult"
|
||||
save_dir_event = Path(savepath) / evtname
|
||||
|
||||
|
||||
ShoppingDict = {"eventPath": eventpath,
|
||||
"eventName": evtname,
|
||||
"barcode": barcode,
|
||||
"eventType": '', # "input", "output", "other"
|
||||
"frontCamera": {},
|
||||
"backCamera": {}}
|
||||
|
||||
for vpath in vpaths:
|
||||
'''事件结果文件夹'''
|
||||
save_dir_event = Path(savepath) / Path(os.path.basename(eventpath))
|
||||
'''相机事件字典构造'''
|
||||
CameraEvent = {"cameraType": '', # "front", "back"
|
||||
"videoPath": '',
|
||||
"imagePaths": [],
|
||||
"yoloResnetTracker": [],
|
||||
"tracking": [],
|
||||
}
|
||||
|
||||
if isinstance(vpath, list):
|
||||
save_dir_video = save_dir_event / Path("images")
|
||||
CameraEvent["imagePaths"] = vpath
|
||||
bname = os.path.basename(vpath[0])
|
||||
if not isinstance(vpath, list):
|
||||
CameraEvent["videoPath"] = vpath
|
||||
bname = os.path.basename(vpath)
|
||||
if bname.split('_')[0] == "0" or bname.find('back')>=0:
|
||||
CameraEvent["cameraType"] = "back"
|
||||
if bname.split('_')[0] == "1" or bname.find('front')>=0:
|
||||
CameraEvent["cameraType"] = "front"
|
||||
|
||||
'''事件结果存储文件夹'''
|
||||
|
||||
if isinstance(vpath, list):
|
||||
save_dir_video = save_dir_event / Path("images")
|
||||
else:
|
||||
save_dir_video = save_dir_event / Path(str(Path(vpath).stem))
|
||||
|
||||
if not save_dir_video.exists():
|
||||
save_dir_video.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
'''Yolo + Resnet + Tracker'''
|
||||
optdict["source"] = vpath
|
||||
optdict["save_dir"] = save_dir_video
|
||||
|
||||
yrtOut = yolo_resnet_tracker(**optdict)
|
||||
|
||||
tracksdict = yolo_resnet_tracker(**optdict)
|
||||
CameraEvent["yoloResnetTracker"] = yrtOut
|
||||
|
||||
bboxes = tracksdict['TrackBoxes']
|
||||
|
||||
bname = os.path.basename(vpath[0]) if isinstance(vpath, list) else os.path.basename(vpath)
|
||||
if bname.split('_')[0] == "0" or bname.find('back')>=0:
|
||||
vts = doBackTracks(bboxes, tracksdict)
|
||||
vts.classify()
|
||||
# bboxes = np.empty((0, 9), dtype = np.float32)
|
||||
# for frameDict in yrtOut:
|
||||
# bboxes = np.concatenate([bboxes, frameDict["tboxes"]], axis=0)
|
||||
|
||||
trackerboxes = np.empty((0, 9), dtype=np.float64)
|
||||
trackefeats = {}
|
||||
for frameDict in yrtOut:
|
||||
tboxes = frameDict["tboxes"]
|
||||
ffeats = frameDict["feats"]
|
||||
|
||||
trackerboxes = np.concatenate((trackerboxes, np.array(tboxes)), axis=0)
|
||||
for i in range(len(tboxes)):
|
||||
fid, bid = int(tboxes[i, 7]), int(tboxes[i, 8])
|
||||
trackefeats.update({f"{fid}_{bid}": ffeats[f"{fid}_{bid}"]})
|
||||
|
||||
|
||||
'''tracking'''
|
||||
if CameraEvent["cameraType"] == "back":
|
||||
vts = doBackTracks(trackerboxes, trackefeats)
|
||||
vts.classify()
|
||||
event_tracks.append(("back", vts))
|
||||
|
||||
if bname.split('_')[0] == "1" or bname.find('front')>=0:
|
||||
vts = doFrontTracks(bboxes, tracksdict)
|
||||
CameraEvent["tracking"] = vts
|
||||
ShoppingDict["backCamera"] = CameraEvent
|
||||
|
||||
if CameraEvent["cameraType"] == "front":
|
||||
vts = doFrontTracks(trackerboxes, trackefeats)
|
||||
vts.classify()
|
||||
event_tracks.append(("front", vts))
|
||||
|
||||
CameraEvent["tracking"] = vts
|
||||
ShoppingDict["frontCamera"] = CameraEvent
|
||||
|
||||
|
||||
# pklpath = save_dir_event / "ShoppingDict.pkl"
|
||||
# with open(str(pklpath), 'wb') as f:
|
||||
# pickle.dump(ShoppingDict, f)
|
||||
pklpath = Path(savepath) / evtname+".pkl"
|
||||
with open(str(pklpath), 'wb') as f:
|
||||
pickle.dump(ShoppingDict, f)
|
||||
|
||||
|
||||
'''轨迹显示模块'''
|
||||
illus = [None, None]
|
||||
for CamerType, vts in event_tracks:
|
||||
@ -182,14 +255,39 @@ def main():
|
||||
'''
|
||||
函数:pipeline(),遍历事件文件夹,选择类型 image 或 video,
|
||||
'''
|
||||
parmDict = {}
|
||||
parmDict["eventpath"] = r"\\192.168.1.28\share\测试视频数据以及日志\各模块测试记录\展厅测试\1120_展厅模型v801测试\扫A放A\20241121-144855-dce94b09-1100-43f1-92e8-33a1b538b159_6924743915848_6924743915848"
|
||||
evtdir = r"\\192.168.1.28\share\测试视频数据以及日志\各模块测试记录\比对测试\1209永辉超市测试"
|
||||
evtdir = Path(evtdir)
|
||||
|
||||
parmDict["savepath"] = r"D:\contrast\detect"
|
||||
parmDict = {}
|
||||
parmDict["savepath"] = r"D:\contrast\detect\pipeline"
|
||||
parmDict["SourceType"] = "image" # video, image
|
||||
parmDict["stdfeat_path"] = None
|
||||
|
||||
pipeline(**parmDict)
|
||||
|
||||
k = 1
|
||||
errEvents = []
|
||||
for item in evtdir.iterdir():
|
||||
if item.is_dir():
|
||||
item = r"D:\exhibition\images\images2\images2"
|
||||
|
||||
|
||||
parmDict["eventpath"] = item
|
||||
|
||||
|
||||
try:
|
||||
pipeline(**parmDict)
|
||||
except Exception as e:
|
||||
errEvents.append(item)
|
||||
|
||||
|
||||
# k+=1
|
||||
# if k==1:
|
||||
# break
|
||||
|
||||
errfile = os.path.join(parmDict["savepath"], f'error_events.txt')
|
||||
with open(errfile, 'w', encoding='utf-8') as f:
|
||||
for line in errEvents:
|
||||
f.write(line + '\n')
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user