Update bgfg_gaussmix2.cpp to avoid divide by zero cases.

pull/8342/head
Matthias Grundmann 8 years ago committed by GitHub
parent 8ef23d64a1
commit 0a1767a6b5
  1. 16
      modules/video/src/bgfg_gaussmix2.cpp

@ -693,11 +693,16 @@ public:
//go through all modes //go through all modes
////// //////
//renormalize weights // Renormalize weights. In the special case that the pixel does
totalWeight = 1.f/totalWeight; // 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++ ) for( int mode = 0; mode < nmodes; mode++ )
{ {
gmm[mode].weight *= totalWeight; gmm[mode].weight *= invWeight;
} }
//make new mode if needed and exit //make new mode if needed and exit
@ -900,7 +905,10 @@ void BackgroundSubtractorMOG2Impl::getBackgroundImage_intern(OutputArray backgro
if(totalWeight > backgroundRatio) if(totalWeight > backgroundRatio)
break; 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); meanBackground.at<Vec<T,CN> >(row, col) = Vec<T,CN>(meanVal * invWeight);
meanVal = 0.f; meanVal = 0.f;

Loading…
Cancel
Save