%SCRIPT_BuildTrueDetectionArray
%
%intent: to be input to PrecisionRecallOfDetectionArrays
%for EzContext ICCV 2005

load /cbcl/scratch01/bileschi/TextureRec/First_Train_Indicies
Test = setdiff(1:300,TTS.Train);
DA250_bicycle = [];
DA250_car = [];
DA250_pedestrian = [];
load CAFileList_FilterSS
for i = Test
  fprintf('.');
  ol = QReadOList2(CAfilelist{i}.olistname);
  if(isfield(ol,'bicycle'))
     for j = 1:length(ol.bicycle)
       bbox = poly2bbox(ol.bicycle{j});
       bbox = bboxEnforceAspectRatio(bbox,[1 1],'bottom');
       x = mean([bbox(1),bbox(1)+bbox(3)+.5]);
       y = mean([bbox(2),bbox(2)+bbox(4)+.5]);
       DA250_bicycle(1,(end+1)) = i;
       DA250_bicycle(2,end) = 1;
       DA250_bicycle(3,end) = x;
       DA250_bicycle(4,end) = y;
       DA250_bicycle(5,end) = bbox(3) / 2;
     end
  end
  if(isfield(ol,'car'))
     for j = 1:length(ol.car)
       bbox = poly2bbox(ol.car{j});
       bbox = bboxEnforceAspectRatio(bbox,[1 1],'bottom');
       x = mean([bbox(1),bbox(1)+bbox(3)+.5]);
       y = mean([bbox(2),bbox(2)+bbox(4)+.5]);
       DA250_car(1,(end+1)) = i;
       DA250_car(2,end) = 1;
       DA250_car(3,end) = x;
       DA250_car(4,end) = y;
       DA250_car(5,end) = bbox(3) / 2;
     end
  end
  if(isfield(ol,'pedestrian'))
     for j = 1:length(ol.pedestrian)
       bbox = poly2bbox(ol.pedestrian{j});
       bbox = bboxEnforceAspectRatio(bbox,[1 1],'bottom');
       x = mean([bbox(1),bbox(1)+bbox(3)+.5]);
       y = mean([bbox(2),bbox(2)+bbox(4)+.5]);
       DA250_pedestrian(1,(end+1)) = i;
       DA250_pedestrian(2,end) = 1;
       DA250_pedestrian(3,end) = x;
       DA250_pedestrian(4,end) = y;
       DA250_pedestrian(5,end) = bbox(3) / 2;
     end
  end
end
save('DA250','DA250_pedestrian','DA250_car','DA250_bicycle');  
       
       
       
%d(1) is CAidx, d(2) is confidence, d(3) is x coord, d(4) is y coord, d(5) is radius of detection field

  
  