Fixed windows build problems of BackgroundSubtractorGMG but code still need more work.

This commit is contained in:
Andrey Kamaev 2012-06-28 20:42:26 +00:00
parent 82cb2ab556
commit a25c27ca05
3 changed files with 559 additions and 561 deletions

View File

@ -272,7 +272,7 @@ private:
* Used internally to represent a single feature in a histogram.
* Feature is a color and an associated likelihood (weight in the histogram).
*/
struct HistogramFeatureGMG
struct CV_EXPORTS HistogramFeatureGMG
{
/**
* Default constructor.
@ -316,11 +316,11 @@ private:
* Representation of the statistical model of a single pixel for use in the background subtraction
* algorithm.
*/
class PixelModelGMG
class CV_EXPORTS PixelModelGMG
{
public:
PixelModelGMG();
virtual ~PixelModelGMG();
~PixelModelGMG();
/**
* Incorporate the last observed feature into the statistical model.
@ -359,7 +359,7 @@ private:
PixelModelGMG& operator *=(const float &rhs);
//friend class BackgroundSubtractorGMG;
//friend class HistogramFeatureGMG;
protected:
private:
size_t numFeatures; //!< number of features in histogram
size_t maxFeatures; //!< max allowable features in histogram
std::list<HistogramFeatureGMG> histogram; //!< represents the histogram as a list of features
@ -444,8 +444,6 @@ protected:
Mat fgMaskImage; //!< Foreground mask image.
};
bool initModule_BackgroundSubtractorGMG(void);
}
#endif

View File

@ -237,14 +237,14 @@ void BackgroundSubtractorGMG::operator()(InputArray _image, OutputArray _fgmask,
if (frameNum > numInitializationFrames) // typical operation
{
newFeature.likelihood = learningRate;
newFeature.likelihood = float(learningRate);
/*
* (1) Query histogram to find posterior probability of feature under model.
*/
float likelihood = (float)pixel->getLikelihood(newFeature);
// see Godbehere, Matsukawa, Goldberg (2012) for reasoning behind this implementation of Bayes rule
float posterior = (likelihood*backgroundPrior)/(likelihood*backgroundPrior+(1-likelihood)*(1-backgroundPrior));
float posterior = float((likelihood*backgroundPrior)/(likelihood*backgroundPrior+(1-likelihood)*(1-backgroundPrior)));
/*
* (2) feed posterior probability into the posterior image
@ -252,7 +252,7 @@ void BackgroundSubtractorGMG::operator()(InputArray _image, OutputArray _fgmask,
int row,col;
col = i%imWidth;
row = (i-col)/imWidth;
posteriorImage.at<float>(row,col) = (1.0-posterior);
posteriorImage.at<float>(row,col) = (1.0f-posterior);
}
pixel->setLastObservedFeature(newFeature);
}
@ -393,8 +393,8 @@ void BackgroundSubtractorGMG::PixelModelGMG::insertFeature(double learningRate)
* (3) Check if feature already represented. If so, simply add.
* (4) If feature is not represented, remove old feature, distribute weight evenly among existing features, add in new feature.
*/
*this *= (1.0-learningRate);
lastObservedFeature.likelihood = learningRate;
*this *= float(1.0-learningRate);
lastObservedFeature.likelihood = float(learningRate);
for (feature = histogram.begin(); feature != last_feature; ++feature)
{
@ -453,7 +453,7 @@ void BackgroundSubtractorGMG::PixelModelGMG::normalizeHistogram()
for (feature = histogram.begin(); feature != last_feature; ++feature)
{
if (total != 0.0)
feature->likelihood /= total;
feature->likelihood = float(feature->likelihood / total);
}
}