本文主要是介绍目标跟踪CLE绘图 OTB数据跟踪绘图 mat文件txt文件 相互转换,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
跟踪 OTB数据集 绘图
文章主要3个内容
1.txt文件数据--》转换 mat文件 (在matlab上画图)
2.mat文件--》txt文件 画CLE图
3.CLE画图代码 跟踪目标中心距离误差
1.txt文件转换成 mat文件
把python跟踪得到txt数据集 转换成 matlab使用mat文件 画图
matlab程序代码
clear;clc;
close all;
% txt路径
txt_path = 'D:\atom\default_000\';
% mat路径
mat_path = 'D:\atom\default\';
mkdir(mat_path);
% 跟踪器名字
tracker='ATOM';txt_files = dir([txt_path '*.txt']);txt_files={txt_files.name};for i=1:numel(txt_files)region=csvread([txt_path txt_files{i}]);results{1}.type = 'rect';results{1}.res = region;results{1}.len = length(region);videoname=txt_files{i};videoname=videoname(1:length(videoname)-4);save([mat_path videoname '_' tracker '.mat'], 'results');end
把得到mat文件放入OTB下面results文件目录下 perfplot.m一下
2.mat文件转换txt文件
matlab程序代码
clear;clc;
close all;
% txt路径
txt_path = 'D:\liux_code\deep_sort_yolov3\results\txtpsps1\';
% mat路径
%mat_path = 'D:\liux_code\deep_sort_yolov3\results\mat\';
mat_path = 'D:\OTB\tracker_benchmark_v1\results\results_OPE_CVPR12\';mkdir(txt_path);
% 跟踪器名字
tracker='bacf';mat_files = dir([mat_path '*.mat']);mat_files={mat_files.name};for i=1:numel(mat_files)region=load([mat_path mat_files{i}]);results= region.results{1};results=results.res;
% results{1}.res = region;
% results{1}.len = length(region);videoname=mat_files{i};videoname=videoname(1:length(videoname)-4);%fid = fopen([txt_path videoname '_' tracker '.txt'] ,'wt');fid = fopen([txt_path videoname '.txt'] ,'wt');[M,N]=size(results);for m =1:Mfor n= 1:Nif n ==4 fprintf(fid,'%d',results(m,n));elsefprintf(fid,'%d\t',results(m,n));endendfprintf(fid,'\n');endfclose(fid);%save([txt_path videoname '_' tracker '.txt' ], 'results','-ASCII', '-tabs');%'-ASCII -double'end
TRE只需要转换第一栏第一个数据集代码
转换后这样算正常
如果出现这样的 说明你的mat文件 出现问题 在跟踪程序里需要修改
在跟踪程序中(matlab 相关滤波跟踪)
寻找box 跟踪框
box = [floor(pos([2,1])) - floor(target_sz([2,1])/2), floor(target_sz([2,1]))];rect_results(frame,:)=box;%visualization
floor是取实数 代码更改成类似的 只要跟踪结果mat文件 都是实数就可以
得到txt跟踪数据集 我们来画CLE图像
3.CLE绘图
python程序代码
from pylab import *
import math
import matplotlib.pyplot as plt
import numpyimport os# calculate the Pre,CLE is CENTOR LOCATION ERROR,and it is a list
def calculatePre(CLE):res = []for thresh in range(1, 100):tmp = numpy.array(CLE) # get the temporary variabletmp[tmp <= thresh] = 1tmp[tmp > thresh] = 0num = sum(tmp)rate = float(num) / float(tmp.size)res.append(rate)return res# 定义画中心位置误差图像的函数
def drawCLE(title, ResGroundLines, ResKcfLines, ResKcfILines,ResKcfILines2,ResKcfILines3):CleKcf = []list1 =['Car4','CarScale','Couple', 'Crossing', 'Faceocc1','Girl','Singer1','Subway','Walking','Walking2','Woman','Sylvester','Jogging-1',]# 读取groundtruth_rect里数据 CleKcfI = [] # 有的 , 隔开 有的是空格 隔开 CleKcfI2 = []CleKcfI3 = []num_of_frame = len(ResGroundLines) # 帧数,去掉表头和最后一帧(主要是我结果好像少写了一帧)for index in range(1, (num_of_frame )):# 每一行拿出来,第一列是分别是 frame x y width height,分离出来并转换成数字if title in list1:GroundPos = (ResGroundLines[index]).split('\t')else:GroundPos = (ResGroundLines[index]).split(',')#KcfPos = (ResKcfLines[index]).split('\t')KcfIPos = (ResKcfILines[index]).split('\t')# KcfIPos = KcfIPos.replace('\n')KcfIPos2 = (ResKcfILines2[index]).split('\t')KcfIPos3 = (ResKcfILines3[index]).split('\t')GroundPos = list(map(int, GroundPos))#KcfPos = list(map(int, KcfPos))KcfIPos = list(map(int, KcfIPos))KcfIPos2 = list(map(int, KcfIPos2))KcfIPos3 = list(map(int, KcfIPos3))# 提取中心位置P_G = [GroundPos[0] + GroundPos[2] / 2, GroundPos[1] + GroundPos[3] / 2]#P_K = [KcfPos[0] + KcfPos[2] / 2, KcfPos[2] + KcfPos[3] / 2]P_KI = [KcfIPos[0] + KcfIPos[2] / 2, KcfIPos[2] + KcfIPos[3] / 2]P_KI2 = [KcfIPos2[0] + KcfIPos2[2] / 2, KcfIPos2[2] + KcfIPos2[3] / 2]P_KI3 = [KcfIPos3[0] + KcfIPos3[2] / 2, KcfIPos3[2] + KcfIPos3[3] / 2]#CLE_KCF = math.sqrt((P_K[0] - P_G[0]) ** 2 + (P_K[1] - P_G[1]) ** 2)CLE_KCF_I = math.sqrt((P_KI[0] - P_G[0]) ** 2 + (P_KI[1] - P_G[1]) ** 2)CLE_KCF_I2 = math.sqrt((P_KI2[0] - P_G[0]) ** 2 + (P_KI2[1] - P_G[1]) ** 2)CLE_KCF_I3 = math.sqrt((P_KI3[0] - P_G[0]) ** 2 + (P_KI3[1] - P_G[1]) ** 2)#CleKcf.append(CLE_KCF)CleKcfI.append(CLE_KCF_I)CleKcfI2.append(CLE_KCF_I2)CleKcfI3.append(CLE_KCF_I3)plt.figure() # CLE CENTOR LOCATION ERRORplt.title(title + "CLE Plot")#plt.plot(CleKcf, color='red', label="atom")#####################################################plt.plot(CleKcfI, color='black', label="samf")#plt.plot(CleKcfI2, color='red', label="samfpaceauto")plt.plot(CleKcfI3, color='red', label="our")mpl.rcParams['font.sans-serif'] = ['SimHei']plt.xlabel('帧数',fontsize =13)plt.ylabel('中心位置误差',fontsize =13)plt.legend()# 保存图片plt.savefig("results//samfpsps1//" + title + ".png", dpi=600)# PreKcf = calculatePre(CleKcf)# PreKcfI = calculatePre(CleKcfI)## plt.figure() # PRECISION PERCENT# plt.title(title + "Precision Plot")# plt.plot(PreKcf, color='red', label='atom')# plt.plot(PreKcfI, color='blue', label="bacf")# plt.legend()# plt.savefig("results//" + title + "_Pre.png", dpi=600)# 主函数
# for target in lines:# target有个回车,这里需要把这个回车给去掉,然后下面把当前target下的文件读取# AveFpsKcf = open(path + target[:-1] + ave_fps_kcf)# AveFpsKcfI = open(path + target[:-1] + ave_fps_kcf_inter)
#s = "basketball"
a = ['Jogging-1','Basketball', 'Bolt', 'Boy', 'Car4', 'CarDark', 'CarScale','Coke', 'Couple', 'Crossing', 'David2', 'David3', 'David', 'Deer','Dog1', 'Doll', 'Dudek', 'Faceocc1', 'Faceocc2', 'Fish', 'Fleetface','Football', 'Football1', 'Freeman1', 'Freeman3', 'Freeman4', 'Girl','Ironman', 'Jumping', 'Lemming', 'Liquor', 'Matrix','Mhyang', 'MotorRolling', 'MountainBike', 'Shaking', 'Singer1','Singer2', 'Skating1', 'Skiing', 'Soccer','Subway', 'Suv','Sylvester','Tiger2', 'Trellis','Walking', 'Walking2', 'Woman'] #'Jogging-1''Tiger1',path = "results//"
otbpath = "D://OTB//OTB100//"
txtfile = "txtpsps1//"
#os.makedirs(r"results//samfpsps1" )
for s in a:if s =='Jogging-1':res_ground = otbpath+'jogging'+"./groundtruth_rect.1.txt"else:res_ground = otbpath + s + "./groundtruth_rect.txt"res_bacfapceauto = "./results/" + txtfile + s +"_samfapceauto.txt"res_bacf = "./results/"+txtfile + s +"_samf.txt"res_bacfapce = "./results/" +txtfile + s +"_samfpsps1.txt"ResGround = open(res_ground)#Resatom= open(res_atom)Resbacfauto = open(res_bacfapceauto)Resbacf = open(res_bacf)Resbacfapce = open(res_bacfapce)# AveFpsKcfLines = AveFpsKcf.readlines()# AveFpsKcfILines = AveFpsKcfI.readlines()ResGroundLines = ResGround.readlines()#ResKcfLines = Resatom.readlines()ResKcfLines = 0ResKcfILines = Resbacf.readlines()ResKcfILines2 = Resbacfauto.readlines()ResKcfILines3 = Resbacfapce.readlines()target = sdrawCLE(target, ResGroundLines, ResKcfLines, ResKcfILines,ResKcfILines2,ResKcfILines3)
这篇关于目标跟踪CLE绘图 OTB数据跟踪绘图 mat文件txt文件 相互转换的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!