commented code removed

pull/39/head
jaco 10 years ago
parent 9462b818c7
commit e2fde8a610
  1. 3
      modules/saliency/include/opencv2/saliency/saliencyBaseClasses.hpp
  2. 19
      modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp
  3. 4
      modules/saliency/samples/computeSaliency.cpp
  4. 28
      modules/saliency/src/BING/CmShow.cpp
  5. 40
      modules/saliency/src/BING/kyheader.hpp
  6. 22
      modules/saliency/src/BING/objectnessBING.cpp
  7. 51
      modules/saliency/src/motionSaliencyBinWangApr2014.cpp
  8. 1
      modules/saliency/src/saliency_init.cpp
  9. 1
      modules/saliency/src/staticSaliency.cpp
  10. 9
      modules/saliency/src/staticSaliencySpectralResidual.cpp

@ -75,7 +75,6 @@ class CV_EXPORTS Saliency : public virtual Algorithm
* \param saliencyMap The computed saliency map.
* \return true if the saliency map is computed, false otherwise
*/
//bool computeSaliency( const Mat& image, Mat& saliencyMap );
bool computeSaliency( const InputArray image, OutputArray saliencyMap );
/**
@ -85,7 +84,7 @@ class CV_EXPORTS Saliency : public virtual Algorithm
String getClassName() const;
protected:
//virtual bool computeSaliencyImpl( const Mat& image, Mat& saliencyMap ) = 0;
virtual bool computeSaliencyImpl( const InputArray image, OutputArray saliencyMap ) = 0;
String className;
};

@ -63,7 +63,6 @@ class CV_EXPORTS StaticSaliencySpectralResidual : public StaticSaliency
{
public:
//StaticSaliencySpectralResidual( const StaticSaliencySpectralResidual::Params &parameters = StaticSaliencySpectralResidual::Params() );
StaticSaliencySpectralResidual();
virtual ~StaticSaliencySpectralResidual();
@ -75,7 +74,6 @@ protected:
AlgorithmInfo* info() const;CV_PROP_RW
int resImWidth;
int resImHeight;
//Ptr<Size> resizedImageSize;
};
@ -107,16 +105,11 @@ private:
// classification (and adaptation) functions
bool fullResolutionDetection( const Mat& image, Mat& highResBFMask );
bool lowResolutionDetection( const Mat& image, Mat& lowResBFMask );
//bool templateUpdate( Mat highResBFMask );
// Background model maintenance functions
bool templateOrdering();
bool templateReplacement( const Mat& finalBFMask, const Mat& image );
// Decision threshold adaptation and Activity control function
//bool activityControl(vector<Mat> noisePixelMask);
//bool decisionThresholdAdaptation();
// changing structure
std::vector<Ptr<Mat> > backgroundModel;// The vector represents the background template T0---TK of reference paper.
// Matrices are two-channel matrix. In the first layer there are the B (background value)
@ -124,15 +117,10 @@ private:
Mat potentialBackground;// Two channel Matrix. For each pixel, in the first level there are the Ba value (potential background value)
// and in the secon level there are the Ca value, the counter for each potential value.
Mat epslonPixelsValue; // epslon threshold
//Mat activityPixelsValue; // Activity level of each pixel
//vector<Mat> noisePixelMask; // We define a ‘noise-pixel’ as a pixel that has been classified as a foreground pixel during the full resolution
// detection process,however, after the low resolution detection, it has become a
// background pixel. In a noise-pixel mask, the identified noise-pixels are set to 1 while other pixels are 0;
//fixed parameter
bool neighborhoodCheck;
int N_DS;// Number of template to be downsampled and used in lowResolutionDetection function
//Ptr<Size> imgSize;
int imageWidth;// Width of input image
int imageHeight;//Height of input image
int K;// Number of background model template
@ -144,12 +132,6 @@ private:
int gamma;// Parameter that controls the time that the newly updated long-term background value will remain in the
// long-term template, regardless of any subsequent background changes. A relatively large (eg gamma=3) will
//restrain the generation of ghosts.
//int Ainc; // Activity Incrementation;
//int Bmax; // Upper-bound value for pixel activity
//int Bth; // Max activity threshold
//int Binc, Bdec; // Threshold for pixel-level decision threshold (epslon) adaptation
//int deltaINC, deltaDEC; // Increment-decrement value for epslon adaptation
//int epslonMIN, epslonMAX; // Range values for epslon threshold
};
@ -254,7 +236,6 @@ private:
// List of the rectangles' objectness value, in the same order as
// the vector<Vec4i> objectnessBoundingBox returned by the algorithm (in computeSaliencyImpl function)
std::vector<float> objectnessValues;
//vector<Vec4i> objectnessBoundingBox;
private:
// functions

@ -145,7 +145,7 @@ int main( int argc, char** argv )
if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) )
{
std::cout << "Objectness done" << std::endl;
}
}
@ -169,7 +169,7 @@ int main( int argc, char** argv )
Mat saliencyMap;
if( saliencyAlgorithm->computeSaliency( frame, saliencyMap ) )
{
//std::cout << "motion saliency done" << std::endl;
std::cout << "current frame motion saliency done" << std::endl;
}
imshow( "image", frame );

@ -102,33 +102,5 @@ Mat CmShow::HistBins( CMat& color3f, CMat& val, CStr& title, bool descendShow, C
return showImg3b;
}
/* void CmShow::showTinyMat(CStr &title, CMat &m)
{
int scale = 50, sz = m.rows * m.cols;
while (sz > 200){
scale /= 2;
sz /= 4;
}
Mat img;
resize(m, img, Size(), scale, scale, INTER_NEAREST );
if (img.channels() == 3)
cvtColor(img, img, COLOR_RGB2BGR);
SaveShow(img, title);
}
void CmShow::SaveShow(CMat& img, CStr& title)
{
if (title.size() == 0)
return;
int mDepth = CV_MAT_DEPTH(img.type());
double scale = (mDepth == CV_32F || mDepth == CV_64F ? 255 : 1);
if (title.size() > 4 && title[title.size() - 4] == '.')
imwrite(String(title.c_str()), img*scale);
else if (title.size())
imshow(String(title.c_str()), img);
} */
} // namespace saliency
} // namespace cv

