function draw_cpe_plot (tracker, videos, gt, r)

load('cc');
axis tight
set(gcf,'Position',[100,100,1400,800]);


fprintf('Calculating Centers [')
k = 0;

for vid = 1:length(videos)
    fprintf('-')
    seq_len = r{vid,1}.seq_len;
    
    clear cd
    for fr = 1:seq_len
        g = gt{vid}(fr,:);
        k = k+1;

        for tr = 1:length(tracker)
            cd(tr,fr) = center_distance(r{vid,tr}.res(fr,:) , g);
        end
        
    end
    
    clf
    hold on
    auc = sum(cd,2)/k;
    cpe(vid,:) = auc;
    [~,trackers_sorted_indices] = sort(auc,'ascend');
    X = 1:seq_len;
    
    for i = 1:length(tracker)
        tr = trackers_sorted_indices(i);
        leg{i} = [tracker{tr} sprintf(' (%0.2f)', auc(tr))];
        
        clear Yi
        Yi = cd(tr,:);
        
        if (i <= 5)
            pl = plot(X,Yi,'Color',cc(i,:), 'LineWidth', 2);
        else
            pl = plot(X,Yi,'Color',cc(i,:), 'LineWidth', 1);
        end
    end
    legend(leg,'Location','NorthEastOutside');
    xlim([0 min(seq_len,100)]);
    ylim([0 50]);
    xlabel('Frame #');
    ylabel('CPE (pixels)');
    box on
    saveas(gcf, ['vis//cpe//cpe_plot_' videos{vid}], 'png') %Save figure
end
disp(']')

clf
hold on
for tr = 1:length(tracker)
    pl = plot(1:length(videos),cpe(:,tr),'Color',cc(tr,:));
end
    
xlabel('Videos');
ylabel('CPE (pixels)');
ylim([0,50]);
xlim([0,length(videos)+1])
set(gca,'YScale','log');
rotateXLabels(gca,90)
set(gca,'xTick',1:length(videos),'xTickLabel',videos)
set(gcf,'Position',[100,100,2000,800]);
print(gcf,'vis//cpe_plot.png','-dpng')




