Update bgfg_gaussmix2.cpp to avoid divide by zero cases.
This commit is contained in:
parent
8ef23d64a1
commit
0a1767a6b5
@ -693,11 +693,16 @@ public:
|
||||
//go through all modes
|
||||
//////
|
||||
|
||||
//renormalize weights
|
||||
totalWeight = 1.f/totalWeight;
|
||||
// Renormalize weights. In the special case that the pixel does
|
||||
// not agree with any modes, set weights to zero (a new mode will be added below).
|
||||
float invWeight = 0.f;
|
||||
if (fabs(totalWeight) > 1e-12f) {
|
||||
invWeight = 1.f/totalWeight;
|
||||
}
|
||||
|
||||
for( int mode = 0; mode < nmodes; mode++ )
|
||||
{
|
||||
gmm[mode].weight *= totalWeight;
|
||||
gmm[mode].weight *= invWeight;
|
||||
}
|
||||
|
||||
//make new mode if needed and exit
|
||||
@ -900,7 +905,10 @@ void BackgroundSubtractorMOG2Impl::getBackgroundImage_intern(OutputArray backgro
|
||||
if(totalWeight > backgroundRatio)
|
||||
break;
|
||||
}
|
||||
float invWeight = 1.f/totalWeight;
|
||||
float invWeight = 0.f;
|
||||
if (fabs(totalWeight) > 1e-12f) {
|
||||
invWeight = 1.f/totalWeight;
|
||||
}
|
||||
|
||||
meanBackground.at<Vec<T,CN> >(row, col) = Vec<T,CN>(meanVal * invWeight);
|
||||
meanVal = 0.f;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user