Commit 071b7ae1 authored by jaco's avatar jaco

Algorithm Params stuff and InputArray/OutputArray added

parent b9e4b3e9
...@@ -73,7 +73,8 @@ class CV_EXPORTS_W Saliency : public virtual Algorithm ...@@ -73,7 +73,8 @@ class CV_EXPORTS_W Saliency : public virtual Algorithm
* \param saliencyMap The computed saliency map. * \param saliencyMap The computed saliency map.
* \return true if the saliency map is computed, false otherwise * \return true if the saliency map is computed, false otherwise
*/ */
bool computeSaliency( const Mat& image, Mat& saliencyMap ); //bool computeSaliency( const Mat& image, Mat& saliencyMap );
bool computeSaliency( const InputArray& image, OutputArray& saliencyMap );
/** /**
* \brief Get the name of the specific saliency type * \brief Get the name of the specific saliency type
...@@ -82,7 +83,8 @@ class CV_EXPORTS_W Saliency : public virtual Algorithm ...@@ -82,7 +83,8 @@ class CV_EXPORTS_W Saliency : public virtual Algorithm
String getClassName() const; String getClassName() const;
protected: protected:
virtual bool computeSaliencyImpl( const Mat& image, Mat& saliencyMap ) = 0; //virtual bool computeSaliencyImpl( const Mat& image, Mat& saliencyMap ) = 0;
virtual bool computeSaliencyImpl( const InputArray& image, OutputArray& saliencyMap ) = 0;
String className; String className;
}; };
...@@ -90,49 +92,32 @@ class CV_EXPORTS_W Saliency : public virtual Algorithm ...@@ -90,49 +92,32 @@ class CV_EXPORTS_W Saliency : public virtual Algorithm
class CV_EXPORTS_W StaticSaliency : public virtual Saliency class CV_EXPORTS_W StaticSaliency : public virtual Saliency
{ {
public: public:
struct CV_EXPORTS Params
{
Params();
};
bool computeBinaryMap( const Mat& saliencyMap, Mat& binaryMap ); bool computeBinaryMap( const Mat& saliencyMap, Mat& binaryMap );
protected: protected:
virtual bool computeSaliencyImpl( const Mat& image, Mat& saliencyMap ) = 0; virtual bool computeSaliencyImpl( const InputArray& image, OutputArray& saliencyMap ) = 0;
private:
Params params;
}; };
/************************************ Motion Saliency Base Class ************************************/ /************************************ Motion Saliency Base Class ************************************/
class CV_EXPORTS_W MotionSaliency : public virtual Saliency class CV_EXPORTS_W MotionSaliency : public virtual Saliency
{ {
public:
// struct CV_EXPORTS Params
// {
// Params();
// };
protected: protected:
virtual bool computeSaliencyImpl( const Mat& image, Mat& saliencyMap ) = 0; virtual bool computeSaliencyImpl( const InputArray& image, OutputArray& saliencyMap ) = 0;
private:
//Params params;
}; };
/************************************ Objectness Base Class ************************************/ /************************************ Objectness Base Class ************************************/
class CV_EXPORTS_W Objectness : public virtual Saliency class CV_EXPORTS_W Objectness : public virtual Saliency
{ {
public:
// struct CV_EXPORTS Params
// {
// Params();
// };
protected: protected:
virtual bool computeSaliencyImpl( const Mat& image, Mat& saliencyMap ) = 0; virtual bool computeSaliencyImpl( const InputArray& image, OutputArray& saliencyMap ) = 0;
private:
//Params params;
}; };
} /* namespace cv */ } /* namespace cv */
......
...@@ -57,30 +57,40 @@ namespace cv ...@@ -57,30 +57,40 @@ namespace cv
/** /**
* \brief Saliency based on algorithms based on [1] * \brief Saliency based on algorithms based on [1]
* [1] Yan, Jia, Xi Chen, and QiuPing Zhu. "Robust online tracking via adaptive samples selection with saliency detection." (2013) * [1]Hou, Xiaodi, and Liqing Zhang. "Saliency detection: A spectral residual approach." Computer Vision and Pattern Recognition, 2007. CVPR'07. IEEE Conference on. IEEE, 2007.
*/ */
class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency
{ {
public: public:
struct CV_EXPORTS Params /*struct CV_EXPORTS Params
{ {
Params(); Params();
Size resizedImageSize; Size resizedImageSize;
void read( const FileNode& fn ); void read( const FileNode& fn );
void write( FileStorage& fs ) const; void write( FileStorage& fs ) const;
}; }; */
StaticSaliencySpectralResidual( const StaticSaliencySpectralResidual::Params &parameters = StaticSaliencySpectralResidual::Params() );
//StaticSaliencySpectralResidual( const StaticSaliencySpectralResidual::Params &parameters = StaticSaliencySpectralResidual::Params() );
StaticSaliencySpectralResidual();
~StaticSaliencySpectralResidual(); ~StaticSaliencySpectralResidual();
typedef cv::Ptr<Size> (cv::Algorithm::*SizeGetter)();
typedef void (cv::Algorithm::*SizeSetter)( const cv::Ptr<Size> & );
cv::Ptr<Size> getWsize();
void setWsize( const cv::Ptr<Size> &arrPtr );
void read( const FileNode& fn ); void read( const FileNode& fn );
void write( FileStorage& fs ) const; void write( FileStorage& fs ) const;
protected: protected:
bool computeSaliencyImpl( const Mat& src, Mat& dst ); bool computeSaliencyImpl( const InputArray& src, OutputArray& dst );
AlgorithmInfo* info() const { return 0; } AlgorithmInfo* info() const; //{ return 0; }
CV_PROP_RW Ptr<Size> resizedImageSize;
private: private:
Params params; //Params params;
}; };
/************************************ Specific Motion Saliency Specialized Classes ************************************/ /************************************ Specific Motion Saliency Specialized Classes ************************************/
...@@ -93,25 +103,26 @@ class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency ...@@ -93,25 +103,26 @@ class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency
class CV_EXPORTS_W MotionSaliencyPBAS : public MotionSaliency class CV_EXPORTS_W MotionSaliencyPBAS : public MotionSaliency
{ {
public: public:
struct CV_EXPORTS Params /* struct CV_EXPORTS Params
{ {
Params(); Params();
void read( const FileNode& fn ); void read( const FileNode& fn );
void write( FileStorage& fs ) const; void write( FileStorage& fs ) const;
}; }; */
MotionSaliencyPBAS( const MotionSaliencyPBAS::Params &parameters = MotionSaliencyPBAS::Params() );
//MotionSaliencyPBAS(); //MotionSaliencyPBAS( const MotionSaliencyPBAS::Params &parameters = MotionSaliencyPBAS::Params() );
MotionSaliencyPBAS();
~MotionSaliencyPBAS(); ~MotionSaliencyPBAS();
void read( const FileNode& fn ); void read( const FileNode& fn );
void write( FileStorage& fs ) const; void write( FileStorage& fs ) const;
protected: protected:
bool computeSaliencyImpl( const Mat& src, Mat& dst ); bool computeSaliencyImpl( const InputArray& src, OutputArray& dst );
AlgorithmInfo* info() const { return 0; } AlgorithmInfo* info() const; // { return 0; }
private: private:
Params params; //Params params;
}; };
/************************************ Specific Objectness Specialized Classes ************************************/ /************************************ Specific Objectness Specialized Classes ************************************/
...@@ -123,25 +134,26 @@ class CV_EXPORTS_W MotionSaliencyPBAS : public MotionSaliency ...@@ -123,25 +134,26 @@ class CV_EXPORTS_W MotionSaliencyPBAS : public MotionSaliency
class CV_EXPORTS_W ObjectnessBING : public Objectness class CV_EXPORTS_W ObjectnessBING : public Objectness
{ {
public: public:
struct CV_EXPORTS Params /*struct CV_EXPORTS Params
{ {
Params(); Params();
void read( const FileNode& fn ); void read( const FileNode& fn );
void write( FileStorage& fs ) const; void write( FileStorage& fs ) const;
}; }; */
ObjectnessBING( const ObjectnessBING::Params &parameters = ObjectnessBING::Params() ); //ObjectnessBING( const ObjectnessBING::Params &parameters = ObjectnessBING::Params() );
//ObjectnessBING(); ObjectnessBING();
~ObjectnessBING(); ~ObjectnessBING();
void read( const FileNode& fn ); void read( const FileNode& fn );
void write( FileStorage& fs ) const; void write( FileStorage& fs ) const;
protected: protected:
bool computeSaliencyImpl( const Mat& src, Mat& dst ); bool computeSaliencyImpl( const InputArray& src, OutputArray& dst );
AlgorithmInfo* info() const { return 0; } AlgorithmInfo* info() const; //{ return 0; }
private: private:
Params params; //Params params;
}; };
} /* namespace cv */ } /* namespace cv */
......
...@@ -50,7 +50,7 @@ namespace cv ...@@ -50,7 +50,7 @@ namespace cv
/** /**
* Parameters * Parameters
*/
MotionSaliencyPBAS::Params::Params() MotionSaliencyPBAS::Params::Params()
{ {
...@@ -65,10 +65,9 @@ void MotionSaliencyPBAS::Params::read( const cv::FileNode& fn ) ...@@ -65,10 +65,9 @@ void MotionSaliencyPBAS::Params::read( const cv::FileNode& fn )
void MotionSaliencyPBAS::Params::write( cv::FileStorage& fs ) const void MotionSaliencyPBAS::Params::write( cv::FileStorage& fs ) const
{ {
//fs << "resizedImageSize" << resizedImageSize; //fs << "resizedImageSize" << resizedImageSize;
} } */
MotionSaliencyPBAS::MotionSaliencyPBAS(const MotionSaliencyPBAS::Params &parameters ) : MotionSaliencyPBAS::MotionSaliencyPBAS()
params( parameters )
{ {
className = "PBAS"; className = "PBAS";
} }
...@@ -80,15 +79,15 @@ MotionSaliencyPBAS::~MotionSaliencyPBAS() ...@@ -80,15 +79,15 @@ MotionSaliencyPBAS::~MotionSaliencyPBAS()
void MotionSaliencyPBAS::read( const cv::FileNode& fn ) void MotionSaliencyPBAS::read( const cv::FileNode& fn )
{ {
params.read( fn ); //params.read( fn );
} }
void MotionSaliencyPBAS::write( cv::FileStorage& fs ) const void MotionSaliencyPBAS::write( cv::FileStorage& fs ) const
{ {
params.write( fs ); //params.write( fs );
} }
bool MotionSaliencyPBAS::computeSaliencyImpl( const Mat& image, Mat& saliencyMap ) bool MotionSaliencyPBAS::computeSaliencyImpl( const InputArray& src, OutputArray& dst )
{ {
return true; return true;
......
...@@ -50,7 +50,7 @@ namespace cv ...@@ -50,7 +50,7 @@ namespace cv
/** /**
* Parameters * Parameters
*/
ObjectnessBING::Params::Params() ObjectnessBING::Params::Params()
{ {
...@@ -65,10 +65,9 @@ void ObjectnessBING::Params::read( const cv::FileNode& fn ) ...@@ -65,10 +65,9 @@ void ObjectnessBING::Params::read( const cv::FileNode& fn )
void ObjectnessBING::Params::write( cv::FileStorage& fs ) const void ObjectnessBING::Params::write( cv::FileStorage& fs ) const
{ {
//fs << "resizedImageSize" << resizedImageSize; //fs << "resizedImageSize" << resizedImageSize;
} } */
ObjectnessBING::ObjectnessBING( const ObjectnessBING::Params &parameters ) : ObjectnessBING::ObjectnessBING()
params( parameters )
{ {
className = "BING"; className = "BING";
} }
...@@ -80,15 +79,15 @@ ObjectnessBING::~ObjectnessBING() ...@@ -80,15 +79,15 @@ ObjectnessBING::~ObjectnessBING()
void ObjectnessBING::read( const cv::FileNode& fn ) void ObjectnessBING::read( const cv::FileNode& fn )
{ {
params.read( fn ); //params.read( fn );
} }
void ObjectnessBING::write( cv::FileStorage& fs ) const void ObjectnessBING::write( cv::FileStorage& fs ) const
{ {
params.write( fs ); //params.write( fs );
} }
bool ObjectnessBING::computeSaliencyImpl( const Mat& image, Mat& saliencyMap ) bool ObjectnessBING::computeSaliencyImpl( const InputArray& src, OutputArray& dst )
{ {
return true; return true;
......
...@@ -51,7 +51,7 @@ Saliency::~Saliency() ...@@ -51,7 +51,7 @@ Saliency::~Saliency()
Ptr<Saliency> Saliency::create( const String& saliencyType ) Ptr<Saliency> Saliency::create( const String& saliencyType )
{ {
if( saliencyType.find( "STATIC_SALIENCY.SPECTRAL_RESIDUAL" ) == 0 ) /*if( saliencyType.find( "STATIC_SALIENCY.SPECTRAL_RESIDUAL" ) == 0 )
{ {
return Ptr < Saliency > ( new StaticSaliencySpectralResidual() ); return Ptr < Saliency > ( new StaticSaliencySpectralResidual() );
} }
...@@ -66,13 +66,15 @@ Ptr<Saliency> Saliency::create( const String& saliencyType ) ...@@ -66,13 +66,15 @@ Ptr<Saliency> Saliency::create( const String& saliencyType )
else if( saliencyType.find( "OBJECTNESS.BING" ) == 0 ) else if( saliencyType.find( "OBJECTNESS.BING" ) == 0 )
{ {
return Ptr < Saliency > ( new ObjectnessBING() ); return Ptr < Saliency > ( new ObjectnessBING() );
} } */
return Algorithm::create<Saliency>( "SALIENCY." + saliencyType );
CV_Error( -1, "Saliency algorithm type " + saliencyType + " not supported" ); //CV_Error( -1, "Saliency algorithm type " + saliencyType + " not supported" );
return Ptr<Saliency>(); //return Ptr<Saliency>();
} }
bool Saliency::computeSaliency( const Mat& image, Mat& saliencyMap ) bool Saliency::computeSaliency( const InputArray& image, OutputArray& saliencyMap )
{ {
if( image.empty() ) if( image.empty() )
return false; return false;
......
...@@ -45,15 +45,19 @@ ...@@ -45,15 +45,19 @@
namespace cv namespace cv
{ {
//CV_INIT_ALGORITHM(TrackerMIL, "TRACKER.MIL",); CV_INIT_ALGORITHM( StaticSaliencySpectralResidual, "SALIENCY.SPECTRAL_RESIDUAL",
obj.info()->addParam(obj, "resizedImageSize", obj.resizedImageSize, false, reinterpret_cast<SizeGetter>(&StaticSaliencySpectralResidual::getWsize), reinterpret_cast<SizeSetter>(&StaticSaliencySpectralResidual::setWsize)));
//CV_INIT_ALGORITHM(TrackerBoosting, "TRACKER.BOOSTING",); CV_INIT_ALGORITHM( MotionSaliencyPBAS, "SALIENCY.PBAS",);
bool initModule_saliency(void) CV_INIT_ALGORITHM( ObjectnessBING, "SALIENCY.BING", );
bool initModule_saliency( void )
{ {
bool all = true; bool all = true;
//all &= !TrackerMIL_info_auto.name().empty(); all &= !StaticSaliencySpectralResidual_info_auto.name().empty();
//all &= !TrackerBoosting_info_auto.name().empty(); all &= !MotionSaliencyPBAS_info_auto.name().empty();
all &= !ObjectnessBING_info_auto.name().empty();
return all; return all;
} }
......
...@@ -50,12 +50,12 @@ namespace cv ...@@ -50,12 +50,12 @@ namespace cv
/** /**
* Parameters * Parameters
*/
StaticSaliency::Params::Params() StaticSaliency::Params::Params()
{ {
} } */
bool StaticSaliency::computeBinaryMap( const Mat& saliencyMap, Mat& BinaryMap ) bool StaticSaliency::computeBinaryMap( const Mat& saliencyMap, Mat& BinaryMap )
{ {
......
...@@ -50,7 +50,7 @@ namespace cv ...@@ -50,7 +50,7 @@ namespace cv
/** /**
* Parameters * Parameters
*/
StaticSaliencySpectralResidual::Params::Params() StaticSaliencySpectralResidual::Params::Params()
{ {
...@@ -66,12 +66,20 @@ void StaticSaliencySpectralResidual::Params::read( const cv::FileNode& fn ) ...@@ -66,12 +66,20 @@ void StaticSaliencySpectralResidual::Params::read( const cv::FileNode& fn )
void StaticSaliencySpectralResidual::Params::write( cv::FileStorage& fs ) const void StaticSaliencySpectralResidual::Params::write( cv::FileStorage& fs ) const
{ {
//fs << "resizedImageSize" << resizedImageSize; //fs << "resizedImageSize" << resizedImageSize;
} */
cv::Ptr<Size> StaticSaliencySpectralResidual::getWsize(){
return resizedImageSize;
} }
void StaticSaliencySpectralResidual::setWsize(const cv::Ptr<Size>& newSize){
resizedImageSize = newSize;
}
StaticSaliencySpectralResidual::StaticSaliencySpectralResidual( const StaticSaliencySpectralResidual::Params &parameters ) : StaticSaliencySpectralResidual::StaticSaliencySpectralResidual()
params( parameters )
{ {
className = "SPECTRAL_RESIDUAL"; className = "SPECTRAL_RESIDUAL";
resizedImageSize=Ptr<Size>(new Size(64,64));
} }
StaticSaliencySpectralResidual::~StaticSaliencySpectralResidual() StaticSaliencySpectralResidual::~StaticSaliencySpectralResidual()
...@@ -81,37 +89,36 @@ StaticSaliencySpectralResidual::~StaticSaliencySpectralResidual() ...@@ -81,37 +89,36 @@ StaticSaliencySpectralResidual::~StaticSaliencySpectralResidual()
void StaticSaliencySpectralResidual::read( const cv::FileNode& fn ) void StaticSaliencySpectralResidual::read( const cv::FileNode& fn )
{ {
params.read( fn ); //params.read( fn );
} }
void StaticSaliencySpectralResidual::write( cv::FileStorage& fs ) const void StaticSaliencySpectralResidual::write( cv::FileStorage& fs ) const
{ {
params.write( fs ); //params.write( fs );
} }
bool StaticSaliencySpectralResidual::computeSaliencyImpl( const Mat& image, Mat& saliencyMap ) bool StaticSaliencySpectralResidual::computeSaliencyImpl( const InputArray& image, OutputArray& saliencyMap )
{ {
Mat grayTemp, grayDown; Mat grayTemp, grayDown;
std::vector<Mat> mv; std::vector<Mat> mv;
Mat realImage( params.resizedImageSize, CV_64F ); Mat realImage(*resizedImageSize, CV_64F );
Mat imaginaryImage( params.resizedImageSize, CV_64F ); Mat imaginaryImage( *resizedImageSize, CV_64F );
imaginaryImage.setTo( 0 ); imaginaryImage.setTo( 0 );
Mat combinedImage( params.resizedImageSize, CV_64FC2 ); Mat combinedImage( *resizedImageSize, CV_64FC2 );
Mat imageDFT; Mat imageDFT;
Mat logAmplitude; Mat logAmplitude;
Mat angle( params.resizedImageSize, CV_64F ); Mat angle( *resizedImageSize, CV_64F );
Mat magnitude( params.resizedImageSize, CV_64F ); Mat magnitude( *resizedImageSize, CV_64F );
Mat logAmplitude_blur, imageGR; Mat logAmplitude_blur, imageGR;
if( image.channels() == 3 ) if( image.channels() == 3 )
{ {
cvtColor( image, imageGR, COLOR_BGR2GRAY ); cvtColor( image, imageGR, COLOR_BGR2GRAY );
resize( imageGR, grayDown, params.resizedImageSize, 0, 0, INTER_LINEAR ); resize( imageGR, grayDown, *resizedImageSize, 0, 0, INTER_LINEAR );
} }
else else
{ {
resize( image, grayDown, params.resizedImageSize, 0, 0, INTER_LINEAR ); resize( image, grayDown, *resizedImageSize, 0, 0, INTER_LINEAR );
} }
grayDown.convertTo( realImage, CV_64F ); grayDown.convertTo( realImage, CV_64F );
...@@ -148,8 +155,8 @@ bool StaticSaliencySpectralResidual::computeSaliencyImpl( const Mat& image, Mat& ...@@ -148,8 +155,8 @@ bool StaticSaliencySpectralResidual::computeSaliencyImpl( const Mat& image, Mat&
resize( magnitude, saliencyMap, image.size(), 0, 0, INTER_LINEAR ); resize( magnitude, saliencyMap, image.size(), 0, 0, INTER_LINEAR );
#ifdef SALIENCY_DEBUG #ifdef SALIENCY_DEBUG
// visualize saliency map before and after K-means // visualize saliency map
imshow( "Saliency Map", saliencyMap ); imshow( "Saliency Map Interna", saliencyMap );
#endif #endif
......
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