@ -53,11 +53,9 @@
#include <time.h>
#include <fstream>
#include <stdint.h>
//#include <omp.h>
// TODO: reference additional headers your program requires here
//#include "LibLinear/linear.h"
//#include <opencv2/opencv.hpp>
#include "opencv2/core.hpp"
#define CV_VERSION_ID CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) CVAUX_STR(CV_SUBMINOR_VERSION)
@ -67,10 +65,6 @@
#define cvLIB(name) "opencv_" name CV_VERSION_ID
#endif
//#pragma comment( lib, cvLIB("core"))
//#pragma comment( lib, cvLIB("imgproc"))
//#pragma comment( lib, cvLIB("highgui"))
#ifdef WIN32
/* windows stuff */
#else
@ -121,13 +115,6 @@ enum
template<typename T>
static inline int findFromList( const T &word, const std::vector<T> &strList )
{
//TODO delete test code
//cout << "\n\n" << "word" <<" "<< word << endl;
for ( int i = 0; i < strList.size(); i++ )
{
//cout <<"test word:"<< word << " " << endl;
//cout << "Size w " << word.size() << " Size L "<< strList[i].size() << endl;
}
std::vector<cv::String>::iterator it = std::find( strList.begin(), strList.end(), word );
if( it == strList.end() )
@ -138,21 +125,8 @@ static inline int findFromList( const T &word, const std::vector<T> &strList )
{
int index = it - strList.begin();
return index;
//vector<String>::iterator index = std::distance( strList.begin(), it );
//cout << "index" <<" "<< index << endl;
//return int( index );
}
}
/*template<typename T>
static inline int findFromList(const string &word, const vector<T> &strList) {
//for(int i=0; i<strList.size(); i++){
//cout <<"element: " <<strList[i]<<" "<<word << endl;
//if (std::strcmp(word.c_str(),strList[i].c_str())==0) return i;
}
return -1;
}
*/
template<typename T> inline T sqr( T x )
{
@ -174,15 +148,7 @@ inline cv::Rect Vec4i2Rect( cv::Vec4i &v )
{
return cv::Rect( cv::Point( v[0] - 1, v[1] - 1 ), cv::Point( v[2], v[3] ) );
}
/*
#ifdef __WIN32
#define INT64 long long
#else
#define INT64 long
typedef unsigned long UINT64_;
//#define UINT64 unsigned long
#endif
*/
#if defined(_MSC_VER)
# include <intrin.h>
@ -288,6 +254,4 @@ inline int popcnt_byte( register uint32_t u )
}
}
/////
#endif // KYHEADER_H

