mirror of
https://github.com/opencv/opencv.git
synced 2026-09-19 15:23:23 -05:00
Fixed an issue with weight assignment causing the resulting GMM weights to be unsorted in the CUDA and OCL versions of BackgroundSubtractorMOG2
This commit is contained in:
@@ -489,7 +489,7 @@ namespace cv { namespace gpu { namespace device
|
|||||||
{
|
{
|
||||||
//need only weight if fit is found
|
//need only weight if fit is found
|
||||||
float weight = alpha1 * gmm_weight(mode * frame.rows + y, x) + prune;
|
float weight = alpha1 * gmm_weight(mode * frame.rows + y, x) + prune;
|
||||||
|
int swap_count = 0;
|
||||||
//fit not found yet
|
//fit not found yet
|
||||||
if (!fitsPDF)
|
if (!fitsPDF)
|
||||||
{
|
{
|
||||||
@@ -540,6 +540,7 @@ namespace cv { namespace gpu { namespace device
|
|||||||
if (weight < gmm_weight((i - 1) * frame.rows + y, x))
|
if (weight < gmm_weight((i - 1) * frame.rows + y, x))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
swap_count++;
|
||||||
//swap one up
|
//swap one up
|
||||||
swap(gmm_weight, x, y, i - 1, frame.rows);
|
swap(gmm_weight, x, y, i - 1, frame.rows);
|
||||||
swap(gmm_variance, x, y, i - 1, frame.rows);
|
swap(gmm_variance, x, y, i - 1, frame.rows);
|
||||||
@@ -557,7 +558,7 @@ namespace cv { namespace gpu { namespace device
|
|||||||
nmodes--;
|
nmodes--;
|
||||||
}
|
}
|
||||||
|
|
||||||
gmm_weight(mode * frame.rows + y, x) = weight; //update weight by the calculated value
|
gmm_weight((mode - swap_count) * frame.rows + y, x) = weight; //update weight by the calculated value
|
||||||
totalWeight += weight;
|
totalWeight += weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ __kernel void mog2_kernel(__global T_FRAME * frame, __global int* fgmask, __glob
|
|||||||
for (int mode = 0; mode < nmodes; ++mode)
|
for (int mode = 0; mode < nmodes; ++mode)
|
||||||
{
|
{
|
||||||
float _weight = alpha1 * weight[(mode * frame_row + y) * weight_step + x] + prune;
|
float _weight = alpha1 * weight[(mode * frame_row + y) * weight_step + x] + prune;
|
||||||
|
int swap_count = 0;
|
||||||
if (!fitsPDF)
|
if (!fitsPDF)
|
||||||
{
|
{
|
||||||
float var = variance[(mode * frame_row + y) * var_step + x];
|
float var = variance[(mode * frame_row + y) * var_step + x];
|
||||||
@@ -404,6 +404,7 @@ __kernel void mog2_kernel(__global T_FRAME * frame, __global int* fgmask, __glob
|
|||||||
{
|
{
|
||||||
if (_weight < weight[((i - 1) * frame_row + y) * weight_step + x])
|
if (_weight < weight[((i - 1) * frame_row + y) * weight_step + x])
|
||||||
break;
|
break;
|
||||||
|
swap_count++;
|
||||||
swap(weight, x, y, i - 1, frame_row, weight_step);
|
swap(weight, x, y, i - 1, frame_row, weight_step);
|
||||||
swap(variance, x, y, i - 1, frame_row, var_step);
|
swap(variance, x, y, i - 1, frame_row, var_step);
|
||||||
#if defined (CN1)
|
#if defined (CN1)
|
||||||
@@ -421,7 +422,7 @@ __kernel void mog2_kernel(__global T_FRAME * frame, __global int* fgmask, __glob
|
|||||||
nmodes--;
|
nmodes--;
|
||||||
}
|
}
|
||||||
|
|
||||||
weight[(mode * frame_row + y) * weight_step + x] = _weight; //update weight by the calculated value
|
weight[((mode - swap_count) * frame_row + y) * weight_step + x] = _weight; //update weight by the calculated value
|
||||||
totalWeight += _weight;
|
totalWeight += _weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user