function [scores, labels] = calculateROC()
scores = []; labels = [];
files = dir('pos\*.png');
for k=1:length(files)
name = files(k).name;
gt_file = fopen(strcat('..\gt_bbox\' , substring(name, 0, length(name)-4) , 'txt'));
gt = fscanf(gt_file, ' %d %d %d %d ', [4,Inf]);
gt = gt';
load(strcat('pos\' , substring(name, 0, length(name)-5) , '_boxes.mat'));
for i=1:size(rawr,1)
maxPascal = 0;
for j=1:size(gt,1)
pascal = pascalScore(rawr(i,:) , gt(j,:));
maxPascal = max(maxPascal, pascal);
end
label = 0;
if (maxPascal > 0.5)
label = 1;
end
labels = [labels; label];
scores = [scores; raws(i)];
end
fclose(gt_file);
end
files = dir('neg\*.mat');
for k=1:length(files)
name = files(k).name;
load(strcat('neg\' , name));
for i=1:size(rawr,1)
labels = [labels; 0];
scores = [scores; raws(i)];
end
end
[X,Y] = perfcurve(labels,scores,1);
plot(X,Y);
end
function score = pascalScore(rawr, gt)
raw_ul = [rawr(1), rawr(2)];
raw_lr = [rawr(1)+rawr(3), rawr(2)+rawr(4)];
gt_ul = [gt(1), gt(2)];
gt_lr = [gt(3), gt(4)];
raw_area = rawr(3)*rawr(4);
gt_area = (gt(3) - gt(1))*(gt(4) - gt(2));
intersection_ul = [max(raw_ul(1), gt_ul(1)) , max(raw_ul(2), gt_ul(2))];
intersection_lr = [min(raw_lr(1), gt_lr(1)) , min(raw_lr(2), gt_lr(2))];
intersection_width = intersection_lr(1) - intersection_ul(1);
intersection_height = intersection_lr(2) - intersection_ul(2);
intersection_area = 0;
label = 0;
if (intersection_width > 0 && intersection_height > 0)
intersection_area = intersection_width * intersection_height;
end
union_area = raw_area + gt_area - intersection_area;
score = intersection_area/union_area;
end