提交 2409924d 编写于 作者: V Vadim Pisarevsky

Merge pull request #8342 from grundman:patch-1

...@@ -693,11 +693,16 @@ public: ...@@ -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 (std::abs(totalWeight) > FLT_EPSILON) {
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 ...@@ -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 (std::abs(totalWeight) > FLT_EPSILON) {
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册