function [fgMask, W, M, V] = detectForeground(I, learningRate, ...
                                              W, M, V, varargin)  %#codegen
% DETECTFOREGROUND helps ForegroundDetector object to redirect detectForeground
% calls to the matlab algorithm file that will build code using codegen.
% 
% Copyright 2009 The MathWorks, Inc.
% $Revision: 1.1.6.2 $  $Date: 2010/11/17 13:14:12 $

% Declare that the non-tunable parameters to be constant in order to generate 
% more optimzed code.    
eml_prefer_const(varargin);

% parse inputs
[classToUse, paramStruct] = parseInputs(varargin{:});

% call to detectForegroundAlgBuild
[fgMask, W, M, V] = detectForegroundAlgBuild(I, ...
            cast(learningRate, classToUse), ...
            cast(W, classToUse), cast(M, classToUse), cast(V, classToUse), ...
            classToUse, paramStruct);
end

function [classToUse, paramStruct] = parseInputs(varargin)

classToUse = varargin{1};
paramStruct.numGaussians           = cast(varargin{2}, classToUse);
paramStruct.varianceThreshold      = cast(varargin{3}, classToUse);
paramStruct.minimumBackgroundRatio = cast(varargin{4}, classToUse);
paramStruct.initialWeight          = cast(varargin{5}, classToUse);
paramStruct.initialVariance        = cast(varargin{6}, classToUse);
paramStruct.initialRank            = cast(varargin{7}, classToUse);
end
