Itseez/opencv — pull request #2473 by euphrat (2014-03-12 14:25:26+00:00)
Title: Fixed an issue with weight assignment causing the resulting GMM weights ...

...to be unsorted in BackgroundSubtractorMOG2

Bug explanation:
When I look at the weights of the resulting Gaussians after processing my images with MOG2 Background subtractor, I see that they are not necessarily sorted. As far as I know, the weights should be sorted from high to low so that at some point you can choose the modes that correspond to the background.

My guess is that the problem is due to the swap operations happening in MOG2Invoker::operator(const Range& range). The swaps change the position of the Gaussians, but the weight is assigned to the original position before the swaps.

Solution:
In order to fix this, I keep track of the number of swaps to determine the correct position and update the correct Gaussian's weight.