mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-22 07:31:26 +08:00
update
This commit is contained in:
@@ -114,7 +114,7 @@ class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
// classification (and adaptation) functions
|
// classification (and adaptation) functions
|
||||||
bool fullResolutionDetection( Mat image, Mat highResBFMask );
|
bool fullResolutionDetection( Mat& image, Mat& highResBFMask );
|
||||||
bool lowResolutionDetection( Mat image, Mat lowResBFMask );
|
bool lowResolutionDetection( Mat image, Mat lowResBFMask );
|
||||||
//bool templateUpdate( Mat highResBFMask );
|
//bool templateUpdate( Mat highResBFMask );
|
||||||
|
|
||||||
|
@@ -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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -97,47 +97,45 @@ MotionSaliencyBinWangApr2014::~MotionSaliencyBinWangApr2014()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// classification (and adaptation) functions
|
// classification (and adaptation) functions
|
||||||
bool MotionSaliencyBinWangApr2014::fullResolutionDetection( Mat image, Mat highResBFMask )
|
bool MotionSaliencyBinWangApr2014::fullResolutionDetection( Mat& image, Mat& highResBFMask )
|
||||||
{
|
{
|
||||||
Mat currentTemplateMat;
|
|
||||||
float* currentB;
|
float* currentB;
|
||||||
float* currentC;
|
float* currentC;
|
||||||
Vec2f elem;
|
|
||||||
float currentPixelValue;
|
float currentPixelValue;
|
||||||
float currentEpslonValue;
|
float currentEpslonValue;
|
||||||
bool backgFlag = false;
|
bool backgFlag = false;
|
||||||
|
|
||||||
// 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
|
||||||
|
highResBFMask.create(image.rows, image.cols, CV_8UC1);
|
||||||
highResBFMask.setTo( 1 );
|
highResBFMask.setTo( 1 );
|
||||||
|
|
||||||
// Scan all pixels of image
|
// 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
|
// 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 );
|
currentEpslonValue = epslonPixelsValue.at<float>( i, j );
|
||||||
|
|
||||||
// scan background model vector
|
// scan background model vector
|
||||||
for ( size_t z = 0; z < backgroundModel.size(); z++ )
|
for ( size_t z = 0; z < backgroundModel.size(); z++ )
|
||||||
{
|
{
|
||||||
currentTemplateMat = backgroundModel[z]; // Current Background Model matrix
|
|
||||||
// TODO replace "at" with more efficient matrix access
|
// TODO replace "at" with more efficient matrix access
|
||||||
elem = currentTemplateMat.at<Vec2f>( i, j );
|
currentB = &backgroundModel[z].at<Vec2f>( i, j )[0];
|
||||||
currentB = &elem[0];
|
currentC = &backgroundModel[z].at<Vec2f>( i, j )[1];
|
||||||
currentC = &elem[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 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)
|
// The correspondence pixel in the BF mask is set as background ( 0 value)
|
||||||
// TODO replace "at" with more efficient matrix access
|
// 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
|
*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;
|
backgFlag = true;
|
||||||
//break;
|
//break;
|
||||||
}
|
}
|
||||||
@@ -148,10 +146,10 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( Mat image, Mat highR
|
|||||||
|
|
||||||
}
|
}
|
||||||
} // end "for" cicle of template vector
|
} // end "for" cicle of template vector
|
||||||
|
|
||||||
}
|
}
|
||||||
} // end "for" cicle of all image's pixels
|
} // end "for" cicle of all image's pixels
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool MotionSaliencyBinWangApr2014::lowResolutionDetection( Mat image, Mat lowResBFMask )
|
bool MotionSaliencyBinWangApr2014::lowResolutionDetection( Mat image, Mat lowResBFMask )
|
||||||
@@ -180,6 +178,50 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( Mat finalBFMask )
|
|||||||
bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image, OutputArray saliencyMap )
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user