function draw_precision_plot (tracker, videos, gt, r , db_vids)

load('cc');
threshold_steps = 50;

fprintf('Calculating CPE [')
k = 0;
for vid = 1:length(videos)
    fprintf('-')
    seq_len = r{vid,1}.seq_len;
    
    for fr = 1:seq_len
        g = gt{vid}(fr,:);
        k = k+1;
        
        for tr = 1:length(tracker)
            cpe(k,tr) = cpe_score(r{vid,tr}.res(fr,:) , g);
        end
    end
end
disp(']')


for to = 0:threshold_steps
    for tr = 1:length(tracker)
        s(tr,to+1) = sum(cpe(:,tr) <= to)/k;
    end
end

auc = sum(s,2)/threshold_steps;

[~,trackers_sorted_indices] = sort(auc,'descend');

figure_handle = figure;
set(gcf,'Color','w');
hold on;

X = 0:threshold_steps-1;

leg = cell(1,length(tracker));
for i = 1:length(tracker)
    tr = trackers_sorted_indices(i);
    
    if (strcmp(tracker{tr},'STRUCK'))
        txt = 'STRK';
    else
        txt = tracker{tr};
    end
    leg{i} = [txt sprintf(' (%0.2f)', auc(tr))];
    Yi = s(tr,2:end);
    if (i > 6)
        pl = plot(X,Yi,'Color',cc(i,:), 'LineWidth', 4 , 'LineStyle', ':');
    else
        pl = plot(X,Yi,'Color',cc(i,:), 'LineWidth', 4);
    end
end

%bring to top
my_tracker = 2; %%%%%
Yi = s(trackers_sorted_indices(my_tracker),2:end);
pl = plot(X,Yi,'Color',cc(my_tracker,:), 'LineWidth', 4);

grid on
legend(leg,'Location','SouthEast');
xlim([0 threshold_steps]);
ylim([0 1.01]);
xlabel('Location Error Threshold');
ylabel('Precision');
 
%set(gcf,'Position',[0,0,1,1]);
ax= gca;
ax.YTick = [0 0.2 0.4 0.6 0.8 1];
set(gca, 'Units', 'pixels', 'Position', [20, 20, 300, 150]);
ax.Position = [75,50, 400, 200];
%yticks([0 0.2 0.4 0.6 0.8 1])
box on
saveas(gcf, ['vis//precision_plot_' db_vids], 'png') %Save figure
saveas(gcf, ['vis//precision_plot_' db_vids], 'pdf') %Save figure

img = imread(['vis//precision_plot_' db_vids '.png']);
img2 = img(65:end-35,86:end-100,:);
imwrite(img2,['vis//precision_plot_' db_vids '.png']);




end

function ce = cpe_score (b1 , b2)

b1 = double(b1);
b2 = double(b2);

dx = (b1(1) + b1(3)/2) - (b2(1) + b2(3)/2);
dy = (b1(2) + b2(4)/2) - (b2(2) + b2(4)/2);
ce = sqrt (dx*dx + dy*dy);

end

