Commit 3a086642 authored by jaco's avatar jaco

Initialization phase added

parent 301c6252
...@@ -139,6 +139,7 @@ class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency ...@@ -139,6 +139,7 @@ class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency
// background pixel. In a noise-pixel mask, the identified noise-pixels are set to 1 while other pixels are 0; // background pixel. In a noise-pixel mask, the identified noise-pixels are set to 1 while other pixels are 0;
//fixed parameter //fixed parameter
bool neighborhoodCheck;
int N_DS; // Number of template to be downsampled and used in lowResolutionDetection function int N_DS; // Number of template to be downsampled and used in lowResolutionDetection function
Ptr<Size> imgSize; // Size of input image Ptr<Size> imgSize; // Size of input image
int K; // Number of background model template int K; // Number of background model template
......
...@@ -64,6 +64,7 @@ MotionSaliencyBinWangApr2014::MotionSaliencyBinWangApr2014() ...@@ -64,6 +64,7 @@ MotionSaliencyBinWangApr2014::MotionSaliencyBinWangApr2014()
thetaL = 2500; // T0, T1 swap threshold thetaL = 2500; // T0, T1 swap threshold
thetaA = 200; thetaA = 200;
gamma = 3; gamma = 3;
neighborhoodCheck = true;
className = "BinWangApr2014"; className = "BinWangApr2014";
} }
...@@ -103,7 +104,7 @@ MotionSaliencyBinWangApr2014::~MotionSaliencyBinWangApr2014() ...@@ -103,7 +104,7 @@ MotionSaliencyBinWangApr2014::~MotionSaliencyBinWangApr2014()
// classification (and adaptation) functions // classification (and adaptation) functions
bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, Mat& highResBFMask ) bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, Mat& highResBFMask )
{ {
Mat image=image2.clone(); Mat image = image2.clone();
float* currentB; float* currentB;
float* currentC; float* currentC;
float currentPixelValue; float currentPixelValue;
...@@ -121,9 +122,9 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M ...@@ -121,9 +122,9 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
// Scan all pixels of image // Scan all pixels of image
for ( int i = 0; i < image.rows; i++ ) for ( int i = 0; i < image.rows; i++ )
{ {
pImage= image.ptr<uchar>(i); pImage = image.ptr<uchar>( i );
pEpslon= epslonPixelsValue.ptr<float>(i); pEpslon = epslonPixelsValue.ptr<float>( i );
pMask= highResBFMask.ptr<uchar>(i); pMask = highResBFMask.ptr<uchar>( i );
for ( int j = 0; j < image.cols; j++ ) for ( int j = 0; j < image.cols; j++ )
{ {
backgFlag = false; backgFlag = false;
...@@ -131,39 +132,46 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M ...@@ -131,39 +132,46 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
//currentPixelValue = image.at<uchar>( i, j ); //currentPixelValue = image.at<uchar>( i, j );
//currentEpslonValue = epslonPixelsValue.at<float>( i, j ); //currentEpslonValue = epslonPixelsValue.at<float>( i, j );
currentPixelValue = pImage[j]; currentPixelValue = pImage[j];
currentEpslonValue= pEpslon[j]; currentEpslonValue = pEpslon[j];
if( backgroundModel[0].at<Vec2f>( i, j )[1] != 0 ) //if at least the first template is activated / initialized
// scan background model vector
for ( size_t z = 0; z < backgroundModel.size(); z++ )
{ {
// TODO replace "at" with more efficient matrix access
currentB = &backgroundModel[z].at<Vec2f>( i, j )[0];
currentC = &backgroundModel[z].at<Vec2f>( i, j )[1];
if( *currentC > 0 ) //The current template is active // scan background model vector
for ( size_t z = 0; z < backgroundModel.size(); z++ )
{ {
// If there is a match with a current background template // TODO replace "at" with more efficient matrix access
if( abs( currentPixelValue - * ( currentB ) ) < currentEpslonValue && !backgFlag ) currentB = &backgroundModel[z].at<Vec2f>( i, j )[0];
{ currentC = &backgroundModel[z].at<Vec2f>( i, j )[1];
// The correspondence pixel in the BF mask is set as background ( 0 value)
// TODO replace "at" with more efficient matrix access if( *currentC > 0 ) //The current template is active
//highResBFMask.at<uchar>( i, j ) = 0;
pMask[j]=0;
if( ( *currentC < L0 && z == 0 ) || ( *currentC < L1 && z == 1 ) || ( z > 1 ) )
*currentC += 1; // increment the efficacy of this template
*currentB = ( ( 1 - alpha ) * * ( currentB ) ) + ( alpha * currentPixelValue ); // Update the template value
backgFlag = true;
//break;
}
else
{ {
currentC -= 1; // decrement the efficacy of this template // If there is a match with a current background template
if( abs( currentPixelValue - * ( currentB ) ) < currentEpslonValue && !backgFlag )
{
// The correspondence pixel in the BF mask is set as background ( 0 value)
//highResBFMask.at<uchar>( i, j ) = 0;
pMask[j] = 0;
if( ( *currentC < L0 && z == 0 ) || ( *currentC < L1 && z == 1 ) || ( z > 1 ) )
*currentC += 1; // increment the efficacy of this template
*currentB = ( ( 1 - alpha ) * * ( currentB ) ) + ( alpha * currentPixelValue ); // Update the template value
backgFlag = true;
//break;
}
else
{
currentC -= 1; // decrement the efficacy of this template
}
} }
} // end "for" cicle of template vector
} }
} // end "for" cicle of template vector else
{
pMask[j] = 1; //if the model of the current pixel is not yet initialized, we mark the pixels as foreground
}
} }
} // end "for" cicle of all image's pixels } // end "for" cicle of all image's pixels
...@@ -173,112 +181,79 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M ...@@ -173,112 +181,79 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat& lowResBFMask ) bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat& lowResBFMask )
{ {
//double t = (double) getTickCount(); std::vector<Mat> mv;
split( backgroundModel[0], mv );
float currentPixelValue; //if at least the first template is activated / initialized for all pixels
float currentEpslonValue; if( countNonZero( mv.at( 1 ) ) == ( mv.at( 1 ).cols * mv.at( 1 ).rows ) )
float currentB; {
float currentC; float currentPixelValue;
float currentEpslonValue;
float currentB;
float currentC;
/*// Create a mask to select ROI in the original Image and Backgound model and at the same time compute the mean // Create a mask to select ROI in the original Image and Backgound model and at the same time compute the mean
Mat ROIMask( image.rows, image.cols, CV_8UC1 );
ROIMask.setTo( 0 );*/
Rect roi( Point( 0, 0 ), Size( N, N ) ); Rect roi( Point( 0, 0 ), Size( N, N ) );
Scalar imageROImean; Scalar imageROImean;
Scalar backGModelROImean; Scalar backGModelROImean;
Mat currentModel; Mat currentModel;
// Initially, all pixels are considered as foreground and then we evaluate with the background model // Initially, all pixels are considered as foreground and then we evaluate with the background model
//lowResBFMask.create( image.size().height / ( N * N ), image.size().width / ( N * N ), CV_8UC1 ); lowResBFMask.create( image.rows, image.cols, CV_8UC1 );
//lowResBFMask.setTo( 1 ); lowResBFMask.setTo( 1 );
lowResBFMask.create( image.rows, image.cols, CV_8UC1 ); // Scan all the ROI of original matrices
lowResBFMask.setTo( 1 ); for ( int i = 0; i < image.rows / N; i++ )
/*t = ( (double) getTickCount() - t ) / getTickFrequency();
cout << "INITIALIZATION TIME: " << t << "s" << endl << endl;*/
// Scan all the ROI of original matrices
for ( int i = 0; i < image.rows / N; i++ )
{
for ( int j = 0; j < image.cols / N; j++ )
{ {
//double t = (double) getTickCount(); for ( int j = 0; j < image.cols / N; j++ )
//double t1 = (double) getTickCount();
// Reset and update ROI mask
//ROIMask.setTo( 0 );
//rectangle( ROIMask, roi, Scalar( 255 ), FILLED );
//double t3 = (double) getTickCount();
// Compute the mean of image's block and epslonMatrix's block based on ROI
// TODO replace "at" with more efficient matrix access
Mat roiImage = image( roi );
Mat roiEpslon = epslonPixelsValue( roi );
currentPixelValue = mean( roiImage ).val[0];
currentEpslonValue = mean( roiEpslon ).val[0];
//t3 = ( (double) getTickCount() - t3 ) / getTickFrequency();
// cout << "MEAN time: " << t3 << "s" << endl << endl;
//t1 = ( (double) getTickCount() - t1 ) / getTickFrequency();
//cout << "FASE 1 time: " << t1 << "s" << endl << endl;
//double t2 = (double) getTickCount();
// scan background model vector
for ( int z = 0; z < N_DS; z++ )
{ {
// Compute the mean of image's block and epslonMatrix's block based on ROI
//double t = (double) getTickCount(); Mat roiImage = image( roi );
// Select the current template 2 channel matrix, select ROI and compute the mean for each channel separately Mat roiEpslon = epslonPixelsValue( roi );
Mat roiTemplate = backgroundModel[z]( roi ); currentPixelValue = mean( roiImage ).val[0];
Scalar templateMean = mean( roiTemplate ); currentEpslonValue = mean( roiEpslon ).val[0];
currentB = templateMean[0];
currentC = templateMean[1]; // scan background model vector
//t = ( (double) getTickCount() - t ) / getTickFrequency(); for ( int z = 0; z < N_DS; z++ )
//cout << "currentB and currentC MEAN time" << t << "s" << endl << endl;
if( currentC > 0 ) //The current template is active
{ {
// If there is a match with a current background template // Select the current template 2 channel matrix, select ROI and compute the mean for each channel separately
if( abs( currentPixelValue - ( currentB ) ) < currentEpslonValue ) Mat roiTemplate = backgroundModel[z]( roi );
Scalar templateMean = mean( roiTemplate );
currentB = templateMean[0];
currentC = templateMean[1];
if( currentC > 0 ) //The current template is active
{ {
// The correspondence pixel in the BF mask is set as background ( 0 value) // If there is a match with a current background template
// TODO replace "at" with more efficient matrix access if( abs( currentPixelValue - ( currentB ) ) < currentEpslonValue )
//lowResBFMask.at<uchar>( i, j ) = 0; {
//lowResBFMask.setTo( 0, ROIMask ); // The correspondence pixel in the BF mask is set as background ( 0 value)
rectangle( lowResBFMask, roi, Scalar( 0 ), FILLED ); // TODO replace "at" with more efficient matrix access
break; //lowResBFMask.at<uchar>( i, j ) = 0;
//lowResBFMask.setTo( 0, ROIMask );
rectangle( lowResBFMask, roi, Scalar( 0 ), FILLED );
break;
}
} }
} }
// Shift the ROI from left to right follow the block dimension
roi = roi + Point( N, 0 );
} }
//Shift the ROI from up to down follow the block dimension, also bringing it back to beginning of row
//t2 = ( (double) getTickCount() - t2 ) / getTickFrequency(); roi.x = 0;
//cout << "ALL TEMPLATE time: " << t2 << " s" << endl << endl; roi.y += N;
// Shift the ROI from left to right follow the block dimension
roi = roi + Point( N, 0 );
//t = ( (double) getTickCount() - t ) / getTickFrequency();
//cout << "low res PIXEL : " << t << " s" << endl << endl;
//exit(0);
} }
//Shift the ROI from up to down follow the block dimension, also bringing it back to beginning of row return true;
roi.x = 0; }
roi.y += N; else
{
lowResBFMask.create( image.rows, image.cols, CV_8UC1 );
lowResBFMask.setTo( NAN );
return false;
} }
//t = ( (double) getTickCount() - t ) / getTickFrequency();
//cout << "Scan all the ROI of original matrices time: " << t << "s" << endl << endl;
// UPSAMPLE the lowResBFMask to the original image dimension, so that it's then possible to compare the results
// of lowlResolutionDetection with the fullResolutionDetection
//resize( lowResBFMask, lowResBFMask, image.size(), 0, 0, INTER_LINEAR );
return true;
} }
/*bool MotionSaliencyBinWangApr2014::templateUpdate( Mat highResBFMask )
{
return true;
}*/
bool inline pairCompare( pair<float, float> t, pair<float, float> t_plusOne ) bool inline pairCompare( pair<float, float> t, pair<float, float> t_plusOne )
{ {
...@@ -338,6 +313,22 @@ bool MotionSaliencyBinWangApr2014::templateOrdering() ...@@ -338,6 +313,22 @@ bool MotionSaliencyBinWangApr2014::templateOrdering()
} }
bool MotionSaliencyBinWangApr2014::templateReplacement( const Mat& finalBFMask, const Mat& image ) bool MotionSaliencyBinWangApr2014::templateReplacement( const Mat& finalBFMask, const Mat& image )
{ {
std::vector<Mat> temp;
split( backgroundModel[0], temp );
//if at least the first template is activated / initialized for all pixels
if( countNonZero( temp.at( 1 ) ) != ( temp.at( 1 ).cols * temp.at( 1 ).rows ) )
{
thetaA = 20;
neighborhoodCheck = false;
}
else
{
thetaA = 200;
neighborhoodCheck = true;
}
float roiSize = 3; // FIXED ROI SIZE, not change until you first appropriately adjust the following controls in the EVALUATION section! float roiSize = 3; // FIXED ROI SIZE, not change until you first appropriately adjust the following controls in the EVALUATION section!
int countNonZeroElements = NAN; int countNonZeroElements = NAN;
std::vector<Mat> mv; std::vector<Mat> mv;
...@@ -375,85 +366,93 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( const Mat& finalBFMask, ...@@ -375,85 +366,93 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( const Mat& finalBFMask,
/////////////////// EVALUATION of potentialBackground values /////////////////// /////////////////// EVALUATION of potentialBackground values ///////////////////
if( potentialBackground.at<Vec2f>( i, j )[1] > thetaA ) if( potentialBackground.at<Vec2f>( i, j )[1] > thetaA )
{ {
// replicate currentBA value if( neighborhoodCheck )
replicateCurrentBAMat.setTo( potentialBackground.at<Vec2f>( i, j )[0] );
for ( size_t z = 0; z < backgroundModel.size(); z++ )
{ {
// Neighborhood of current pixel in the current background model template. // replicate currentBA value
// The ROI is centered in the pixel coordinates replicateCurrentBAMat.setTo( potentialBackground.at<Vec2f>( i, j )[0] );
/*if( ( i - floor( roiSize / 2 ) >= 0 ) && ( j - floor( roiSize / 2 ) >= 0 ) for ( size_t z = 0; z < backgroundModel.size(); z++ )
&& ( i + floor( roiSize / 2 ) <= ( backgroundModel[z].rows - 1 ) )
&& ( j + floor( roiSize / 2 ) <= ( backgroundModel[z].cols - 1 ) ) ) */
if( i > 0 && j > 0 && i < ( backgroundModel[z].rows - 1 ) && j < ( backgroundModel[z].cols - 1 ) )
{
split( backgroundModel[z], mv );
backgroundModelROI = mv.at( 0 )( Rect( j - floor( roiSize / 2 ), i - floor( roiSize / 2 ), roiSize, roiSize ) );
}
else if( i == 0 && j == 0 ) // upper left
{
split( backgroundModel[z], mv );
backgroundModelROI = mv.at( 0 )( Rect( j, i, ceil( roiSize / 2 ), ceil( roiSize / 2 ) ) );
}
else if( j == 0 && i > 0 && i < ( backgroundModel[z].rows - 1 ) ) // middle left
{
split( backgroundModel[z], mv );
backgroundModelROI = mv.at( 0 )( Rect( j, i - floor( roiSize / 2 ), ceil( roiSize / 2 ), roiSize ) );
}
else if( i == ( backgroundModel[z].rows - 1 ) && j == 0 ) //down left
{
split( backgroundModel[z], mv );
backgroundModelROI = mv.at( 0 )( Rect( j, i - floor( roiSize / 2 ), ceil( roiSize / 2 ), ceil( roiSize / 2 ) ) );
}
else if( i == 0 && j > 0 && j < ( backgroundModel[z].cols - 1 ) ) // upper - middle
{ {
split( backgroundModel[z], mv ); // Neighborhood of current pixel in the current background model template.
backgroundModelROI = mv.at( 0 )( Rect( ( j - floor( roiSize / 2 ) ), i, roiSize, ceil( roiSize / 2 ) ) ); // The ROI is centered in the pixel coordinates
}
else if( i == ( backgroundModel[z].rows - 1 ) && j > 0 && j < ( backgroundModel[z].cols - 1 ) ) //down middle /*if( ( i - floor( roiSize / 2 ) >= 0 ) && ( j - floor( roiSize / 2 ) >= 0 )
{ && ( i + floor( roiSize / 2 ) <= ( backgroundModel[z].rows - 1 ) )
split( backgroundModel[z], mv ); && ( j + floor( roiSize / 2 ) <= ( backgroundModel[z].cols - 1 ) ) ) */
backgroundModelROI = mv.at( 0 )( Rect( j - floor( roiSize / 2 ), i - floor( roiSize / 2 ), roiSize, ceil( roiSize / 2 ) ) ); if( i > 0 && j > 0 && i < ( backgroundModel[z].rows - 1 ) && j < ( backgroundModel[z].cols - 1 ) )
} {
else if( i == 0 && j == ( backgroundModel[z].cols - 1 ) ) // upper right split( backgroundModel[z], mv );
{ backgroundModelROI = mv.at( 0 )( Rect( j - floor( roiSize / 2 ), i - floor( roiSize / 2 ), roiSize, roiSize ) );
split( backgroundModel[z], mv ); }
backgroundModelROI = mv.at( 0 )( Rect( j - floor( roiSize / 2 ), i, ceil( roiSize / 2 ), ceil( roiSize / 2 ) ) ); else if( i == 0 && j == 0 ) // upper left
} {
else if( j == ( backgroundModel[z].cols - 1 ) && i > 0 && i < ( backgroundModel[z].rows - 1 ) ) // middle - right split( backgroundModel[z], mv );
{ backgroundModelROI = mv.at( 0 )( Rect( j, i, ceil( roiSize / 2 ), ceil( roiSize / 2 ) ) );
split( backgroundModel[z], mv ); }
backgroundModelROI = mv.at( 0 )( Rect( j - floor( roiSize / 2 ), i - floor( roiSize / 2 ), ceil( roiSize / 2 ), roiSize ) ); else if( j == 0 && i > 0 && i < ( backgroundModel[z].rows - 1 ) ) // middle left
} {
else if( i == ( backgroundModel[z].rows - 1 ) && j == ( backgroundModel[z].cols - 1 ) ) // down right split( backgroundModel[z], mv );
{ backgroundModelROI = mv.at( 0 )( Rect( j, i - floor( roiSize / 2 ), ceil( roiSize / 2 ), roiSize ) );
split( backgroundModel[z], mv ); }
backgroundModelROI = mv.at( 0 )( Rect( j - floor( roiSize / 2 ), i - floor( roiSize / 2 ), ceil( roiSize / 2 ), ceil( roiSize / 2 ) ) ); else if( i == ( backgroundModel[z].rows - 1 ) && j == 0 ) //down left
} {
split( backgroundModel[z], mv );
/* Check if the value of current pixel BA in potentialBackground model is already contained in at least one of its neighbors' backgroundModelROI = mv.at( 0 )( Rect( j, i - floor( roiSize / 2 ), ceil( roiSize / 2 ), ceil( roiSize / 2 ) ) );
* background model }
*/ else if( i == 0 && j > 0 && j < ( backgroundModel[z].cols - 1 ) ) // upper - middle
resize( replicateCurrentBAMat, replicateCurrentBAMat, Size( backgroundModelROI.cols, backgroundModelROI.rows ), 0, 0, INTER_LINEAR ); {
resize( diffResult, diffResult, Size( backgroundModelROI.cols, backgroundModelROI.rows ), 0, 0, INTER_LINEAR ); split( backgroundModel[z], mv );
backgroundModelROI = mv.at( 0 )( Rect( ( j - floor( roiSize / 2 ) ), i, roiSize, ceil( roiSize / 2 ) ) );
absdiff( replicateCurrentBAMat, backgroundModelROI, diffResult ); }
threshold( diffResult, diffResult, epslonPixelsValue.at<float>( i, j ), 255, THRESH_BINARY_INV ); else if( i == ( backgroundModel[z].rows - 1 ) && j > 0 && j < ( backgroundModel[z].cols - 1 ) ) //down middle
countNonZeroElements = countNonZero( diffResult ); {
split( backgroundModel[z], mv );
if( countNonZeroElements > 0 ) backgroundModelROI = mv.at( 0 )( Rect( j - floor( roiSize / 2 ), i - floor( roiSize / 2 ), roiSize, ceil( roiSize / 2 ) ) );
{ }
/////////////////// REPLACEMENT of backgroundModel template /////////////////// else if( i == 0 && j == ( backgroundModel[z].cols - 1 ) ) // upper right
//replace TA with current TK {
split( backgroundModel[z], mv );
//TODO CHECK BACKGROUND MODEL COUNTER ASSIGNEMENT backgroundModelROI = mv.at( 0 )( Rect( j - floor( roiSize / 2 ), i, ceil( roiSize / 2 ), ceil( roiSize / 2 ) ) );
//backgroundModel[backgroundModel.size()-1].at<Vec2f>( i, j )[0]=potentialBackground.at<Vec2f>( i, j )[0]; }
//backgroundModel[backgroundModel.size()-1].at<Vec2f>( i, j )[1]= potentialBackground.at<Vec2f>( i, j )[1]; else if( j == ( backgroundModel[z].cols - 1 ) && i > 0 && i < ( backgroundModel[z].rows - 1 ) ) // middle - right
backgroundModel[backgroundModel.size() - 1].at<Vec2f>( i, j ) = potentialBackground.at<Vec2f>( i, j ); {
break; split( backgroundModel[z], mv );
} backgroundModelROI = mv.at( 0 )( Rect( j - floor( roiSize / 2 ), i - floor( roiSize / 2 ), ceil( roiSize / 2 ), roiSize ) );
} // end for backgroundModel size }
else if( i == ( backgroundModel[z].rows - 1 ) && j == ( backgroundModel[z].cols - 1 ) ) // down right
{
split( backgroundModel[z], mv );
backgroundModelROI = mv.at( 0 )(
Rect( j - floor( roiSize / 2 ), i - floor( roiSize / 2 ), ceil( roiSize / 2 ), ceil( roiSize / 2 ) ) );
}
/* Check if the value of current pixel BA in potentialBackground model is already contained in at least one of its neighbors'
* background model
*/
resize( replicateCurrentBAMat, replicateCurrentBAMat, Size( backgroundModelROI.cols, backgroundModelROI.rows ), 0, 0, INTER_LINEAR );
resize( diffResult, diffResult, Size( backgroundModelROI.cols, backgroundModelROI.rows ), 0, 0, INTER_LINEAR );
absdiff( replicateCurrentBAMat, backgroundModelROI, diffResult );
threshold( diffResult, diffResult, epslonPixelsValue.at<float>( i, j ), 255, THRESH_BINARY_INV );
countNonZeroElements = countNonZero( diffResult );
if( countNonZeroElements > 0 )
{
/////////////////// REPLACEMENT of backgroundModel template ///////////////////
//replace TA with current TK
//TODO CHECK BACKGROUND MODEL COUNTER ASSIGNEMENT
//backgroundModel[backgroundModel.size()-1].at<Vec2f>( i, j )[0]=potentialBackground.at<Vec2f>( i, j )[0];
//backgroundModel[backgroundModel.size()-1].at<Vec2f>( i, j )[1]= potentialBackground.at<Vec2f>( i, j )[1];
backgroundModel[backgroundModel.size() - 1].at<Vec2f>( i, j ) = potentialBackground.at<Vec2f>( i, j );
break;
}
} // end for backgroundModel size
}
else
{
backgroundModel[backgroundModel.size() - 1].at<Vec2f>( i, j ) = potentialBackground.at<Vec2f>( i, j );
}
} // close if of EVALUATION } // close if of EVALUATION
} // end of if( finalBFMask.at<uchar>( i, j ) == 1 ) // i.e. the corresponding frame pixel has been market as foreground } // end of if( finalBFMask.at<uchar>( i, j ) == 1 ) // i.e. the corresponding frame pixel has been market as foreground
...@@ -470,19 +469,10 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image, ...@@ -470,19 +469,10 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image,
Mat lowResBFMask; Mat lowResBFMask;
Mat not_lowResBFMask; Mat not_lowResBFMask;
Mat noisePixelsMask; Mat noisePixelsMask;
double tt = (double) getTickCount();
double t = (double) getTickCount();
fullResolutionDetection( image.getMat(), highResBFMask ); fullResolutionDetection( image.getMat(), highResBFMask );
t = ( (double) getTickCount() - t ) / getTickFrequency();
cout << "fullResolutionDetection time: " << t << "s" << endl << endl;
t = (double) getTickCount();
lowResolutionDetection( image.getMat(), lowResBFMask ); lowResolutionDetection( image.getMat(), lowResBFMask );
t = ( (double) getTickCount() - t ) / getTickFrequency();
cout << "lowResolutionDetection time: " << t << "s" << endl << endl;
t = (double) getTickCount();
// 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, saliencyMap ); bitwise_and( highResBFMask, lowResBFMask, saliencyMap );
...@@ -490,26 +480,10 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image, ...@@ -490,26 +480,10 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image,
// 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 );
t = ( (double) getTickCount() - t ) / getTickFrequency();
cout << "and not and time: " << t << "s" << endl << endl;
t = (double) getTickCount();
templateOrdering(); templateOrdering();
t = ( (double) getTickCount() - t ) / getTickFrequency();
cout << "ordering1 : " << t << "s" << endl << endl;
t = (double) getTickCount();
templateReplacement( saliencyMap.getMat(), image.getMat() ); templateReplacement( saliencyMap.getMat(), image.getMat() );
t = ( (double) getTickCount() - t ) / getTickFrequency();
cout << "replacement : " << t << "s" << endl << endl;
t = (double) getTickCount();
templateOrdering(); templateOrdering();
t = ( (double) getTickCount() - t ) / getTickFrequency();
cout << "ordering2 : " << t << "s" << endl << endl;
tt = ( (double) getTickCount() - tt ) / getTickFrequency();
cout << "TOTAL : " << tt << "s" << endl << endl;
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