@ -108,12 +108,9 @@ int ObjectnessBING::loadTrainedModel( std::string modelName ) // Return -1, 0,
return 0;
}
//filters1f = aFilter(0.8f, 8);
//normalize(filters1f, filters1f, p, 1, NORM_MINMAX);
normalize( filters1f, show3u, 1, 255, NORM_MINMAX, CV_8U );
_tigF.update( filters1f );
//_tigF.reconstruct(filters1f);
_svmSzIdxs = idx1i;
CV_Assert( _svmSzIdxs.size() > 1 && filters1f.size() == Size(_W, _W) && filters1f.type() == CV_32F );
@ -146,10 +143,6 @@ void ObjectnessBING::predictBBoxSI( Mat &img3u, ValStructVec<float, Vec4i> &valB
resize( img3u, im3u, Size( cvRound( _W * imgW * 1.0 / width ), cvRound( _W * imgH * 1.0 / height ) ) );
gradientMag( im3u, mag1u );
//Mat mag1f;
//mag1u.convertTo(mag1f, CV_32F);
//matchTemplate(mag1f, _svmFilter, matchCost1f, CV_TM_CCORR);
matchCost1f = _tigF.matchTemplate( mag1u );
ValStructVec<float, Point> matchCost;
@ -449,21 +442,6 @@ bool ObjectnessBING::matRead( const std::string& filename, Mat& _M )
Mat M;
fs2[String( removeExtension( basename( filename ) ).c_str() )] >> M;
/* FILE* f = fopen(_S(filename), "rb");
if (f == NULL)
return false;
char buf[8];
int pre = fread(buf,sizeof(char), 5, f);
if (strncmp(buf, "CmMat", 5) != 0) {
printf("Invalidate CvMat data file %s\n", _S(filename));
return false;
}
int headData[3]; // Width, height, type
fread(headData, sizeof(int), 3, f);
Mat M(headData[1], headData[0], headData[2]);
fread(M.data, sizeof(char), M.step * M.rows, f);
fclose(f); */
M.copyTo( _M );
return true;
}

