add yolo v10 and modify pipeline
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -116,11 +116,13 @@ class BOTSORT(BYTETracker):
|
||||
self.proximity_thresh = args.proximity_thresh
|
||||
self.appearance_thresh = args.appearance_thresh
|
||||
|
||||
if args.with_reid:
|
||||
# Haven't supported BoT-SORT(reid) yet
|
||||
# self.encoder = ReIDInterface(config)
|
||||
# if args.with_reid:
|
||||
# # Haven't supported BoT-SORT(reid) yet
|
||||
# # self.encoder = ReIDInterface(config)
|
||||
|
||||
self.encoder = FeatsInterface(conf)
|
||||
# self.encoder = FeatsInterface(conf)
|
||||
|
||||
# print('load model {} in BOTSORT'.format(conf.testbackbone))
|
||||
|
||||
# self.gmc = GMC(method=args.gmc_method) # commented by WQG
|
||||
|
||||
|
180
tracking/tracking_pipeline.py
Normal file
180
tracking/tracking_pipeline.py
Normal file
@ -0,0 +1,180 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Thu Mar 27 16:09:07 2025
|
||||
|
||||
@author: ym
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import cv2
|
||||
import pickle
|
||||
import numpy as np
|
||||
from pathlib import Path
|
||||
from scipy.spatial.distance import cdist
|
||||
|
||||
from .dotrack.dotracks_back import doBackTracks
|
||||
from .dotrack.dotracks_front import doFrontTracks
|
||||
from .utils.drawtracks import plot_frameID_y2, draw_all_trajectories
|
||||
from .utils.read_data import read_similar
|
||||
|
||||
|
||||
|
||||
|
||||
class CameraEvent_:
|
||||
def __init__(self):
|
||||
self.cameraType = '', # "front", "back"
|
||||
self.videoPath = '',
|
||||
self.imagePaths = [],
|
||||
self.yoloResnetTracker =[],
|
||||
self.tracking = None,
|
||||
|
||||
class ShoppingEvent_:
|
||||
def __init__(self):
|
||||
self.eventPath = ''
|
||||
self.eventName = ''
|
||||
self.barcode = ''
|
||||
self.eventType = '', # "input", "output", "other"
|
||||
self.frontCamera = None
|
||||
self.backCamera = None
|
||||
self.one2n = []
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
'''
|
||||
将一个对象读取,修改其中一个属性
|
||||
|
||||
'''
|
||||
|
||||
|
||||
evt_pkfile = 'path.pickle'
|
||||
with open(evt_pkfile, 'rb') as f:
|
||||
ShoppingDict = pickle.load(f)
|
||||
|
||||
savepath = ""
|
||||
|
||||
back_camera = ShoppingDict["backCamera"]["cameraType"]
|
||||
back_yrt = ShoppingDict["backCamera"]["yoloResnetTracker"]
|
||||
front_camera = ShoppingDict["frontCamera"]["cameraType"]
|
||||
front_yrt = ShoppingDict["frontCamera"]["yoloResnetTracker"]
|
||||
yrts = [(back_camera, back_yrt), (front_camera, front_yrt)]
|
||||
|
||||
|
||||
shopping_event = ShoppingEvent_()
|
||||
shopping_event.eventPath = ShoppingDict["eventPath"]
|
||||
shopping_event.eventName = ShoppingDict["eventName"]
|
||||
shopping_event.barcode = ShoppingDict["barcode"]
|
||||
|
||||
yrtDict = {}
|
||||
event_tracks = []
|
||||
for camera_type, yrtOut in yrts:
|
||||
'''
|
||||
inputs:
|
||||
yrtOut
|
||||
camera_type
|
||||
outputs:
|
||||
CameraEvent
|
||||
'''
|
||||
|
||||
camera_event = CameraEvent_()
|
||||
|
||||
|
||||
|
||||
'''================= 4. tracking ================='''
|
||||
'''(1) 生成用于 tracking 模块的 boxes、feats'''
|
||||
bboxes = np.empty((0, 6), dtype=np.float64)
|
||||
trackerboxes = np.empty((0, 9), dtype=np.float64)
|
||||
trackefeats = {}
|
||||
for frameDict in yrtOut:
|
||||
tboxes = frameDict["tboxes"]
|
||||
ffeats = frameDict["feats"]
|
||||
|
||||
boxes = frameDict["bboxes"]
|
||||
bboxes = np.concatenate((bboxes, np.array(boxes)), axis=0)
|
||||
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}"]})
|
||||
|
||||
|
||||
'''(2) tracking, 后摄'''
|
||||
if CameraEvent["cameraType"] == "back":
|
||||
vts = doBackTracks(trackerboxes, trackefeats)
|
||||
vts.classify()
|
||||
event_tracks.append(("back", vts))
|
||||
|
||||
|
||||
|
||||
camera_event.camera_type = camera_type
|
||||
camera_event.yoloResnetTracker = yrtOut
|
||||
camera_event.tracking = vts
|
||||
camera_event.videoPath = ShoppingDict["backCamera"]["videoPath"]
|
||||
camera_event.imagePaths = ShoppingDict["backCamera"]["imagePaths"]
|
||||
shopping_event.backCamera = camera_event
|
||||
|
||||
yrtDict["backyrt"] = yrtOut
|
||||
|
||||
'''(2) tracking, 前摄'''
|
||||
if CameraEvent["cameraType"] == "front":
|
||||
vts = doFrontTracks(trackerboxes, trackefeats)
|
||||
vts.classify()
|
||||
event_tracks.append(("front", vts))
|
||||
|
||||
camera_event.camera_type = camera_type
|
||||
camera_event.yoloResnetTracker = yrtOut
|
||||
camera_event.tracking = vts
|
||||
camera_event.videoPath = ShoppingDict["frontCamera"]["videoPath"]
|
||||
camera_event.imagePaths = ShoppingDict["frontCamera"]["imagePaths"]
|
||||
shopping_event.backCamera = camera_event
|
||||
|
||||
yrtDict["frontyrt"] = yrtOut
|
||||
|
||||
|
||||
name = Path(evt_pkfile).stem
|
||||
pf_path = os.path.join(savepath, name+"_new.pickle")
|
||||
with open(str(pf_path), 'wb') as f:
|
||||
pickle.dump(shopping_event, f)
|
||||
|
||||
|
||||
|
||||
illus = [None, None]
|
||||
for CamerType, vts in event_tracks:
|
||||
if len(vts.tracks)==0: continue
|
||||
|
||||
if CamerType == 'front':
|
||||
edgeline = cv2.imread("./tracking/shopcart/cart_tempt/board_ftmp_line.png")
|
||||
|
||||
h, w = edgeline.shape[:2]
|
||||
# nh, nw = h//2, w//2
|
||||
# edgeline = cv2.resize(edgeline, (nw, nh), interpolation=cv2.INTER_AREA)
|
||||
|
||||
img_tracking = draw_all_trajectories(vts, edgeline, savepath_pipeline, CamerType, draw5p=True)
|
||||
illus[0] = img_tracking
|
||||
|
||||
plt = plot_frameID_y2(vts)
|
||||
plt.savefig(os.path.join(savepath_pipeline, "front_y2.png"))
|
||||
|
||||
if CamerType == 'back':
|
||||
edgeline = cv2.imread("./tracking/shopcart/cart_tempt/edgeline.png")
|
||||
|
||||
h, w = edgeline.shape[:2]
|
||||
# nh, nw = h//2, w//2
|
||||
# edgeline = cv2.resize(edgeline, (nw, nh), interpolation=cv2.INTER_AREA)
|
||||
|
||||
img_tracking = draw_all_trajectories(vts, edgeline, savepath_pipeline, CamerType, draw5p=True)
|
||||
illus[1] = img_tracking
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user