def __init__(self, img_dir, tracker_type, dataset_config): self.img_dir = img_dir self.tracker_type = tracker_type if self.tracker_type == 'MOSSE': self.tracker = MOSSE() elif self.tracker_type == 'CSK': self.tracker = CSK() elif self.tracker_type == 'CN': self.tracker = CN() elif self.tracker_type == 'DSST': self.tracker = DSST(dsst_config.DSSTConfig()) elif self.tracker_type == 'Staple': self.tracker = Staple(config=staple_config.StapleConfig()) elif self.tracker_type == 'Staple-CA': self.tracker = Staple(config=staple_config.StapleCAConfig()) elif self.tracker_type == 'KCF_CN': self.tracker = KCF(features='cn', kernel='gaussian') elif self.tracker_type == 'KCF_GRAY': self.tracker = KCF(features='gray', kernel='gaussian') elif self.tracker_type == 'KCF_HOG': self.tracker = KCF(features='hog', kernel='gaussian') elif self.tracker_type == 'DCF_GRAY': self.tracker = KCF(features='gray', kernel='linear') elif self.tracker_type == 'DCF_HOG': self.tracker = KCF(features='hog', kernel='linear') elif self.tracker_type == 'DAT': self.tracker = DAT() elif self.tracker_type == 'ECO-HC': self.tracker = ECO(config=otb_hc_config.OTBHCConfig()) elif self.tracker_type == 'ECO': self.tracker = ECO(config=otb_deep_config.OTBDeepConfig()) elif self.tracker_type == 'BACF': self.tracker = BACF() elif self.tracker_type == 'CSRDCF': self.tracker = CSRDCF(config=csrdcf_config.CSRDCFConfig()) elif self.tracker_type == 'CSRDCF-LP': self.tracker = CSRDCF(config=csrdcf_config.CSRDCFLPConfig()) elif self.tracker_type == 'SAMF': self.tracker = SAMF() elif self.tracker_type == 'LDES': self.tracker = LDES(ldes_config.LDESDemoLinearConfig()) elif self.tracker_type == 'DSST-LP': self.tracker = DSST(dsst_config.DSSTLPConfig()) elif self.tracker_type == 'MKCFup': self.tracker = MKCFup(config=mkcf_up_config.MKCFupConfig()) elif self.tracker_type == 'MKCFup-LP': self.tracker = MKCFup(config=mkcf_up_config.MKCFupLPConfig()) elif self.tracker_type == 'STRCF': self.tracker = STRCF() elif self.tracker_type == 'MCCTH-Staple': self.tracker = MCCTHStaple( config=mccth_staple_config.MCCTHOTBConfig()) else: raise NotImplementedError
def create_tracker(tracker_type): if tracker_type == 'MOSSE': tracker = MOSSE() elif tracker_type == 'CSK': tracker = CSK() elif tracker_type == 'CN': tracker = CN() elif tracker_type == 'DSST': tracker = DSST(dsst_config.DSSTConfig()) elif tracker_type == 'SAMF': tracker = SAMF() elif tracker_type == 'Staple': tracker = Staple(config=staple_config.StapleVOTConfig()) #elif tracker_type=='Staple-CA': # tracker=Staple(config=staple_config.StapleCAVOTConfig()) elif tracker_type == 'KCF': tracker = KCF(features='hog', kernel='gaussian') elif tracker_type == 'DCF': tracker = KCF(features='hog', kernel='linear') elif tracker_type == 'DAT': tracker = DAT() elif tracker_type == 'ECO-HC': tracker = ECO(config=vot18_hc_config.VOT18HCConfig()) elif tracker_type == 'ECO': tracker = ECO(config=vot18_deep_config.VOT18DeepConfig()) elif tracker_type == 'BACF': tracker = BACF() elif tracker_type == 'CSRDCF': tracker = CSRDCF(csrdcf_config.CSRDCFConfig()) elif tracker_type == 'CSRDCF-LP': tracker = CSRDCF(csrdcf_config.CSRDCFLPConfig()) elif tracker_type == 'OPENCV_KCF': tracker = OpenCVCFTracker(name='KCF') elif tracker_type == 'OPENCV_MOSSE': tracker = OpenCVCFTracker(name='MOSSE') elif tracker_type == 'OPENCV-CSRDCF': tracker = OpenCVCFTracker(name='CSRDCF') elif tracker_type == 'LDES': tracker = LDES(config=ldes_config.LDESVOTLinearConfig()) elif tracker_type == 'LDES-NoBGD': tracker = LDES(config=ldes_config.LDESVOTNoBGDLinearConfig()) elif tracker_type == 'DSST-LP': tracker = DSST(dsst_config.DSSTLPConfig()) elif tracker_type == 'MKCFup': tracker = MKCFup(config=mkcf_up_config.MKCFupConfig()) elif tracker_type == 'MKCFup-LP': tracker = MKCFup(config=mkcf_up_config.MKCFupLPConfig()) elif tracker_type == 'STRCF': tracker = STRCF() elif tracker_type == 'MCCTH-Staple': tracker = MCCTHStaple(config=mccth_staple_config.MCCTHVOTConfig()) else: raise NotImplementedError return tracker
from cftracker import dsst from cftracker.config import dsst_config import numpy as np import cv2 tracker = dsst.DSST(dsst_config.DSSTConfig()) # tracker instance cap = cv2.VideoCapture(0) #or video ret, frame = cap.read() roi = cv2.selectROI(windowName="demo", img=frame, showCrosshair=False, fromCenter=False) x, y, w, h = roi tracker.init(frame, roi) # initialize tracker with GT bounding box while True: ret, frame = cap.read() x1, y1, w1, h1 = tracker.update( frame) # update tracker and output estimated position x1 = int(x1) y1 = int(y1) w1 = int(w1) h1 = int(h1) cv2.rectangle(frame, (x1, y1), (x1 + w1, y1 + h1), (255, 0, 0), 2) cv2.imshow('demo', frame) if cv2.waitKey(1) & 0xFF == ord('q'): print("Exit!") break
def __init__(self, img_dir, tracker_type, dataset_config): self.img_dir = img_dir self.tracker_type = tracker_type self.frame_list = get_img_list(img_dir) self.frame_list.sort() dataname = img_dir.split('\\')[-2] self.gts = get_ground_truthes(img_dir[:-4]) if dataname in dataset_config.frames.keys(): start_frame, end_frame = dataset_config.frames[dataname][0:2] if dataname != 'David': self.init_gt = self.gts[start_frame - 1] else: self.init_gt = self.gts[0] self.frame_list = self.frame_list[start_frame - 1:end_frame] else: self.init_gt = self.gts[0] if self.tracker_type == 'MOSSE': self.tracker = MOSSE() elif self.tracker_type == 'CSK': self.tracker = CSK() elif self.tracker_type == 'CN': self.tracker = CN() elif self.tracker_type == 'DSST': self.tracker = DSST(dsst_config.DSSTConfig()) elif self.tracker_type == 'Staple': self.tracker = Staple(config=staple_config.StapleConfig()) elif self.tracker_type == 'Staple-CA': self.tracker = Staple(config=staple_config.StapleCAConfig()) elif self.tracker_type == 'KCF_CN': self.tracker = KCF(features='cn', kernel='gaussian') elif self.tracker_type == 'KCF_GRAY': self.tracker = KCF(features='gray', kernel='gaussian') elif self.tracker_type == 'KCF_HOG': self.tracker = KCF(features='hog', kernel='gaussian') elif self.tracker_type == 'DCF_GRAY': self.tracker = KCF(features='gray', kernel='linear') elif self.tracker_type == 'DCF_HOG': self.tracker = KCF(features='hog', kernel='linear') elif self.tracker_type == 'DAT': self.tracker = DAT() elif self.tracker_type == 'ECO-HC': self.tracker = ECO(config=otb_hc_config.OTBHCConfig()) elif self.tracker_type == 'ECO': self.tracker = ECO(config=otb_deep_config.OTBDeepConfig()) elif self.tracker_type == 'BACF': self.tracker = BACF() elif self.tracker_type == 'CSRDCF': self.tracker = CSRDCF(config=csrdcf_config.CSRDCFConfig()) elif self.tracker_type == 'CSRDCF-LP': self.tracker = CSRDCF(config=csrdcf_config.CSRDCFLPConfig()) elif self.tracker_type == 'SAMF': self.tracker = SAMF() elif self.tracker_type == 'LDES': self.tracker = LDES(ldes_config.LDESDemoLinearConfig()) elif self.tracker_type == 'DSST-LP': self.tracker = DSST(dsst_config.DSSTLPConfig()) elif self.tracker_type == 'MKCFup': self.tracker = MKCFup(config=mkcf_up_config.MKCFupConfig()) elif self.tracker_type == 'MKCFup-LP': self.tracker = MKCFup(config=mkcf_up_config.MKCFupLPConfig()) elif self.tracker_type == 'STRCF': self.tracker = STRCF() elif self.tracker_type == 'MCCTH-Staple': self.tracker = MCCTHStaple( config=mccth_staple_config.MCCTHOTBConfig()) elif self.tracker_type == 'MCCTH': self.tracker = MCCTH(config=mccth_config.MCCTHConfig()) else: raise NotImplementedError
def __init__(self,img_dir,tracker_type,dataset_config): # img_directory is an attribute self.img_dir=img_dir # tracker type definition self.tracker_type=tracker_type # get_img_list function appends the name of all jpg files into a list. self.frame_list = get_img_list(img_dir) # Sorting the frame_list self.frame_list.sort() # name of the folder dataname=img_dir.split('/')[-2] # Getting the ground truth self.gts=get_ground_truthes(img_dir[:-4]) if dataname in dataset_config.frames.keys(): start_frame,end_frame=dataset_config.frames[dataname][0:2] if dataname!='David': self.init_gt=self.gts[start_frame-1] else: self.init_gt=self.gts[0] self.frame_list=self.frame_list[start_frame-1:end_frame] else: self.init_gt=self.gts[0] # Calling the appropriate tracker class as asked for. if self.tracker_type == 'MOSSE': self.tracker=MOSSE() elif self.tracker_type=='CSK': self.tracker=CSK() elif self.tracker_type=='CN': self.tracker=CN() elif self.tracker_type=='DSST': self.tracker=DSST(dsst_config.DSSTConfig()) elif self.tracker_type=='Staple': self.tracker=Staple(config=staple_config.StapleConfig()) elif self.tracker_type=='Staple-CA': self.tracker=Staple(config=staple_config.StapleCAConfig()) elif self.tracker_type=='KCF_CN': self.tracker=KCF(features='cn',kernel='gaussian') elif self.tracker_type=='KCF_GRAY': self.tracker=KCF(features='gray',kernel='gaussian') elif self.tracker_type=='KCF_HOG': self.tracker=KCF(features='hog',kernel='gaussian') elif self.tracker_type=='DCF_GRAY': self.tracker=KCF(features='gray',kernel='linear') elif self.tracker_type=='DCF_HOG': self.tracker=KCF(features='hog',kernel='linear') elif self.tracker_type=='DAT': self.tracker=DAT() elif self.tracker_type=='ECO-HC': self.tracker=ECO(config=otb_hc_config.OTBHCConfig()) elif self.tracker_type=='ECO': self.tracker=ECO(config=otb_deep_config.OTBDeepConfig()) elif self.tracker_type=='BACF': self.tracker=BACF() elif self.tracker_type=='CSRDCF': self.tracker=CSRDCF(config=csrdcf_config.CSRDCFConfig()) elif self.tracker_type=='CSRDCF-LP': self.tracker=CSRDCF(config=csrdcf_config.CSRDCFLPConfig()) elif self.tracker_type=='SAMF': self.tracker=SAMF() elif self.tracker_type=='LDES': self.tracker=LDES(ldes_config.LDESDemoLinearConfig()) elif self.tracker_type=='DSST-LP': self.tracker=DSST(dsst_config.DSSTLPConfig()) elif self.tracker_type=='MKCFup': self.tracker=MKCFup(config=mkcf_up_config.MKCFupConfig()) elif self.tracker_type=='MKCFup-LP': self.tracker=MKCFup(config=mkcf_up_config.MKCFupLPConfig()) elif self.tracker_type=='STRCF': self.tracker=STRCF() elif self.tracker_type=='MCCTH-Staple': self.tracker=MCCTHStaple(config=mccth_staple_config.MCCTHOTBConfig()) elif self.tracker_type=='MCCTH': self.tracker=MCCTH(config=mccth_config.MCCTHConfig()) else: raise NotImplementedError
def track_otb(tracker_type, dataset): for video in dataset: regions = [] print('video:', video.name) if tracker_type == 'MOSSE': tracker = MOSSE() elif tracker_type == 'CSK': tracker = CSK() elif tracker_type == 'CN': tracker = CN() elif tracker_type == 'DSST': tracker = DSST(dsst_config.DSSTConfig()) elif tracker_type == 'SAMF': tracker = SAMF() elif tracker_type == 'Staple': tracker = Staple(config=staple_config.StapleConfig()) elif tracker_type == 'Staple-CA': tracker = Staple(config=staple_config.StapleCAConfig()) elif tracker_type == 'KCF': tracker = KCF(features='hog', kernel='gaussian') elif tracker_type == 'DCF': tracker = KCF(features='hog', kernel='linear') elif tracker_type == 'DAT': tracker = DAT() elif tracker_type == 'ECO-HC': tracker = ECO(config=otb_hc_config.OTBHCConfig()) elif tracker_type == 'ECO': tracker = ECO(config=otb_deep_config.OTBDeepConfig()) elif tracker_type == 'BACF': tracker = BACF() elif tracker_type == 'CSRDCF': tracker = CSRDCF(csrdcf_config.CSRDCFConfig()) elif tracker_type == 'CSRDCF-LP': tracker = CSRDCF(csrdcf_config.CSRDCFLPConfig()) elif tracker_type == 'OPENCV_KCF': tracker = OpenCVCFTracker(name='KCF') elif tracker_type == 'OPENCV_MOSSE': tracker = OpenCVCFTracker(name='MOSSE') elif tracker_type == 'OPENCV-CSRDCF': tracker = OpenCVCFTracker(name='CSRDCF') elif tracker_type == 'LDES': tracker = LDES(ldes_config.LDESOTBLinearConfig()) elif tracker_type == 'LDES-NoBGD': tracker = LDES(ldes_config.LDESOTBNoBGDLinearConfig()) elif tracker_type == 'DSST-LP': tracker = DSST(dsst_config.DSSTLPConfig()) elif tracker_type == 'MKCFup': tracker = MKCFup(mkcf_up_config.MKCFupConfig()) elif tracker_type == 'MKCFup-LP': tracker = MKCFup(mkcf_up_config.MKCFupLPConfig()) elif tracker_type == 'STRCF': tracker = STRCF() elif tracker_type == 'MCCTH-Staple': tracker = MCCTHStaple(mccth_staple_config.MCCTHOTBConfig()) else: raise NotImplementedError for idx, (img, gt_bbox) in enumerate(video): if idx == 0: # init your tracker here tracker.init(img, tuple(gt_bbox)) regions.append(gt_bbox) location = gt_bbox else: bbox = tracker.update(img) regions.append(bbox) location = bbox if args.visualization and idx >= 0: # visualization (skip lost frame) im_show = img.copy() if idx == 0: cv2.destroyAllWindows() cv2.rectangle( im_show, (gt_bbox[0], gt_bbox[1]), (gt_bbox[0] + gt_bbox[2], gt_bbox[1] + gt_bbox[3]), (0, 255, 0), 3) location = [int(l) for l in location] cv2.rectangle( im_show, (location[0], location[1]), (location[0] + location[2], location[1] + location[3]), (0, 255, 255), 3) cv2.putText(im_show, str(idx), (40, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 2) cv2.imshow(video.name, im_show) cv2.waitKey(1) name = tracker_type video_path = join('test', args.dataset, name) if not isdir(video_path): makedirs(video_path) result_path = join(video_path, '{:s}.txt'.format(video.name)) with open(result_path, "w") as fin: for x in regions: fin.write(','.join([str(i) for i in x]) + '\n')