Commit 6bf41074 authored by jaco's avatar jaco

init and fullResolutionDetection function completed

parent 4b1d0c21
......@@ -105,6 +105,8 @@ class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency
Ptr<Size> getWsize();
void setWsize( const Ptr<Size> &newSize );
bool init();
protected:
bool computeSaliencyImpl( const InputArray image, OutputArray saliencyMap );
AlgorithmInfo* info() const;
......
......@@ -56,10 +56,6 @@ void MotionSaliencyBinWangApr2014::setWsize( const cv::Ptr<Size>& newSize )
MotionSaliencyBinWangApr2014::MotionSaliencyBinWangApr2014()
{
epslonPixelsValue = Mat::zeros( imgSize->height, imgSize->width, CV_8U );
potentialBackground = Mat::zeros( imgSize->height, imgSize->width, CV_32FC2 );
backgroundModel=std::vector<Mat>( 4, Mat::zeros( imgSize->height, imgSize->width, CV_32FC2 ) );
K = 3; // Number of background model template
alpha = 0.01; // Learning rate
L0 = 6000; // Upper-bound values for C0 (efficacy of the first template (matrices) of backgroundModel
......@@ -71,6 +67,30 @@ MotionSaliencyBinWangApr2014::MotionSaliencyBinWangApr2014()
className = "BinWangApr2014";
}
bool MotionSaliencyBinWangApr2014::init()
{
epslonPixelsValue = Mat( imgSize->height, imgSize->width, CV_32F );
potentialBackground = Mat( imgSize->height, imgSize->width, CV_32FC2 );
backgroundModel = std::vector<Mat>( K + 1, Mat::zeros( imgSize->height, imgSize->width, CV_32FC2 ) );
potentialBackground.setTo( NAN );
for ( size_t i = 0; i < backgroundModel.size(); i++ )
backgroundModel[i].setTo( NAN );
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
// the position (n / 2) and ((n / 2) +1) (choose their arithmetic mean).
/* epslonPixelsValue = Mat::zeros( imgSize->height, imgSize->width, CV_8U );
potentialBackground = Mat::NAN( imgSize->height, imgSize->width, CV_32FC2 );
backgroundModel = std::vector<Mat>( 4, Mat::zeros( imgSize->height, imgSize->width, CV_32FC2 ) );*/
return true;
}
MotionSaliencyBinWangApr2014::~MotionSaliencyBinWangApr2014()
{
......@@ -79,6 +99,58 @@ MotionSaliencyBinWangApr2014::~MotionSaliencyBinWangApr2014()
// classification (and adaptation) functions
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.setTo( 1 );
// Scan all pixels of image
for ( size_t i = 0; i < image.size().width; i++ )
{
for ( size_t j = 0; j < image.size().height; j++ )
{
// TODO replace "at" with more efficient matrix access
currentPixelValue = image.at<float>( 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];
if( currentC > 0 ) //The current template is active
{
// If there is a match with a current background template
if( abs( currentPixelValue - currentB ) < currentEpslonValue )
{
// 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;
// backgFlag=true;
break;
}
}
} // end "for" cicle of template vector
// if the pixel has not matched with none of the active background models, is set as the foreground
// in the high resolution mask
//if(!backgFlag)
// highResBFMask.at<int>( i, j ) = 1;
}
} // end "for" cicle of all image's pixels
//////// THERE WE CALL THE templateUpdate FUNCTION (to be implemented) ////////
templateUpdate(highResBFMask);
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