Commit c88e0fc4 authored by jaco's avatar jaco

templateReplacement function added (I part)

parent 5dfc2ff4
...@@ -120,7 +120,7 @@ class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency ...@@ -120,7 +120,7 @@ class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency
// Background model maintenance functions // Background model maintenance functions
bool templateOrdering(); bool templateOrdering();
bool templateReplacement( Mat finalBFMask ); bool templateReplacement( Mat finalBFMask, Mat image );
// Decision threshold adaptation and Activity control function // Decision threshold adaptation and Activity control function
//bool activityControl(vector<Mat> noisePixelMask); //bool activityControl(vector<Mat> noisePixelMask);
......
...@@ -298,9 +298,43 @@ bool MotionSaliencyBinWangApr2014::templateOrdering() ...@@ -298,9 +298,43 @@ bool MotionSaliencyBinWangApr2014::templateOrdering()
return true; return true;
} }
bool MotionSaliencyBinWangApr2014::templateReplacement( Mat finalBFMask ) bool MotionSaliencyBinWangApr2014::templateReplacement( Mat finalBFMask, Mat image )
{ {
/////////////////// MAINTENANCE of potentialBackground model ///////////////////
// Scan all pixels of finalBFMask
for ( int i = 0; i < finalBFMask.rows; i++ )
{
for ( int j = 0; j < finalBFMask.cols; j++ )
{
if( finalBFMask.at<int>( i, j ) == 1 ) // i.e. the corresponding frame pixel has been market as foreground
{
/* For the pixels with CA= 0, if the current frame pixel has been classified as foreground, its value
* will be loaded into BA and CA will be set to 1*/
if( potentialBackground.at<Vec2f>( i, j )[1] == 0 )
{
potentialBackground.at<Vec2f>( i, j )[0] = image.at<int>( i, j );
potentialBackground.at<Vec2f>( i, j )[1] = 1;
}
/*the distance between this pixel value and BA is calculated, and if this distance is smaller than
the decision threshold epslon, then CA is increased by 1, otherwise is decreased by 1*/
else if( abs( image.at<int>( i, j ) - potentialBackground.at<Vec2f>( i, j )[0] ) < epslonPixelsValue.at<float>( i, j ) )
{
potentialBackground.at<Vec2f>( i, j )[1] += 1;
}
else
{
potentialBackground.at<Vec2f>( i, j )[1] -= 1;
}
}
} // end of second for
} // end of first for
/////////////////// EVALUATION of potentialBackground values ///////////////////
return true; return true;
} }
...@@ -319,15 +353,16 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image, ...@@ -319,15 +353,16 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image,
fullResolutionDetection( image.getMat(), highResBFMask ); fullResolutionDetection( image.getMat(), highResBFMask );
lowResolutionDetection( image.getMat(), lowResBFMask ); lowResolutionDetection( image.getMat(), lowResBFMask );
// Compute the final background-foreground mask. One pixel is marked as foreground if and only if it is // Compute the final background-foreground mask. One pixel is marked as foreground if and only if it is
// foreground in both masks (full and low) // foreground in both masks (full and low)
bitwise_and( highResBFMask, lowResBFMask, finalBFMask ); bitwise_and( highResBFMask, lowResBFMask, finalBFMask );
// Detect the noise pixels (i.e. for a given pixel, fullRes(pixel) = foreground and lowRes(pixel)= background) // Detect the noise pixels (i.e. for a given pixel, fullRes(pixel) = foreground and lowRes(pixel)= background)
bitwise_not( lowResBFMask, not_lowResBFMask ); bitwise_not( lowResBFMask, not_lowResBFMask );
bitwise_and( highResBFMask, not_lowResBFMask, noisePixelsMask ); bitwise_and( highResBFMask, not_lowResBFMask, noisePixelsMask );
templateOrdering();
templateReplacement( finalBFMask, image.getMat() );
templateOrdering(); templateOrdering();
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment