Beispiel #1
0
    def __init__(self,
                 img_dir,
                 tracker_type=None,
                 tracker_params=DEFAULT_PARAMS,
                 dataset_config=None,
                 max_frames=None,
                 IOUmin=0.33):
        self.img_dir = img_dir
        self.tracker_type = tracker_type
        self.frame_list = get_img_list(img_dir)
        self.frame_list.sort()
        if max_frames:
            self.frame_list = self.frame_list[:max_frames]
        dataname = img_dir.split('/')[-2]

        self.gts = get_ground_truthes(img_dir[:-4])
        frame_list_len = len(self.frame_list)
        gts_len = len(self.gts)
        if gts_len > frame_list_len:
            self.gts = self.gts[:frame_list_len]
        elif gts_len < frame_list_len:
            self.gts += [None] * (frame_list_len - gts_len)

        self.tracker = CSRDCF(config=tracker_params)
        self.init_gt = self.gts[0]

        self.IOUmin = IOUmin
Beispiel #2
0
 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] # / in linux \\ in windows
     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 == '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 == 'VGG16':
         self.tracker = VGG16()
     elif self.tracker_type == 'YOLOV4':
         self.tracker = YOLOV4()
     else:
         raise NotImplementedError
Beispiel #3
0
 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()
     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()
     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_LP()
     else:
         raise NotImplementedError
def vis_results(results_json_path,dataset_dir,data_name):
    f = open(results_json_path, 'r')
    results = json.load(f)
    if not data_name in results.keys():
        raise ValueError
    cap=cv2.VideoCapture(data_name+'_vis.avi')
    data_all = results[data_name]
    gts = get_preds_by_name(data_all, 'gts')
    kcf_gray_preds = get_preds_by_name(data_all, 'kcf_gray_preds')
    kcf_hog_preds = get_preds_by_name(data_all, 'kcf_hog_preds')
    dcf_gray_preds = get_preds_by_name(data_all, 'dcf_gray_preds')
    dcf_hog_preds = get_preds_by_name(data_all, 'dcf_hog_preds')
    mosse_preds = get_preds_by_name(data_all, 'mosse')
    dsst_preds=get_preds_by_name(data_all,'DSST')
    csk_preds = get_preds_by_name(data_all, 'csk')
    eco_hc_preds = get_preds_by_name(data_all, 'eco_hc')
    #kcf_cn_preds = get_preds_by_name(data_all, 'kcf_cn')
    #kcf_pyECO_cn_preds = get_preds_by_name(data_all, 'kcf_pyECO_cn')
    img_dir=os.path.join(dataset_dir,data_name)
    img_dir=os.path.join(img_dir,'img')
    img_list=get_img_list(img_dir)
    color_gt=(0,97,255)# gt 橙色
    color_mosse=(0,255,0)# mosse green
    color_csk=(0,0,255)# csk red
    color_eco=(100,0,100) #
    color_kcf=(255,0,0)
    color_dsst=(240,32,160)#
    writer=None
    for i in range(len(csk_preds)):
        flag,current_frame=cap.read()
        if flag is False:
            return
        gt=gts[i]
        mosse_pred=mosse_preds[i]
        csk_pred=csk_preds[i]
        eco_hc_pred=eco_hc_preds[i]
        dsst_pred=dsst_preds[i]

        show_frame=cv2.rectangle(current_frame,(gt[0],gt[1]),(gt[0]+gt[2],gt[1]+gt[3]),color_gt,thickness=2)

        show_frame=cv2.rectangle(show_frame,(mosse_pred[0],mosse_pred[1]),
                                 (mosse_pred[0]+mosse_pred[2],mosse_pred[1]+mosse_pred[3]),
                                 color_mosse)
        show_frame=cv2.rectangle(show_frame,(csk_pred[0],csk_pred[1]),
                                 (csk_pred[0]+csk_pred[2],csk_pred[1]+csk_pred[3]),
                                 color_csk)
        show_frame=cv2.rectangle(show_frame,(eco_hc_pred[0],eco_hc_pred[1]),
                                 (eco_hc_pred[0]+eco_hc_pred[2],eco_hc_pred[1]+eco_hc_pred[3]),
                                 color_eco)
        show_frame=cv2.rectangle(show_frame,(dsst_pred[0],dsst_pred[1]),
                                 (dsst_pred[0]+dsst_pred[2],dsst_pred[1]+dsst_pred[3]),
                                 color_dsst)

        threshes,kcf_success=get_thresh_success_pair(gts,kcf_hog_preds)
        _,csk_success=get_thresh_success_pair(gts,csk_preds)
        _,mosse_success=get_thresh_success_pair(gts,mosse_preds)
        _,dsst_success=get_thresh_success_pair(gts,dsst_preds)
        _,ecohc_success=get_thresh_success_pair(gts,eco_hc_preds)
        _,gts_success=get_thresh_success_pair(gts,gts)
        show_frame = cv2.putText(show_frame, 'MOSSE ' + str(calAUC(mosse_success))[:5], (50, 40),
                                 cv2.FONT_HERSHEY_COMPLEX, 1, color_mosse)
        show_frame=cv2.putText(show_frame,'KCF '+str(calAUC(kcf_success))[:5],(50,120),cv2.FONT_HERSHEY_COMPLEX,1,color_kcf)
        show_frame=cv2.putText(show_frame,'CSK '+str(calAUC(csk_success))[:5],(50,80),cv2.FONT_HERSHEY_COMPLEX,1,color_csk)
        show_frame=cv2.putText(show_frame,'ECO '+str(calAUC(dsst_success))[:5],(50,200),cv2.FONT_HERSHEY_COMPLEX,1,color_eco)
        show_frame=cv2.putText(show_frame,'DSST '+str(calAUC(ecohc_success))[:5],(50,160),cv2.FONT_HERSHEY_COMPLEX,1,color_dsst)
        show_frame=cv2.putText(show_frame,'GT',(50,240),cv2.FONT_HERSHEY_COMPLEX,1,color_gt)
        cv2.imshow('demo',show_frame)
        if writer is None:
            writer = cv2.VideoWriter(data_name+'_res.avi', cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), 5,
                                     (show_frame.shape[1], show_frame.shape[0]))
        writer.write(show_frame)
        cv2.waitKey(30)
    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 __init__(self, img_dir, anno_dir, tracker_type):
        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 = get_init_gt(anno_dir)
        #        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=='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())
        if self.tracker_type == 'STRCF':
            self.tracker = STRCF()
        if self.tracker_type == 'AutoTrack':
            self.tracker = AutoTrack()
#        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