From 78de75397e512a3fb4b9aad677ebc4c1472fa9cc Mon Sep 17 00:00:00 2001 From: Gilles Rochefort Date: Sun, 29 May 2016 17:25:02 +0200 Subject: [PATCH 1/2] Fixed BackgroundSubstractorMOG2 in opencv_video. The number of gaussians involved in a mixture is supposed to be dynamically adjusted. After being increased, the number of gaussians can't be reduced anymore. It seems to be a regression as the legacy code located in modules/legacy/src/bgfg_gaussmix.cpp allows to reduce such number of gaussians. --- modules/video/src/bgfg_gaussmix2.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/video/src/bgfg_gaussmix2.cpp b/modules/video/src/bgfg_gaussmix2.cpp index 9700dfebd8..d5eff8224c 100644 --- a/modules/video/src/bgfg_gaussmix2.cpp +++ b/modules/video/src/bgfg_gaussmix2.cpp @@ -309,7 +309,7 @@ struct MOG2Invoker : ParallelLoopBody //internal: bool fitsPDF = false;//if it remains zero a new GMM mode will be added - int nmodes = modesUsed[x], nNewModes = nmodes;//current number of modes in GMM + int nmodes = modesUsed[x];//current number of modes in GMM float totalWeight = 0.f; float* mean_m = mean; @@ -415,8 +415,6 @@ struct MOG2Invoker : ParallelLoopBody gmm[mode].weight *= totalWeight; } - nmodes = nNewModes; - //make new mode if needed and exit if( !fitsPDF ) { From 2717ba735a896d45b99a4e1143354bea19c394f7 Mon Sep 17 00:00:00 2001 From: Gilles Rochefort Date: Fri, 3 Jun 2016 11:00:31 +0200 Subject: [PATCH 2/2] Fixed BackgroundSubstractorMOG2 ocl implementation. --- modules/ocl/src/opencl/bgfg_mog.cl | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/ocl/src/opencl/bgfg_mog.cl b/modules/ocl/src/opencl/bgfg_mog.cl index a3c2619abc..f18a115325 100644 --- a/modules/ocl/src/opencl/bgfg_mog.cl +++ b/modules/ocl/src/opencl/bgfg_mog.cl @@ -369,7 +369,6 @@ __kernel void mog2_kernel(__global T_FRAME * frame, __global int* fgmask, __glob bool fitsPDF = false; //if it remains zero a new GMM mode will be added int nmodes = modesUsed[y * modesUsed_step + x]; - int nNewModes = nmodes; //current number of modes in GMM float totalWeight = 0.0f; @@ -430,8 +429,6 @@ __kernel void mog2_kernel(__global T_FRAME * frame, __global int* fgmask, __glob for (int mode = 0; mode < nmodes; ++mode) weight[(mode * frame_row + y) * weight_step + x] *= totalWeight; - nmodes = nNewModes; - if (!fitsPDF) { int mode = nmodes == (NMIXTURES) ? (NMIXTURES) - 1 : nmodes++;