fixed number of update operation

This commit is contained in:
Vladislav Vinogradov
2012-08-09 12:28:30 +04:00
parent 9ec96597cd
commit da38a95de6
2 changed files with 26 additions and 23 deletions

View File

@@ -181,32 +181,18 @@ namespace cv { namespace gpu { namespace device {
int nfeatures = nfeatures_(y, x);
bool isForeground = false;
if (frameNum > c_numInitializationFrames)
if (frameNum >= c_numInitializationFrames)
{
// typical operation
const float weight = findFeature(newFeatureColor, colors_, weights_, x, y, nfeatures);
// see Godbehere, Matsukawa, Goldberg (2012) for reasoning behind this implementation of Bayes rule
const float posterior = (weight * c_backgroundPrior) / (weight * c_backgroundPrior + (1.0f - weight) * (1.0f - c_backgroundPrior));
isForeground = ((1.0f - posterior) > c_decisionThreshold);
}
const bool isForeground = ((1.0f - posterior) > c_decisionThreshold);
fgmask(y, x) = (uchar)(-isForeground);
fgmask(y, x) = (uchar)(-isForeground);
if (frameNum <= c_numInitializationFrames + 1)
{
// training-mode update
insertFeature(newFeatureColor, 1.0f, colors_, weights_, x, y, nfeatures);
if (frameNum == c_numInitializationFrames + 1)
normalizeHistogram(weights_, x, y, nfeatures);
}
else
{
// update histogram.
for (int i = 0, fy = y; i < nfeatures; ++i, fy += c_height)
@@ -220,6 +206,15 @@ namespace cv { namespace gpu { namespace device {
nfeatures_(y, x) = nfeatures;
}
}
else
{
// training-mode update
insertFeature(newFeatureColor, 1.0f, colors_, weights_, x, y, nfeatures);
if (frameNum == c_numInitializationFrames - 1)
normalizeHistogram(weights_, x, y, nfeatures);
}
}
template <typename SrcT>