From a87607e3ef6d30a2ccd8bd3b516fde4647dce16d Mon Sep 17 00:00:00 2001 From: Firat Kalaycilar Date: Wed, 12 Mar 2014 16:14:59 +0200 Subject: [PATCH] Fixed an issue with weight assignment causing the resulting GMM weights to be unsorted in BackgroundSubtractorMOG2 --- modules/video/src/bgfg_gaussmix2.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/video/src/bgfg_gaussmix2.cpp b/modules/video/src/bgfg_gaussmix2.cpp index 6bbb960..b14bc8e 100644 --- a/modules/video/src/bgfg_gaussmix2.cpp +++ b/modules/video/src/bgfg_gaussmix2.cpp @@ -319,7 +319,7 @@ struct MOG2Invoker : ParallelLoopBody for( int mode = 0; mode < nmodes; mode++, mean_m += nchannels ) { float weight = alpha1*gmm[mode].weight + prune;//need only weight if fit is found - + int swap_count = 0; //// //fit not found yet if( !fitsPDF ) @@ -384,6 +384,7 @@ struct MOG2Invoker : ParallelLoopBody if( weight < gmm[i-1].weight ) break; + swap_count++; //swap one up std::swap(gmm[i], gmm[i-1]); for( int c = 0; c < nchannels; c++ ) @@ -401,7 +402,7 @@ struct MOG2Invoker : ParallelLoopBody nmodes--; } - gmm[mode].weight = weight;//update weight by the calculated value + gmm[mode-swap_count].weight = weight;//update weight by the calculated value totalWeight += weight; } //go through all modes -- 2.7.4