mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-23 00:49:38 +08:00
templateOrdering bug fixed
This commit is contained in:
@@ -156,12 +156,12 @@ int main( int argc, char** argv )
|
|||||||
}
|
}
|
||||||
else if( saliency_algorithm.find( "BinWangApr2014" ) == 0 )
|
else if( saliency_algorithm.find( "BinWangApr2014" ) == 0 )
|
||||||
{
|
{
|
||||||
Ptr<Size> size= Ptr<Size>( new Size( 64, 64 ) ) ;
|
Ptr<Size> size= Ptr<Size>( new Size( 32, 32 ) ) ;
|
||||||
saliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->setWsize(size);
|
saliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->setWsize(size);
|
||||||
saliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->init();
|
saliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->init();
|
||||||
|
|
||||||
// Create an fake image test
|
// Create an fake image test
|
||||||
Mat test( 64, 64, CV_8U );
|
Mat test( 32, 32, CV_8U );
|
||||||
RNG rand;
|
RNG rand;
|
||||||
for(int i=0; i<test.rows; i++)
|
for(int i=0; i<test.rows; i++)
|
||||||
for(int j=0; j<test.cols; j++)
|
for(int j=0; j<test.cols; j++)
|
||||||
|
@@ -252,28 +252,29 @@ bool inline pairCompare( pair<float, float> t, pair<float, float> t_plusOne )
|
|||||||
bool MotionSaliencyBinWangApr2014::templateOrdering()
|
bool MotionSaliencyBinWangApr2014::templateOrdering()
|
||||||
{
|
{
|
||||||
vector<pair<float, float> > pixelTemplates( backgroundModel.size() );
|
vector<pair<float, float> > pixelTemplates( backgroundModel.size() );
|
||||||
|
float temp;
|
||||||
|
|
||||||
// Scan all pixels of image
|
// Scan all pixels of image
|
||||||
for ( int i = 0; i < backgroundModel[0].rows; i++ )
|
for ( int i = 0; i < backgroundModel[0].rows; i++ )
|
||||||
{
|
{
|
||||||
for ( int j = 0; j < backgroundModel[0].cols; j++ )
|
for ( int j = 0; j < backgroundModel[0].cols; j++ )
|
||||||
{
|
{
|
||||||
// scan background model vector from T2 to Tk
|
// scan background model vector from T1 to Tk
|
||||||
for ( size_t z = 2; z < backgroundModel.size(); z++ )
|
for ( size_t z = 1; z < backgroundModel.size(); z++ )
|
||||||
{
|
{
|
||||||
// Fill vector of pairs
|
// Fill vector of pairs
|
||||||
pixelTemplates[z - 2].first = backgroundModel[z].at<Vec2f>( i, j )[0]; // Current B (background value)
|
pixelTemplates[z - 1].first = backgroundModel[z].at<Vec2f>( i, j )[0]; // Current B (background value)
|
||||||
pixelTemplates[z - 2].second = backgroundModel[z].at<Vec2f>( i, j )[1]; // Current C (efficacy value)
|
pixelTemplates[z - 1].second = backgroundModel[z].at<Vec2f>( i, j )[1]; // Current C (efficacy value)
|
||||||
}
|
}
|
||||||
|
|
||||||
//SORT template from T2 to Tk
|
//SORT template from T1 to Tk
|
||||||
std::sort( pixelTemplates.begin(), pixelTemplates.end(), pairCompare );
|
std::sort( pixelTemplates.begin(), pixelTemplates.end(), pairCompare );
|
||||||
|
|
||||||
//REFILL CURRENT MODEL ( T2...Tk)
|
//REFILL CURRENT MODEL ( T1...Tk)
|
||||||
for ( size_t zz = 2; zz < backgroundModel.size(); zz++ )
|
for ( size_t zz = 1; zz < backgroundModel.size(); zz++ )
|
||||||
{
|
{
|
||||||
backgroundModel[zz].at<Vec2f>( i, j )[0] = pixelTemplates[zz - 2].first; // Replace previous B with new ordered B value
|
backgroundModel[zz].at<Vec2f>( i, j )[0] = pixelTemplates[zz - 1].first; // Replace previous B with new ordered B value
|
||||||
backgroundModel[zz].at<Vec2f>( i, j )[1] = pixelTemplates[zz - 2].second; // Replace previous C with new ordered C value
|
backgroundModel[zz].at<Vec2f>( i, j )[1] = pixelTemplates[zz - 1].second; // Replace previous C with new ordered C value
|
||||||
}
|
}
|
||||||
|
|
||||||
// SORT Template T0 and T1
|
// SORT Template T0 and T1
|
||||||
@@ -281,10 +282,15 @@ bool MotionSaliencyBinWangApr2014::templateOrdering()
|
|||||||
{
|
{
|
||||||
|
|
||||||
// swap B value of T0 with B value of T1 (for current model)
|
// swap B value of T0 with B value of T1 (for current model)
|
||||||
|
temp = backgroundModel[0].at<Vec2f>( i, j )[0];
|
||||||
backgroundModel[0].at<Vec2f>( i, j )[0] = backgroundModel[1].at<Vec2f>( i, j )[0];
|
backgroundModel[0].at<Vec2f>( i, j )[0] = backgroundModel[1].at<Vec2f>( i, j )[0];
|
||||||
|
backgroundModel[1].at<Vec2f>( i, j )[0] = temp;
|
||||||
|
|
||||||
// set new C0 value for current model)
|
// set new C0 value for current model)
|
||||||
|
temp = backgroundModel[0].at<Vec2f>( i, j )[1];
|
||||||
backgroundModel[0].at<Vec2f>( i, j )[1] = gamma * thetaL;
|
backgroundModel[0].at<Vec2f>( i, j )[1] = gamma * thetaL;
|
||||||
|
backgroundModel[1].at<Vec2f>( i, j )[1] = temp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -300,14 +306,15 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( Mat finalBFMask )
|
|||||||
|
|
||||||
bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image, OutputArray saliencyMap )
|
bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image, OutputArray saliencyMap )
|
||||||
{
|
{
|
||||||
|
|
||||||
Mat highResBFMask;
|
Mat highResBFMask;
|
||||||
Mat lowResBFMask;
|
Mat lowResBFMask;
|
||||||
Mat not_lowResBFMask;
|
Mat not_lowResBFMask;
|
||||||
Mat finalBFMask;
|
Mat finalBFMask;
|
||||||
Mat noisePixelsMask;
|
Mat noisePixelsMask;
|
||||||
Mat t( image.getMat().rows, image.getMat().cols, CV_32FC2 );
|
/*Mat t( image.getMat().rows, image.getMat().cols, CV_32FC2 );
|
||||||
t.setTo( 50 );
|
t.setTo( 50 );
|
||||||
backgroundModel.at( 0 ) = t;
|
backgroundModel.at( 0 ) = t; */
|
||||||
|
|
||||||
fullResolutionDetection( image.getMat(), highResBFMask );
|
fullResolutionDetection( image.getMat(), highResBFMask );
|
||||||
lowResolutionDetection( image.getMat(), lowResBFMask );
|
lowResolutionDetection( image.getMat(), lowResBFMask );
|
||||||
@@ -316,51 +323,13 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image,
|
|||||||
// foreground in both masks (full and low)
|
// foreground in both masks (full and low)
|
||||||
bitwise_and( highResBFMask, lowResBFMask, finalBFMask );
|
bitwise_and( highResBFMask, lowResBFMask, finalBFMask );
|
||||||
|
|
||||||
//imshow("finalBFMask",finalBFMask*255);
|
|
||||||
|
|
||||||
// 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 );
|
||||||
//imshow("noisePixelsMask",noisePixelsMask*255);
|
|
||||||
//waitKey(0);
|
|
||||||
|
|
||||||
templateOrdering();
|
templateOrdering();
|
||||||
|
|
||||||
std::ofstream ofs;
|
|
||||||
ofs.open( "highResBFMask.txt", std::ofstream::out );
|
|
||||||
|
|
||||||
for ( int i = 0; i < highResBFMask.rows; i++ )
|
|
||||||
{
|
|
||||||
for ( int j = 0; j < highResBFMask.cols; j++ )
|
|
||||||
{
|
|
||||||
//highResBFMask.at<int>( i, j ) = i + j;
|
|
||||||
stringstream str;
|
|
||||||
str << (int) highResBFMask.at<uchar>( i, j ) << " ";
|
|
||||||
ofs << str.str();
|
|
||||||
}
|
|
||||||
stringstream str2;
|
|
||||||
str2 << "\n";
|
|
||||||
ofs << str2.str();
|
|
||||||
}
|
|
||||||
ofs.close();
|
|
||||||
|
|
||||||
std::ofstream ofs2;
|
|
||||||
ofs2.open( "lowResBFMask.txt", std::ofstream::out );
|
|
||||||
|
|
||||||
for ( int i = 0; i < lowResBFMask.rows; i++ )
|
|
||||||
{
|
|
||||||
for ( int j = 0; j < lowResBFMask.cols; j++ )
|
|
||||||
{
|
|
||||||
stringstream str;
|
|
||||||
str << (int) lowResBFMask.at<uchar>( i, j ) << " ";
|
|
||||||
ofs2 << str.str();
|
|
||||||
}
|
|
||||||
stringstream str2;
|
|
||||||
str2 << "\n";
|
|
||||||
ofs2 << str2.str();
|
|
||||||
}
|
|
||||||
ofs2.close();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user