diff --git a/modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp b/modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp index 79c44ac5d..d3fa02210 100644 --- a/modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp +++ b/modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp @@ -114,7 +114,7 @@ class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency private: // classification (and adaptation) functions - bool fullResolutionDetection( Mat image, Mat highResBFMask ); + bool fullResolutionDetection( Mat& image, Mat& highResBFMask ); bool lowResolutionDetection( Mat image, Mat lowResBFMask ); //bool templateUpdate( Mat highResBFMask ); diff --git a/modules/saliency/samples/computeSaliency.cpp b/modules/saliency/samples/computeSaliency.cpp index acc24eee6..56ff6ce17 100644 --- a/modules/saliency/samples/computeSaliency.cpp +++ b/modules/saliency/samples/computeSaliency.cpp @@ -141,7 +141,7 @@ int main( int argc, char** argv ) vector saliencyMap; saliencyAlgorithm.dynamicCast()->setTrainingPath( training_path ); - saliencyAlgorithm.dynamicCast()->setBBResDir(training_path + "/Results" ); + saliencyAlgorithm.dynamicCast()->setBBResDir( training_path + "/Results" ); if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) ) { @@ -154,6 +154,14 @@ int main( int argc, char** argv ) } } + else if( saliency_algorithm.find( "BinWangApr2014" ) == 0 ) + { + Mat saliencyMap; + if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) ) + { + std::cout<<"OKKKK"<( i, j ); + currentPixelValue = image.at( i, j ); currentEpslonValue = epslonPixelsValue.at( i, j ); // scan background model vector for ( size_t z = 0; z < backgroundModel.size(); z++ ) { - currentTemplateMat = backgroundModel[z]; // Current Background Model matrix // TODO replace "at" with more efficient matrix access - elem = currentTemplateMat.at( i, j ); - currentB = &elem[0]; - currentC = &elem[1]; + currentB = &backgroundModel[z].at( i, j )[0]; + currentC = &backgroundModel[z].at( i, j )[1]; - if( currentC > 0 ) //The current template is active + if( *currentC > 0 ) //The current template is active { // If there is a match with a current background template - if( abs( currentPixelValue - * ( currentB ) ) < currentEpslonValue && !backgFlag ) + if( abs( currentPixelValue - *(currentB) ) < currentEpslonValue && !backgFlag ) { // The correspondence pixel in the BF mask is set as background ( 0 value) // TODO replace "at" with more efficient matrix access - highResBFMask.at( i, j ) = 0; + highResBFMask.at( i, j ) = 0; *currentC += 1; // increment the efficacy of this template - *currentB = (( 1 - alpha ) * *currentB) + ( alpha * currentPixelValue ); // Update the template value + *currentB = ( ( 1 - alpha ) * *(currentB) ) + ( alpha * currentPixelValue ); // Update the template value backgFlag = true; //break; } @@ -148,10 +146,10 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( Mat image, Mat highR } } // end "for" cicle of template vector + } } // end "for" cicle of all image's pixels - return true; } bool MotionSaliencyBinWangApr2014::lowResolutionDetection( Mat image, Mat lowResBFMask ) @@ -160,10 +158,10 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( Mat image, Mat lowRes return true; } /*bool MotionSaliencyBinWangApr2014::templateUpdate( Mat highResBFMask ) -{ + { - return true; -}*/ + return true; + }*/ // Background model maintenance functions bool MotionSaliencyBinWangApr2014::templateOrdering() @@ -180,6 +178,50 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( Mat finalBFMask ) bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image, OutputArray saliencyMap ) { + Mat Test( 36, 36, CV_32F ); + Mat Results; + + std::ofstream ofs; + ofs.open( "TEST.txt", std::ofstream::out ); + + for ( int i = 0; i < Test.size().height; i++ ) + { + for ( int j = 0; j < Test.size().width; j++ ) + { + Test.at( i, j ) = i + j; + stringstream str; + str << i + j << " "; + ofs << str.str(); + } + stringstream str2; + str2 << "\n"; + ofs << str2.str(); + } + ofs.close(); + + //blur( Test, Results, Size( 4, 4 ) ); + medianBlur( Test, Results, 3 ); + //pyrDown(Results,Results, Size(Test.size().height/9, Test.size().width/9)); + + std::ofstream ofs2; + ofs2.open( "RESULTS.txt", std::ofstream::out ); + + for ( int i = 0; i < Results.size().height; i++ ) + { + for ( int j = 0; j < Results.size().width; j++ ) + { + stringstream str; + str << Results.at( i, j ) << " "; + ofs2 << str.str(); + } + stringstream str2; + str2 << "\n"; + ofs2 << str2.str(); + } + ofs2.close(); + + std::cout<<"TEST SIZE: "<