mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-20 12:55:15 +08:00
update
This commit is contained in:
@@ -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 );
|
||||
|
||||
|
@@ -141,7 +141,7 @@ int main( int argc, char** argv )
|
||||
|
||||
vector<Vec4i> saliencyMap;
|
||||
saliencyAlgorithm.dynamicCast<ObjectnessBING>()->setTrainingPath( training_path );
|
||||
saliencyAlgorithm.dynamicCast<ObjectnessBING>()->setBBResDir(training_path + "/Results" );
|
||||
saliencyAlgorithm.dynamicCast<ObjectnessBING>()->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"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -97,47 +97,45 @@ MotionSaliencyBinWangApr2014::~MotionSaliencyBinWangApr2014()
|
||||
}
|
||||
|
||||
// classification (and adaptation) functions
|
||||
bool MotionSaliencyBinWangApr2014::fullResolutionDetection( Mat image, Mat highResBFMask )
|
||||
bool MotionSaliencyBinWangApr2014::fullResolutionDetection( Mat& image, Mat& highResBFMask )
|
||||
{
|
||||
Mat currentTemplateMat;
|
||||
float* currentB;
|
||||
float* currentC;
|
||||
Vec2f elem;
|
||||
float currentPixelValue;
|
||||
float currentEpslonValue;
|
||||
bool backgFlag = false;
|
||||
|
||||
// Initially, all pixels are considered as foreground and then we evaluate with the background model
|
||||
highResBFMask.create(image.rows, image.cols, CV_8UC1);
|
||||
highResBFMask.setTo( 1 );
|
||||
|
||||
// Scan all pixels of image
|
||||
for ( size_t i = 0; i < image.size().width; i++ )
|
||||
for ( size_t i = 0; i < image.rows; i++ )
|
||||
{
|
||||
for ( size_t j = 0; j < image.size().height; j++ )
|
||||
for ( size_t j = 0; j < image.cols; j++ )
|
||||
{
|
||||
backgFlag = false;
|
||||
// TODO replace "at" with more efficient matrix access
|
||||
currentPixelValue = image.at<float>( i, j );
|
||||
currentPixelValue = image.at<uchar>( i, j );
|
||||
currentEpslonValue = epslonPixelsValue.at<float>( 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<Vec2f>( i, j );
|
||||
currentB = &elem[0];
|
||||
currentC = &elem[1];
|
||||
currentB = &backgroundModel[z].at<Vec2f>( i, j )[0];
|
||||
currentC = &backgroundModel[z].at<Vec2f>( 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<int>( i, j ) = 0;
|
||||
highResBFMask.at<uchar>( 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<float>( 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<float>( i, j ) << " ";
|
||||
ofs2 << str.str();
|
||||
}
|
||||
stringstream str2;
|
||||
str2 << "\n";
|
||||
ofs2 << str2.str();
|
||||
}
|
||||
ofs2.close();
|
||||
|
||||
std::cout<<"TEST SIZE: "<<Test.size().height<<" "<<Test.size().width<<" RESULTS SIZE: "<<Results.size().height<<" "<<Results.size().width<<std::endl ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user