def load_zhicheng_Params_TT(): ''' loading tracked target information in zhicheng datasets, including parameters and tracked targets tbbs and blobs. :return: ''' FilePath = 'F:\\code\\Python\\visual_radar_tracker\\images\\zhicheng20130808_22.28\\Res_MultiKCFs_AutoParams\\' ParamFiles = { 'ALice': 'ALice_Params.txt', 'Billy': 'Billy_Params.txt', 'Camen': 'Camen_Params.txt', 'Dolphin': 'Dolphin_Params.txt', 'Ellen': 'Ellen_Params.txt' } TtTbbsFiles = { 'ALice': 'ALice_tbbs_%02d_option.txt', 'Billy': 'Billy_tbbs_%02d_option.txt', 'Camen': 'Camen_tbbs_%02d_option.txt', 'Dolphin': 'Dolphin_tbbs_%02d_option.txt', 'Ellen': 'Ellen_tbbs_%02d_option.txt' } TtBlobsFiles = { 'ALice': 'ALice_blobs_%02d_option.txt', 'Billy': 'Billy_blobs_%02d_option.txt', 'Camen': 'Camen_blobs_%02d_option.txt', 'Dolphin': 'Dolphin_blobs_%02d_option.txt', 'Ellen': 'Ellen_blobs_%02d_option.txt' } ParamsTT = {} #according the parameters' file's lines to decide howmany tbbs and blob file included. for key in ParamFiles: obj_file = FilePath + ParamFiles[key] with open(obj_file, 'r') as obj: obj_lines = obj.readlines() for i, line in enumerate(obj_lines): #tbbs or blob ttfiles's index is correlated with the line number of parameters file tbbsFileName = (FilePath + TtTbbsFiles[key] % i) blobsFileName = (FilePath + TtBlobsFiles[key] % i) print(tbbsFileName) tbbsDict = uti.get_obj_dict(tbbsFileName) print(blobsFileName) tblobsDict = uti.get_obj_dict(blobsFileName) if tbbsDict == {} or tblobsDict == {}: print('Empty tt file is found in %s_%d, be carefull !!!!' % (key, i)) ptKey = '%s %d' % (key, i) ParamsTT.update({ ptKey: { 'Params': line, 'TbbsDict': tbbsDict, 'tblobsDict': tblobsDict } }) return ParamsTT
def show_precision(tracker_name): ''' show the scores of the given tracker :return: ''' print('\n%s\'s Tracking Results' % tracker_name) ObjNames = [] GtInfo = load_zhicheng_GT() for key in GtInfo: ObjNames.append(key) ObjNames.sort() res_path = '/Users/yizhou/code/MKCF_MAC_Python3.6/results/Res_%s/' % tracker_name # scores_table, contain 3 rows, for cle, pre_cle, pre_iou # the last column is for average. scores_table = np.zeros((3, 5)) # containing 5 objects' tracked bounding box in KfResData KfResData = {} for i, key in enumerate(ObjNames): fname = res_path + key + '_%s_Tbbs.txt' % tracker_name ttData = uti.get_obj_dict(fname) KfResData.update({key: ttData}) GtData = GtInfo[key]['GtData'] (evalue_reports, cle, IoU, pre_cle, pre_iou, fids) = show_tbb_precision(ttData, GtData, bplot=False) print(key) print(evalue_reports) scores_table[0, i] = np.mean(cle) scores_table[1, i] = np.mean(pre_cle) scores_table[2, i] = np.mean(pre_iou) return scores_table
def show_precision_MKCF(): ''' Show the tracking results with Extended Object Tracking based on Random Matrix, and draw the precision curve. :return: ''' print('\nMKCF\'s Tracking Results') ObjNames = [] GtInfo = load_zhicheng_GT() for key in GtInfo: ObjNames.append(key) ObjNames.sort() res_path = '/Users/yizhou/code/MKCF_MAC_Python3.6/results/Res_MKCF/' scores_table = np.zeros( (3, 5)) # scores_table, contain 3 rows, for cle, pre_cle, pre_iou # containing 5 objects' tracked bounding box in KfResData KfResData = {} for i, key in enumerate(ObjNames): fname = res_path + key + '_MKCF_Tbbs.txt' ttData = uti.get_obj_dict(fname) KfResData.update({key: ttData}) GtData = GtInfo[key]['GtData'] (evalue_reports, cle, IoU, pre_cle, pre_iou, fids) = show_tbb_precision(ttData, GtData, bplot=False) print(key) print(evalue_reports) scores_table[0, i] = cle scores_table[1, i] = pre_cle scores_table[2, i] = pre_iou return scores_table
def load_zhicheng_GT(): ''' Set the path and GT files name, according start_id, end_id. Convert the Gt file information into a dictionary data type [GtInfo] :return GtInfo: ''' FilePath = '../ground_truth/' GtParam = { 'ALice': { 'FileName': 'zhicheng20130808_22.xx_60-400_polarGT_Alice.txt', 'StartId': 60, 'EndId': 400 }, 'Billy': { 'FileName': 'zhicheng20130808_22.xx_2-215_polarGT_Billy.txt', 'StartId': 2, 'EndId': 226 }, 'Camen': { 'FileName': 'zhicheng20130808_22.xx_2-408_polarGT_Camen.txt', 'StartId': 75, 'EndId': 335 }, #'Camen': {'FileName': 'zhicheng20130808_22.xx_2-408_polarGT_Camen.txt', 'StartId': 2, 'EndId': 408}, 'Dolphin': { 'FileName': 'zhicheng20130808_22.xx_72-316_polarGT_Dolphin.txt', 'StartId': 73, 'EndId': 316 }, 'Ellen': { 'FileName': 'zhicheng20130808_22.xx_129-408_polarGT_Ellen.txt', 'StartId': 129, 'EndId': 408 } } #将GtParam里面的文件路径参数赋予load_GT函数,分析出Gt的每帧位置信息,存入GtData GtInfo = {} for key in GtParam: GtElem = GtParam[key] fname = FilePath + GtElem['FileName'] GtData = uti.get_obj_dict(fname) start_id = GtElem['StartId'] end_id = GtElem['EndId'] GtInfo[key] = {'GtData': GtData, 'StartId': start_id, 'EndId': end_id} return GtInfo
def show_precision_KF(): ''' Show the tracking results with Kalman Filter, and draw the precision curve. :return: ''' print('\nKalman Filter\'s Tracking Results') ObjNames = [] GtInfo = load_zhicheng_GT() for key in GtInfo: ObjNames.append(key) ObjNames.sort() res_path = '/Users/yizhou/code/MKCF_MAC_Python3.6/results/Res_KF/' scores_table = np.zeros( (3, 5)) #scores_table, contain 3 rows, for cle, pre_cle, pre_iou #containing 5 objects' tracked bounding box in KfResData KfResData = {} for i, key in enumerate(ObjNames): fname = res_path + key + '_KF_Tbbs.txt' ttData = uti.get_obj_dict(fname) KfResData.update({key: ttData}) #cle_fig = pylab.figure(figsize=(800/300, 600/300), dpi=300) #cle_ax = cle_fig.add_subplot(111) #pylab.xlabel('Frame', fontsize=20), pylab.ylabel('Location error(pixels)', fontsize=20) #cle_ax.grid(True) GtData = GtInfo[key]['GtData'] (evalue_reports, cle, IoU, pre_cle, pre_iou, fids) = show_tbb_precision(ttData, GtData, bplot=False) print(key) print(evalue_reports) #cle_ax.plot(fids, cle, label=key, linewidth=2.5, alpha=1) #cle_ax.set_title(key) scores_table[0, i] = cle scores_table[1, i] = pre_cle scores_table[2, i] = pre_iou return scores_table pylab.show()
def view_trackers(): tracker_names = ['KF', 'EOTRM', 'EOTGGIW', 'KCF', 'ASKCF', 'MKL', 'MKCF'] #colors[red, yellow, light blue, white, mud green, violite, light green] tracker_colors= [(0,0,255),(0,255,255), (239,200,148), (255,255,255), (24,115,84), (227,5,198), (97,241,115) ] target_names = ['ALice', 'Billy', 'Camen', 'Dolphin', 'Ellen'] res_path = '/Users/yizhou/code/MKCF_MAC_Python3.6/results/' ResData = {} #loading target's bounding box '*_tbbs.txt' file for 5 targets in 7 trackers. for tracker_name in tracker_names: TrackerResData = {} for target_name in target_names: ttData = {} fname = res_path + 'Res_' + tracker_name + '/' + target_name + '_' + tracker_name + '_Tbbs.txt' ttData = uti.get_obj_dict(fname) TrackerResData.update({target_name: ttData}) ResData.update({tracker_name: TrackerResData}) print('size of the results data in bytes: %d'% ResData.__sizeof__()) image_path = '/Users/yizhou/code/MKCF_MAC_Python3.6/sequences/gray/' video_path = '/Users/yizhou/code/MKCF_MAC_Python3.6/results/video/' # video = cv2.VideoWriter(video_path + '7trackers_5targets.mp4', cv2.VideoWriter_fourcc('a', 'v', 'c', '1'), 30, # (2048, 600)) video = cv2.VideoWriter(video_path + '7trackers_5targets.mp4', cv2.VideoWriter_fourcc('m', 'p', '4', 'v'), 30, (2048, 600)) img_files = os.listdir(image_path) img_files.sort() for file in img_files: img_file = os.path.join(image_path, file) if img_file.endswith('.png'): img = cv2.imread(img_file) id = int(file.split('.')[0]) if id > 409: break frame_id = 'frame %d' % id for i,tracker_name in enumerate(tracker_names): cv2.putText(img, frame_id, org=(20, 50), fontFace=cv2.FONT_HERSHEY_SIMPLEX,fontScale=1, color=(245,255,118),#show the tracker's color in rectangle and label. thickness=2, lineType=cv2.LINE_AA) img = cv2.rectangle(img, (30, 60+i*40), (80, 90+i*40), tracker_colors[i], 2) cv2.putText(img, tracker_name, org=(80, 90+i*40), fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=1, color=tracker_colors[i], thickness=2, lineType=cv2.LINE_AA) for target_name in target_names: if frame_id in ResData[tracker_name][target_name]: tbb = ResData[tracker_name][target_name][frame_id]['BoundingBox'] if len(tbb)>0: tp = (tbb[0], tbb[1]) br = (int(tbb[0]+tbb[2]), int(tbb[1]+tbb[3])) img = cv2.rectangle(img, tp, br, tracker_colors[i], 2) if(tracker_name == 'MKCF'): cv2.putText(img, target_name, org=tp, fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=1, color=(245,255,118), thickness=2, lineType=cv2.LINE_AA) video.write(img) cv2.imshow("Image", img) cv2.waitKey(1) video.release() cv2.destroyAllWindows()
def draw_precision_curve_MKCF(): ''' Draw the 5 precision results on a single plot :return: ''' ObjNames = [] GtInfo = load_zhicheng_GT() for key in GtInfo: ObjNames.append(key) ObjNames.sort() res_path = 'F:\\code\\Python\\visual_radar_tracker\\images\\zhicheng20130808_22.28\\Res_MKCF\\' trackers = ['3', '5', '8', '10', '15'] line_width = [1, 1.2, 1.5, 2, 2.5] line_style = ['o', '+', '--', '-.', '-'] alpha_vals = [0.3, 1, 1, 1, 1] cle_fig = pylab.figure() cle_ax = cle_fig.add_subplot(111) pylab.xlabel('Frame ids', fontsize=15), pylab.ylabel('Location error(pixels)', fontsize=15) precle_fig = pylab.figure() precle_ax = precle_fig.add_subplot(111) pylab.xlabel('Center Location error threshold', fontsize=15), pylab.ylabel('Precision', fontsize=15) iou_fig = pylab.figure() iou_ax = iou_fig.add_subplot(111) pylab.xlabel('Frame ids'), pylab.ylabel('Intersection Rate') preiou_fig = pylab.figure() preiou_ax = preiou_fig.add_subplot(111) pylab.xlabel('Intersection over union threshold'), pylab.ylabel( 'Precision') metric_matrix = np.zeros((5, 5, 3), dtype=np.float32) KfResData = {} for j, key in enumerate(ObjNames): for i, tname in enumerate(trackers): fname = res_path + '20180323_votepsr=10\\20180323_M=' + tname + '\\' + key + '_MKCF_Tbbs.txt' ttData = uti.get_obj_dict(fname) KfResData.update({key: ttData}) GtData = GtInfo[key]['GtData'] (evalue_reports, cle, IoU, pre_cle, pre_iou, fids) = show_tbb_precision(ttData, GtData, bplot=False) # the X_axis is the threashold and the y_axis is the precision. prune_cle = cle.copy() prune_cle[(prune_cle > 200)] = 200 cle_ax.plot(fids, prune_cle) precle_ax.plot(pre_cle, line_style[i], label=tname + '[%2.3f]' % np.mean(pre_cle), linewidth=2.5, alpha=alpha_vals[i]) precle_ax.legend(loc="lower right", fontsize=15) # set legend location if key == 'ALice': titl_str = 'Alice' #change the upper case to lower case else: titl_str = key precle_ax.set_title(titl_str) iou_ax.plot(fids, IoU) preiou_ax.plot(np.arange(1, 0, -0.01).tolist(), pre_iou, line_style[i], label=tname + '[%2.3f]' % np.mean(pre_iou), linewidth=2.5, alpha=alpha_vals[i]) preiou_ax.legend(loc="upper right", fontsize=15) # set legend location preiou_ax.set_title(titl_str) pylab.show(block=False) metric_matrix[i, j, 0] = np.mean(cle) metric_matrix[i, j, 1] = np.mean(pre_cle) metric_matrix[i, j, 2] = np.mean(pre_iou) print( '%s number of trackers %s of KMCF, mean cle %3.3f, mean pre_cle % 3.3f, mean pre_iou % 3.3f' % (key, tname, np.mean(cle), np.mean(pre_cle), np.mean(pre_iou))) # cle_fig.savefig('F:\\code\\Python\\visual_radar_tracker\\images\\paper\\exp\\'+titl_str+'_cle.pdf', format='pdf',dpi = 1200, bbox_inches='tight') # cle_fig.savefig('F:\\code\\Python\\visual_radar_tracker\\images\\paper\\exp\\'+titl_str+'_cle.png', format='png', dpi=1200, bbox_inches='tight') # precle_fig.savefig('F:\\code\\Python\\visual_radar_tracker\\images\\paper\\exp\\'+titl_str+'_precle.pdf', format='pdf',dpi = 1200, bbox_inches='tight') # precle_fig.savefig('F:\\code\\Python\\visual_radar_tracker\\images\\paper\\exp\\'+titl_str+'_precle.png', format='png', dpi=1200, bbox_inches='tight') # iou_fig.savefig('F:\\code\\Python\\visual_radar_tracker\\images\\paper\\exp\\'+titl_str+'_iou.pdf', format='pdf',dpi = 1200, bbox_inches='tight') # iou_fig.savefig('F:\\code\\Python\\visual_radar_tracker\\images\\paper\\exp\\'+titl_str+'_iou.png', format='png', dpi=1200, bbox_inches='tight') # preiou_fig.savefig('F:\\code\\Python\\visual_radar_tracker\\images\\paper\\exp\\'+titl_str+'_preiou.pdf', format='pdf',dpi = 1200, bbox_inches='tight') # preiou_fig.savefig('F:\\code\\Python\\visual_radar_tracker\\images\\paper\\exp\\'+titl_str+'_preiou.png', format='png', dpi=1200, bbox_inches='tight') cle_ax.clear() precle_ax.clear() iou_ax.clear() preiou_ax.clear() for m, tname in enumerate(trackers): mcle = metric_matrix[m, :, 0] print('%s average mean of cle in five objects %f' % (tname, np.mean(mcle))) print(mcle) mprecle = metric_matrix[m, :, 1] print('%s average mean of precle in five objects %f' % (tname, np.mean(mprecle))) print(mprecle) mpreiou = metric_matrix[m, :, 2] print('%s average mean of preiou in five objects %f' % (tname, np.mean(mpreiou))) print(mpreiou) #pylab.show() print('finish painting')
def draw_precision_curve(): ''' Draw the 5 precision results on a single plot :return: ''' ObjNames = [] GtInfo = load_zhicheng_GT() for key in GtInfo: ObjNames.append(key) ObjNames.sort() res_path = '/Users/yizhou/code/MKCF_MAC_Python3.6/results/' trackers = [ 'KF', 'EOTRM', 'EOTGGIW', 'KCF', 'ASKCF', 'MKL', 'MKCF', ] line_width = [1, 1.2, 1.3, 1.5, 2, 2, 2.5] line_style = ['o', '+', 'x', ':', '--', '-.', '-'] alpha_vals = [0.4, 1, 1, 1, 1, 1, 1] params = { 'axes.labelsize': '20', 'xtick.labelsize': '15', 'ytick.labelsize': '15', 'lines.linewidth': 2, 'legend.fontsize': '16', #'figure.figsize': '12, 9' # set figure size } pylab.rcParams.update(params) # set figure parameter KfResData = {} metric_matrix = np.zeros((7, 5, 3), dtype=np.float32) label_font = 20 legend_font = 14 for j, key in enumerate(ObjNames): cle_fig = pylab.figure(figsize=(9, 7), dpi=200) cle_ax = cle_fig.add_subplot(111) pylab.xlabel('Frame', fontsize=label_font), pylab.ylabel( 'Location error(pixels)', fontsize=label_font) cle_ax.grid(True) #figsize=(1200/200, 1000/200), dpi=200 precle_fig = pylab.figure(figsize=(9, 7), dpi=200) precle_ax = precle_fig.add_subplot(111) pylab.xlabel('Center location error threshold'), pylab.ylabel( 'Distance Precision') precle_ax.grid(True) # iou_fig = pylab.figure() # iou_ax = iou_fig.add_subplot(111) # pylab.xlabel('Frame'), pylab.ylabel('Intersection Rate') # iou_ax.grid(True) preiou_fig = pylab.figure(figsize=(9, 7), dpi=200) preiou_ax = preiou_fig.add_subplot(111) pylab.xlabel('Intersection over union threshold'), pylab.ylabel( 'Overlap Precision') preiou_ax.grid(True) for i, tname in enumerate(trackers): fname = res_path + 'Res_' + tname + '/' + key + '_' + tname + '_Tbbs.txt' ttData = uti.get_obj_dict(fname) KfResData.update({key: ttData}) GtData = GtInfo[key]['GtData'] (evalue_reports, cle, IoU, pre_cle, pre_iou, fids) = show_tbb_precision(ttData, GtData, bplot=False) print( '%s %s tracker, mean cle %f, mean pre_cle %f, mean pre_iou %f' % (key, tname, np.mean(cle), np.mean(pre_cle), np.mean(pre_iou))) metric_matrix[i, j, 0] = np.mean(cle) metric_matrix[i, j, 1] = np.mean(pre_cle) metric_matrix[i, j, 2] = np.mean(pre_iou) # the X_axis is the threashold and the y_axis is the precision. prune_cle = cle.copy() prune_cle[(prune_cle > 200)] = 200 if tname == 'MKCF': tname = 'MKCF' + '_10' cle_ax.plot(fids, prune_cle, line_style[i], label=tname, linewidth=2.5, alpha=alpha_vals[i]) if key == 'ALice': titl_str = 'Alice' #change the upper case to lower case else: titl_str = key cle_ax.set_ylim([0, 200]) cle_ax.set_title(titl_str, fontsize=label_font) cle_ax.legend(loc="upper left", fontsize=legend_font) #cle_ax.plot(fids, cle) precle_ax.plot(pre_cle, line_style[i], label=tname + '[%2.3f]' % np.mean(pre_cle), linewidth=2.5, alpha=alpha_vals[i]) precle_ax.legend(loc="upper right", fontsize=legend_font) # set legend location if key == 'ALice': titl_str = 'Alice' #change the upper case to lower case else: titl_str = key precle_ax.set_title(titl_str, fontsize=label_font) #iou_ax.plot(fids, IoU) preiou_ax.plot(np.arange(1, 0, -0.01).tolist(), pre_iou, line_style[i], label=tname + '[%2.3f]' % np.mean(pre_iou), linewidth=2.5, alpha=alpha_vals[i]) preiou_ax.legend(loc="upper right", fontsize=legend_font) # set legend location preiou_ax.set_title(titl_str, fontsize=label_font) #pylab.show(block=True) cle_fig.savefig('/Users/yizhou/code/MKCF_MAC_Python3.6/results/' + titl_str + '_cle.pdf', format='pdf', dpi=200, bbox_inches='tight') cle_fig.savefig('/Users/yizhou/code/MKCF_MAC_Python3.6/results/' + titl_str + '_cle.png', format='png', dpi=200, bbox_inches='tight') precle_fig.savefig('/Users/yizhou/code/MKCF_MAC_Python3.6/results/' + titl_str + '_precle.pdf', format='pdf', dpi=200, bbox_inches='tight') precle_fig.savefig('/Users/yizhou/code/MKCF_MAC_Python3.6/results/' + titl_str + '_precle.png', format='png', dpi=200, bbox_inches='tight') #iou_fig.savefig('/Users/yizhou/code/MKCF_MAC_Python3.6/results/'+titl_str+'_iou.pdf', format='pdf',dpi = 300, bbox_inches='tight') #iou_fig.savefig('/Users/yizhou/code/MKCF_MAC_Python3.6/results/'+titl_str+'_iou.png', format='png', dpi=300, bbox_inches='tight') preiou_fig.savefig('/Users/yizhou/code/MKCF_MAC_Python3.6/results/' + titl_str + '_preiou.pdf', format='pdf', dpi=200, bbox_inches='tight') preiou_fig.savefig('/Users/yizhou/code/MKCF_MAC_Python3.6/results/' + titl_str + '_preiou.png', format='png', dpi=200, bbox_inches='tight') #pylab.show(block=True) cle_fig.clf() precle_fig.clf() #iou_fig.close() preiou_fig.clf() #pylab.show() #print(metric_matrix) for m, tname in enumerate(trackers): mcle = metric_matrix[m, :, 0] print('%s\t average mean of cle in five objects %3.3f' % (tname, np.mean(mcle))) #print (mcle) for m, tname in enumerate(trackers): mprecle = metric_matrix[m, :, 1] print('%s\t average mean of precle in five objects %3.3f' % (tname, np.mean(mprecle))) #print (mprecle) for m, tname in enumerate(trackers): mpreiou = metric_matrix[m, :, 2] print('%s\t average mean of preiou in five objects %3.3f' % (tname, np.mean(mpreiou))) #print (mpreiou) print('cle of 7 trackers\n') print(metric_matrix[:, :, 0]) print('precle of 7 trackers\n') print(metric_matrix[:, :, 1]) print('preiou of 7 trackers\n') print(metric_matrix[:, :, 2]) print('finish painting')