%SCRIPT_ToyotaDetectObjectsInTestImages
%
%intent:  detect object named objname in images 1:300 and record in
%/cbcl/scratch01/bileschi/PrecomputedFeatures/StreetScenes/AppearanceDetector/ToyotaAppObjDet/objname
%clear all;
%objname = 'car';


cmd = sprintf('load /cbcl/scratch01/bileschi/TextureRec/AppModel_%s.mat',objname);
eval(cmd);
cmd = sprintf('Model{1} = AppModel_%s',objname);
eval(cmd);
SaveRoot = sprintf('/cbcl/scratch01/bileschi/PrecomputedFeatures/StreetScenes/AppearanceDetector/ToyotaAppObjDet/%s',objname);
seedrand;
load CAFileList_FilterSS;
p = randperm(300);
nDetectors = 1;
for i = p
   fprintf('beginning detection on %d\n',i);
   savename = fullfile(SaveRoot,sprintf('ToyotaDet_%.5d.mat',i));
   if(exist(savename))
     continue;
   end
   im = imread(CAfilelist{i}.imagename);
   im = rgb2gray(im);
   im = imresize(im,[480 640]);
   superYPyr = ToyotaFeature_ApplyModelToImage_AllScales(im,Model,16,1/(2).^(1/4),1);
   for iDet = 1:nDetectors
     nScales = length(superYPyr);
     for i = 1:nScales
       YPyr{i} = superYPyr{i}{iDet};
     end
     [yComb(:,:,iDet),caYLayr{iDet}] = CombineToyotaDetectionOutputs(YPyr);
   end
   DL = PeakDetection_LocalSuppression(caYLayr);
   
   save(savename,'YPyr','DL');
end   
