Fixed windows build problems of BackgroundSubtractorGMG but code still need more work.
This commit is contained in:
parent
82cb2ab556
commit
a25c27ca05
@ -272,7 +272,7 @@ private:
|
|||||||
* Used internally to represent a single feature in a histogram.
|
* Used internally to represent a single feature in a histogram.
|
||||||
* Feature is a color and an associated likelihood (weight in the histogram).
|
* Feature is a color and an associated likelihood (weight in the histogram).
|
||||||
*/
|
*/
|
||||||
struct HistogramFeatureGMG
|
struct CV_EXPORTS HistogramFeatureGMG
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
@ -316,11 +316,11 @@ private:
|
|||||||
* Representation of the statistical model of a single pixel for use in the background subtraction
|
* Representation of the statistical model of a single pixel for use in the background subtraction
|
||||||
* algorithm.
|
* algorithm.
|
||||||
*/
|
*/
|
||||||
class PixelModelGMG
|
class CV_EXPORTS PixelModelGMG
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PixelModelGMG();
|
PixelModelGMG();
|
||||||
virtual ~PixelModelGMG();
|
~PixelModelGMG();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Incorporate the last observed feature into the statistical model.
|
* Incorporate the last observed feature into the statistical model.
|
||||||
@ -359,7 +359,7 @@ private:
|
|||||||
PixelModelGMG& operator *=(const float &rhs);
|
PixelModelGMG& operator *=(const float &rhs);
|
||||||
//friend class BackgroundSubtractorGMG;
|
//friend class BackgroundSubtractorGMG;
|
||||||
//friend class HistogramFeatureGMG;
|
//friend class HistogramFeatureGMG;
|
||||||
protected:
|
private:
|
||||||
size_t numFeatures; //!< number of features in histogram
|
size_t numFeatures; //!< number of features in histogram
|
||||||
size_t maxFeatures; //!< max allowable features in histogram
|
size_t maxFeatures; //!< max allowable features in histogram
|
||||||
std::list<HistogramFeatureGMG> histogram; //!< represents the histogram as a list of features
|
std::list<HistogramFeatureGMG> histogram; //!< represents the histogram as a list of features
|
||||||
@ -444,8 +444,6 @@ protected:
|
|||||||
Mat fgMaskImage; //!< Foreground mask image.
|
Mat fgMaskImage; //!< Foreground mask image.
|
||||||
};
|
};
|
||||||
|
|
||||||
bool initModule_BackgroundSubtractorGMG(void);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -237,14 +237,14 @@ void BackgroundSubtractorGMG::operator()(InputArray _image, OutputArray _fgmask,
|
|||||||
|
|
||||||
if (frameNum > numInitializationFrames) // typical operation
|
if (frameNum > numInitializationFrames) // typical operation
|
||||||
{
|
{
|
||||||
newFeature.likelihood = learningRate;
|
newFeature.likelihood = float(learningRate);
|
||||||
/*
|
/*
|
||||||
* (1) Query histogram to find posterior probability of feature under model.
|
* (1) Query histogram to find posterior probability of feature under model.
|
||||||
*/
|
*/
|
||||||
float likelihood = (float)pixel->getLikelihood(newFeature);
|
float likelihood = (float)pixel->getLikelihood(newFeature);
|
||||||
|
|
||||||
// see Godbehere, Matsukawa, Goldberg (2012) for reasoning behind this implementation of Bayes rule
|
// 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
|
* (2) feed posterior probability into the posterior image
|
||||||
@ -252,7 +252,7 @@ void BackgroundSubtractorGMG::operator()(InputArray _image, OutputArray _fgmask,
|
|||||||
int row,col;
|
int row,col;
|
||||||
col = i%imWidth;
|
col = i%imWidth;
|
||||||
row = (i-col)/imWidth;
|
row = (i-col)/imWidth;
|
||||||
posteriorImage.at<float>(row,col) = (1.0-posterior);
|
posteriorImage.at<float>(row,col) = (1.0f-posterior);
|
||||||
}
|
}
|
||||||
pixel->setLastObservedFeature(newFeature);
|
pixel->setLastObservedFeature(newFeature);
|
||||||
}
|
}
|
||||||
@ -393,8 +393,8 @@ void BackgroundSubtractorGMG::PixelModelGMG::insertFeature(double learningRate)
|
|||||||
* (3) Check if feature already represented. If so, simply add.
|
* (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.
|
* (4) If feature is not represented, remove old feature, distribute weight evenly among existing features, add in new feature.
|
||||||
*/
|
*/
|
||||||
*this *= (1.0-learningRate);
|
*this *= float(1.0-learningRate);
|
||||||
lastObservedFeature.likelihood = learningRate;
|
lastObservedFeature.likelihood = float(learningRate);
|
||||||
|
|
||||||
for (feature = histogram.begin(); feature != last_feature; ++feature)
|
for (feature = histogram.begin(); feature != last_feature; ++feature)
|
||||||
{
|
{
|
||||||
@ -453,7 +453,7 @@ void BackgroundSubtractorGMG::PixelModelGMG::normalizeHistogram()
|
|||||||
for (feature = histogram.begin(); feature != last_feature; ++feature)
|
for (feature = histogram.begin(); feature != last_feature; ++feature)
|
||||||
{
|
{
|
||||||
if (total != 0.0)
|
if (total != 0.0)
|
||||||
feature->likelihood /= total;
|
feature->likelihood = float(feature->likelihood / total);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user