@ -51,15 +51,6 @@ namespace cv
namespace saliency
{
/* cv::Ptr<Size> MotionSaliencyBinWangApr2014::getWsize()
{
return imgSize;
}
void MotionSaliencyBinWangApr2014::setWsize( const cv::Ptr<Size>& newSize )
{
imgSize = newSize;
} */
void MotionSaliencyBinWangApr2014::setImagesize( int W, int H )
{
imageWidth = W;
@ -91,7 +82,6 @@ bool MotionSaliencyBinWangApr2014::init()
// the position (n / 2) and ((n / 2) +1) (choose their arithmetic mean).
potentialBackground = Mat( imgSize.height, imgSize.width, CV_32FC2, Scalar( NAN, 0 ) );
//backgroundModel = std::vector<Mat>( K + 1, Mat::zeros( imgSize->height, imgSize->width, CV_32FC2 ) );
backgroundModel.resize( K + 1 );
@ -122,17 +112,6 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
float currentEpslonValue;
bool backgFlag = false;
/* for ( int i = 0; i <= K; i++ )
{
vector<Mat> spl;
split( * ( backgroundModel[i] ), spl );
stringstream windowTitle;
windowTitle << "TEST_t" << i << "B";
Mat convert;
spl[0].convertTo( convert, CV_8UC1 );
imshow( windowTitle.str().c_str(), convert );
}*/
// Initially, all pixels are considered as foreground and then we evaluate with the background model
highResBFMask.create( image.rows, image.cols, CV_32F );
highResBFMask.setTo( 1 );
@ -176,12 +155,10 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
//continue;
if( ( *currentC ) > 0 ) //The current template is active
{
//cout<< "DIFFERENCE: "<<abs( currentPixelValue - ( *currentB ) )<<endl;
// If there is a match with a current background template
if( abs( currentPixelValue - ( *currentB ) ) < currentEpslonValue && !backgFlag )
{
// The correspondence pixel in the BF mask is set as background ( 0 value)
//highResBFMask.at<uchar>( i, j ) = 0;
pMask[j] = 0;
if( ( *currentC < L0 && z == 0 ) || ( *currentC < L1 && z == 1 ) || ( z > 1 ) )
{
@ -190,7 +167,6 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
*currentB = ( ( 1 - alpha ) * ( *currentB ) ) + ( alpha * currentPixelValue ); // Update the template value
backgFlag = true;
//break;
}
else
{
@ -347,7 +323,6 @@ bool MotionSaliencyBinWangApr2014::templateOrdering()
}
// SORT Template T0 and T1
//if( backgroundModel[1]->at<Vec2f>( i, j )[1] > thetaL && backgroundModel[0]->at<Vec2f>( i, j )[1] < thetaL )
if( bgModel_1P[j][1] > thetaL && bgModel_0P[j][1] < thetaL )
{
@ -367,17 +342,6 @@ bool MotionSaliencyBinWangApr2014::templateOrdering()
}
bool MotionSaliencyBinWangApr2014::templateReplacement( const Mat& finalBFMask, const Mat& image )
{
/* Mat test( image.rows, image.cols, CV_8U );
for ( int i = 0; i < test.rows; i++ )
{
for ( int j = 0; j < test.cols; j++ )
{
test.at<uchar>( i, j ) = (int) potentialBackground.at<Vec2f>( i, j )[0];
}
}
imshow( "test_BA", test );*/
std::vector<Mat> temp;
split( *backgroundModel[0], temp );
@ -451,9 +415,6 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( const Mat& finalBFMask,
// Neighborhood of current pixel in the current background model template.
// The ROI is centered in the pixel coordinates
/*if( ( i - floor( roiSize / 2 ) >= 0 ) && ( j - floor( roiSize / 2 ) >= 0 )
&& ( i + floor( roiSize / 2 ) <= ( backgroundModel[z].rows - 1 ) )
&& ( j + floor( roiSize / 2 ) <= ( backgroundModel[z].cols - 1 ) ) ) */
if( i > 0 && j > 0 && i < ( backgroundModel[z]->rows - 1 ) && j < ( backgroundModel[z]->cols - 1 ) )
{
split( *backgroundModel[z], mv );
@ -550,27 +511,15 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image,
fullResolutionDetection( image.getMat(), highResBFMask );
lowResolutionDetection( image.getMat(), lowResBFMask );
/*imshow( "highResBFMask", highResBFMask * 255 );
imshow( "lowResBFMask", lowResBFMask * 255 );
*/
// Compute the final background-foreground mask. One pixel is marked as foreground if and only if it is
// foreground in both masks (full and low)
bitwise_and( highResBFMask, lowResBFMask, saliencyMap );
// Detect the noise pixels (i.e. for a given pixel, fullRes(pixel) = foreground and lowRes(pixel)= background)
//bitwise_not( lowResBFMask, not_lowResBFMask );
//bitwise_and( highResBFMask, not_lowResBFMask, noisePixelsMask );
templateOrdering();
templateReplacement( saliencyMap.getMat(), image.getMat() );
templateOrdering();
/* Mat kernel = getStructuringElement( MORPH_RECT, Size( 3, 3 ));
Mat kernel2 = getStructuringElement( MORPH_RECT, Size( 3, 3 ));
morphologyEx(saliencyMap.getMat(), saliencyMap.getMat(), MORPH_OPEN, kernel);
morphologyEx(saliencyMap.getMat(), saliencyMap.getMat(), MORPH_CLOSE, kernel2);*/
return true;
}

@ -50,7 +50,6 @@ namespace saliency
CV_INIT_ALGORITHM( StaticSaliencySpectralResidual, "SALIENCY.SPECTRAL_RESIDUAL",
obj.info()->addParam( obj, "resImWidth", obj.resImWidth); obj.info()->addParam( obj, "resImHeight", obj.resImHeight) );
//CV_INIT_ALGORITHM( MotionSaliencySuBSENSE, "SALIENCY.SuBSENSE", );
CV_INIT_ALGORITHM(
ObjectnessBING, "SALIENCY.BING",

@ -88,7 +88,6 @@ bool StaticSaliency::computeBinaryMap( const Mat& saliencyMap, Mat& BinaryMap )
//Convert
outputMat = outputMat * 255;
outputMat.convertTo( outputMat, CV_8U );
//saliencyMap = outputMat;
// adaptative thresholding using Otsu's method, to make saliency map binary
threshold( outputMat, BinaryMap, 0, 255, THRESH_BINARY | THRESH_OTSU );

@ -50,21 +50,12 @@ namespace saliency
* SaliencySpectralResidual
*/
/*cv::Ptr<Size> StaticSaliencySpectralResidual::getWsize()
{
return resizedImageSize;
}
void StaticSaliencySpectralResidual::setWsize( const cv::Ptr<Size>& newSize )
{
resizedImageSize = newSize;
}*/
StaticSaliencySpectralResidual::StaticSaliencySpectralResidual()
{
className = "SPECTRAL_RESIDUAL";
resImWidth = 64;
resImHeight = 64;
//resizedImageSize = Ptr<Size>( new Size( 64, 64 ) );
}
StaticSaliencySpectralResidual::~StaticSaliencySpectralResidual()

Loading…
Cancel
Save