Commit b78f7136 authored by jaco's avatar jaco

lowResolutionDetection bug fixed

parent 7e589c5b
...@@ -156,10 +156,29 @@ int main( int argc, char** argv ) ...@@ -156,10 +156,29 @@ 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 ) ) ;
saliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->setWsize(size);
saliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->init();
// Create an fake image test
Mat test( 64, 64, CV_8U );
RNG rand;
for(int i=0; i<test.rows; i++)
for(int j=0; j<test.cols; j++)
{
if(i<12 && i>=6 && j<12 && j>=6)
test.at<uchar>(i,j)=255;
else
test.at<uchar>(i,j)=rand.uniform(40,60);
}
//imshow("Test", test);
//waitKey(0);
Mat saliencyMap; Mat saliencyMap;
if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) ) if( saliencyAlgorithm->computeSaliency( test, saliencyMap ) )
{ {
std::cout<<"OKKKK"<<std::endl; std::cout<<"motion saliency done"<<std::endl;
} }
} }
......
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
//M*/ //M*/
#include "precomp.hpp" #include "precomp.hpp"
//TODO delete highgui include
#include <opencv2/highgui.hpp>
namespace cv namespace cv
{ {
...@@ -74,11 +76,13 @@ bool MotionSaliencyBinWangApr2014::init() ...@@ -74,11 +76,13 @@ bool MotionSaliencyBinWangApr2014::init()
epslonPixelsValue = Mat( imgSize->height, imgSize->width, CV_32F ); epslonPixelsValue = Mat( imgSize->height, imgSize->width, CV_32F );
potentialBackground = Mat( imgSize->height, imgSize->width, CV_32FC2 ); potentialBackground = Mat( imgSize->height, imgSize->width, CV_32FC2 );
backgroundModel = std::vector<Mat>( K + 1, Mat::zeros( imgSize->height, imgSize->width, CV_32FC2 ) ); backgroundModel = std::vector<Mat>( K + 1, Mat::zeros( imgSize->height, imgSize->width, CV_32FC2 ) );
//TODO set to nan
potentialBackground.setTo( 0 );
potentialBackground.setTo( NAN ); //TODO set to nan
for ( size_t i = 0; i < backgroundModel.size(); i++ ){
for ( size_t i = 0; i < backgroundModel.size(); i++ ) backgroundModel[i].setTo( 0 );
backgroundModel[i].setTo( NAN ); }
epslonPixelsValue.setTo( 48.5 ); // Median of range [18, 80] advised in reference paper. epslonPixelsValue.setTo( 48.5 ); // Median of range [18, 80] advised in reference paper.
// Since data is even, the median is estimated using two values ​​that occupy // Since data is even, the median is estimated using two values ​​that occupy
...@@ -157,7 +161,6 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image, Ma ...@@ -157,7 +161,6 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image, Ma
return true; return true;
} }
//typedef Rect_<uint> Rect;
bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat& lowResBFMask ) bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat& lowResBFMask )
{ {
float currentPixelValue; float currentPixelValue;
...@@ -175,13 +178,16 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat ...@@ -175,13 +178,16 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat
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.size().height / ( N * N ), image.size().width / ( N * N ), CV_8UC1 );
//lowResBFMask.setTo( 1 );
lowResBFMask.create( image.rows, image.cols, CV_8UC1 );
lowResBFMask.setTo( 1 ); lowResBFMask.setTo( 1 );
// Scan all the ROI of original matrices that correspond to the pixels of new resized matrices // Scan all the ROI of original matrices that correspond to the pixels of new resized matrices
for ( int i = 0; i < image.rows/( N * N ); i++ ) for ( int i = 0; i < image.rows / N; i++ )
{ {
for ( int j = 0; j < image.cols/( N * N ); j++ ) for ( int j = 0; j < image.cols / N; j++ )
{ {
// Reset and update ROI mask // Reset and update ROI mask
ROIMask.setTo( 0 ); ROIMask.setTo( 0 );
...@@ -207,21 +213,23 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat ...@@ -207,21 +213,23 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat
{ {
// 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
lowResBFMask.at<uchar>( i, j ) = 0; //lowResBFMask.at<uchar>( i, j ) = 0;
lowResBFMask.setTo( 0, ROIMask );
break; break;
} }
} }
} }
// Shift the ROI from left to right follow the block dimension // Shift the ROI from left to right follow the block dimension
roi = roi + Point( 0, N ); roi = roi + Point( N, 0 );
} }
//Shift the ROI from up to down follow the block dimension, also bringing it back to beginning of row //Shift the ROI from up to down follow the block dimension, also bringing it back to beginning of row
roi = roi + Point( N, - ( image.cols - N ) ); roi.x = 0;
roi.y += N;
} }
// UPSAMPLE the lowResBFMask to the original image dimension, so that it's then possible to compare the results // UPSAMPLE the lowResBFMask to the original image dimension, so that it's then possible to compare the results
// of lowlResolutionDetection with the fullResolutionDetection // of lowlResolutionDetection with the fullResolutionDetection
resize( lowResBFMask, lowResBFMask, image.size(), 0, 0, INTER_LINEAR ); //resize( lowResBFMask, lowResBFMask, image.size(), 0, 0, INTER_LINEAR );
return true; return true;
} }
...@@ -246,20 +254,25 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( Mat finalBFMask ) ...@@ -246,20 +254,25 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( Mat finalBFMask )
bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image, OutputArray saliencyMap ) bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image, OutputArray saliencyMap )
{ {
Mat highResBFMask;
Mat lowResBFMask;
Mat t( image.getMat().rows, image.getMat().cols, CV_32FC2 );
t.setTo( 50 );
backgroundModel.at( 0 ) = t;
Mat Test( 36, 36, CV_32F ); fullResolutionDetection( image.getMat(), highResBFMask );
Mat Results; lowResolutionDetection( image.getMat(), lowResBFMask );
std::ofstream ofs; std::ofstream ofs;
ofs.open( "TEST.txt", std::ofstream::out ); ofs.open( "highResBFMask.txt", std::ofstream::out );
for ( int i = 0; i < Test.size().height; i++ ) for ( int i = 0; i < highResBFMask.rows; i++ )
{ {
for ( int j = 0; j < Test.size().width; j++ ) for ( int j = 0; j < highResBFMask.cols; j++ )
{ {
Test.at<float>( i, j ) = i + j; //highResBFMask.at<int>( i, j ) = i + j;
stringstream str; stringstream str;
str << i + j << " "; str << (int) highResBFMask.at<uchar>( i, j ) << " ";
ofs << str.str(); ofs << str.str();
} }
stringstream str2; stringstream str2;
...@@ -268,19 +281,15 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image, ...@@ -268,19 +281,15 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image,
} }
ofs.close(); 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; std::ofstream ofs2;
ofs2.open( "RESULTS.txt", std::ofstream::out ); ofs2.open( "lowResBFMask.txt", std::ofstream::out );
for ( int i = 0; i < Results.size().height; i++ ) for ( int i = 0; i < lowResBFMask.rows; i++ )
{ {
for ( int j = 0; j < Results.size().width; j++ ) for ( int j = 0; j < lowResBFMask.cols; j++ )
{ {
stringstream str; stringstream str;
str << Results.at<float>( i, j ) << " "; str << (int) lowResBFMask.at<uchar>( i, j ) << " ";
ofs2 << str.str(); ofs2 << str.str();
} }
stringstream str2; stringstream str2;
...@@ -289,8 +298,50 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image, ...@@ -289,8 +298,50 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image,
} }
ofs2.close(); ofs2.close();
std::cout << "TEST SIZE: " << Test.size().height << " " << Test.size().width << " RESULTS SIZE: " << Results.size().height << " " /*Mat Test( 16, 16, CV_32F );
<< Results.size().width << std::endl; 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;
} }
......
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