You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.4 KiB
70 lines
2.4 KiB
import numpy as np
|
|
from pytracking.tracker.dimp.dimp import DiMP
|
|
import pytracking.utils.params
|
|
# from pytracking.evaluation.environment import env_settings
|
|
|
|
|
|
class Tracker:
|
|
"""Wraps the tracker for evaluation and running purposes.
|
|
args:
|
|
name: Name of tracking method.
|
|
parameter_name: Name of parameter file.
|
|
run_id: The run id.
|
|
display_name: Name to be displayed in the result plots.
|
|
"""
|
|
|
|
def __init__(self, name: str = 'dimp', parameter_name: str = 'dimp50', debug: bool = False):
|
|
self.name = name
|
|
self.parameter_name = parameter_name
|
|
self.run_id = None
|
|
self.display_name = None
|
|
|
|
# env = env_settings()
|
|
|
|
# self.results_dir = "pytracking/tracking_results/dimp/dimp50"
|
|
# #self.results_dir = '{}/{}/{}'.format(env.results_path, self.name, self.parameter_name)
|
|
# print('self result dir: ' ,self.results_dir)
|
|
|
|
# self.segmentation_dir = "pytracking/segmentation_results/dimp/dimp50"
|
|
# #self.segmentation_dir = '{}/{}/{}'.format(env.segmentation_path, self.name, self.parameter_name)
|
|
# print("self segmenttation dir: ",self.segmentation_dir)
|
|
|
|
#tracker_module_abspath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'tracker', self.name))
|
|
|
|
#tracker_module = importlib.import_module('pytracking.tracker.{}'.format(self.name)) # const pytracking.tracker.dimp
|
|
#print(f'pytracking.tracker.{self.name}')
|
|
#from pytracking.tracker.dimp.dimp import DiMP # alternative for const pytracking.tracker.dimp # moves to top
|
|
#self.tracker_class = DiMP
|
|
|
|
|
|
params = pytracking.utils.params.TrackerParams()
|
|
|
|
params.tracker_name = self.name
|
|
params.param_name = self.parameter_name
|
|
params.debug = debug
|
|
|
|
self.__tracker = DiMP(params)
|
|
|
|
self.is_tracking = False
|
|
|
|
|
|
def init(self, frame, bbox):
|
|
self.__tracker.initialize(frame, bbox)
|
|
self.is_tracking = True
|
|
|
|
def update(self, frame: np.ndarray):
|
|
bbox = None
|
|
success = False
|
|
if self.is_tracking:
|
|
out = self.__tracker.track(frame)
|
|
if 'target_bbox' in out:
|
|
bbox = out['target_bbox']
|
|
bbox = np.array([int(s) for s in bbox])
|
|
success = out.get('success', None)
|
|
|
|
return bbox, success
|
|
|
|
def stop(self):
|
|
self.is_tracking = False
|
|
self.__tracker.initialize()
|
|
|