function LearnAdaboostTemplate(category)
% LearnAdaboostTemplate - Learns an adaboost "template", i.e. strong classifier.
%

disp(sprintf('Learning adaboost template for %s.',category));

rootFolder = pwd;

%% find the corresponding template parameter
load template_params
nT = length(templateParameters);
for iT = 1:nT
    if strcmp(templateParameters(iT).category,category) == 1
        templateSize = templateParameters(iT).templateSize;
        nsketch = templateParameters(iT).nElement_adaboost;
        GaborScale = templateParameters(iT).GaborScale;
        break;
    end
end

%% collect the paths of positive training images
imageNames = [];
imageNames = [imageNames; dir(sprintf('%s/image/%s/*.jpg',rootFolder,category))];
imageNames = [imageNames; dir(sprintf('%s/image/%s/*.bmp',rootFolder,category))];
imageNames = [imageNames; dir(sprintf('%s/image/%s/*.png',rootFolder,category))];
n = numel(imageNames);
posImagePaths = cell(n,1);
for i = 1:n
    posImagePaths{i} = sprintf('%s/image/%s/%s', rootFolder, category, imageNames(i).name);
end

%% collect the paths of negative training images
imageNames = [];
negFolderName = sprintf('neg_%d_%d',templateSize(1),templateSize(2));
imageNames = [imageNames; dir(sprintf('%s/image/%s/*.jpg',rootFolder,negFolderName))];
imageNames = [imageNames; dir(sprintf('%s/image/%s/*.bmp',rootFolder,negFolderName))];
imageNames = [imageNames; dir(sprintf('%s/image/%s/*.png',rootFolder,negFolderName))];
n = numel(imageNames);
negImagePaths = cell(n,1);
for i = 1:n
    negImagePaths{i} = sprintf('%s/image/%s/%s', rootFolder, negFolderName, imageNames(i).name);
end

%% start learning
cd adaboost

adaboostLearn(category, posImagePaths, negImagePaths, nsketch, templateSize, GaborScale);
cd ..

