diff --git a/modules/saliency/doc/common_interfaces_saliency.rst b/modules/saliency/doc/common_interfaces_saliency.rst new file mode 100644 index 000000000..34193e351 --- /dev/null +++ b/modules/saliency/doc/common_interfaces_saliency.rst @@ -0,0 +1,67 @@ +Common Interfaces of Saliency +============================ + +.. highlight:: cpp + + +Saliency : Algorithm +------------------- + +.. ocv:class:: Saliency + +Base abstract class for Saliency algorithms:: + + class CV_EXPORTS_W Saliency : public virtual Algorithm + { + public: + + virtual ~Saliency(); + + static Ptr create( const String& saliencyType ); + + bool computeSaliency( const InputArray image, OutputArray saliencyMap ); + + String getClassName() const; + }; + + +Saliency::create +--------------- + +Creates a specialized saliency algorithm by its name. + +.. ocv:function:: static Ptr create( const String& saliencyType ); + + :param saliencyType: saliency Type + +The following saliency types are now supported: + +* ``"SPECTRAL_RESIDUAL"`` -- :ocv:class:`StaticSaliencySpectralResidual` + +* ``"BING"`` -- :ocv:class:`ObjectnessBING` + + +Saliency::computeSaliency +------------------------ + +Performs all the operations, according to the specific algorithm created, to obtain the saliency map. + +.. ocv:function:: bool computeSaliency( const InputArray image, OutputArray saliencyMap ); + + :param image: image or set of input images. According to InputArray proxy and to the needs of different algorithms (currently plugged), the param image may be Mat or vector + :param saliencyMap: saliency map. According to OutputArray proxy and to the results given by different algorithms (currently plugged), the saliency map may be a Mat or vector (BING results). + +Saliency::getClassName +--------------------- + +Get the name of the specific Saliency Algorithm. + +.. ocv:function:: String getClassName() const; + + + + + + + + diff --git a/modules/saliency/doc/common_interfaces_saliency.rst~ b/modules/saliency/doc/common_interfaces_saliency.rst~ new file mode 100644 index 000000000..6f5159ac4 --- /dev/null +++ b/modules/saliency/doc/common_interfaces_saliency.rst~ @@ -0,0 +1,67 @@ +Common Interfaces of Saliency +============================ + +.. highlight:: cpp + + +Saliency : Algorithm +------------------- + +.. ocv:class:: Saliency + +Base abstract class for Saliency algorithms:: + +class CV_EXPORTS_W Saliency : public virtual Algorithm +{ + public: + + virtual ~Saliency(); + + static Ptr create( const String& saliencyType ); + + bool computeSaliency( const InputArray image, OutputArray saliencyMap ); + + String getClassName() const; +}; + + +Saliency::create +--------------- + +Creates a specialized saliency algorithm by its name. + +.. ocv:function:: static Ptr create( const String& saliencyType ); + + :param saliencyType: saliency Type + +The following saliency types are now supported: + +* ``"SPECTRAL_RESIDUAL"`` -- :ocv:class:`StaticSaliencySpectralResidual` + +* ``"BING"`` -- :ocv:class:`ObjectnessBING` + + +Saliency::computeSaliency +------------------------ + +Performs all the operations, according to the specific algorithm created, to obtain the saliency map. + +.. ocv:function:: bool computeSaliency( const InputArray image, OutputArray saliencyMap ); + + :param image: image or set of input images. According to InputArray proxy and to the needs of different algorithms (currently plugged), the param image may be Mat or vector + :param saliencyMap: saliency map. According to OutputArray proxy and to the results given by different algorithms (currently plugged), the saliency map may be a Mat or vector (BING results). + +Saliency::getClassName +--------------------- + +Get the name of the specific Saliency Algorithm. + +.. ocv:function:: String getClassName() const; + + + + + + + + diff --git a/modules/saliency/doc/misc b/modules/saliency/doc/misc new file mode 160000 index 000000000..14511ac1c --- /dev/null +++ b/modules/saliency/doc/misc @@ -0,0 +1 @@ +Subproject commit 14511ac1cc8564e1aee153efae4bf0453d3e645e diff --git a/modules/saliency/doc/motion_saliency_algorithms.rst b/modules/saliency/doc/motion_saliency_algorithms.rst new file mode 100644 index 000000000..e69de29bb diff --git a/modules/saliency/doc/objectness_algorithms.rst b/modules/saliency/doc/objectness_algorithms.rst new file mode 100644 index 000000000..e69de29bb diff --git a/modules/saliency/doc/pics/saliency.png b/modules/saliency/doc/pics/saliency.png new file mode 100644 index 000000000..533d60f94 Binary files /dev/null and b/modules/saliency/doc/pics/saliency.png differ diff --git a/modules/saliency/doc/saliency.rst b/modules/saliency/doc/saliency.rst new file mode 100644 index 000000000..686430c8b --- /dev/null +++ b/modules/saliency/doc/saliency.rst @@ -0,0 +1,53 @@ +Saliency API +============ + +.. highlight:: cpp + +Many computer vision applications may benefit from understanding where humans focus given a scene. Other than cognitively understanding the way human perceive images and scenes, finding salient regions and objects in the images helps various tasks such as speeding up object detection, object recognition, object tracking and content-aware image editing. + +About the saliency, there is a rich literature but the development is very fragmented. The principal purpose of this API is to give a +unique interface, a unique framework for use and plug sever saliency algorithms, also with very different nature and methodology, but they share the same purpose, organizing algorithms into three main categories: + +**Static Saliency**: algorithms belonging to this category, exploit different image features that allow to detect salient objects in a non dynamic scenarios. + +**Motion Saliency**: algorithms belonging to this category, are particularly focused to detect salient objects over time (hence also over frame), then there is a temporal component sealing cosider that allows to detect "moving" objects as salient, meaning therefore also the more general sense of detection the changes in the scene. + +**Objectness**: Objectness is usually represented as a value which reflects how likely an image window covers an object of any category. Algorithms belonging to this category, avoid making decisions early on, by proposing a small number of category-independent proposals, that are expected to cover all objects in an image. Being able to perceive objects before identifying them is closely related to bottom up visual attention (saliency). + + +UML design: + +----------- + +**Saliency diagram** + +.. image:: pics/saliency.png + :width: 80% + :alt: Saliency diagram + :align: center + +To see how API works, try tracker demo: https://github.com/fpuja/opencv_contrib/blob/saliencyModuleDevelop/modules/saliency/samples/computeSaliency.cpp + + +.. note:: This Tracking API has been designed with PlantUML. If you modify this API please change UML files under modules/tracking/misc/ + +The following reference was used in the API + +.. [SR] Hou, Xiaodi, and Liqing Zhang. "Saliency detection: A spectral residual approach." Computer Vision and Pattern Recognition, 2007. CVPR'07. IEEE Conference on. IEEE, 2007. + +.. [BING] Cheng, Ming-Ming, et al. "BING: Binarized normed gradients for objectness estimation at 300fps." IEEE CVPR. 2014. + + +Saliency classes: +---------------- + +.. toctree:: + :maxdepth: 2 + + common_interfaces_saliency + saliency_categories + static_saliency_algorithms + motion_saliency_algorithms + objectness_algorithms + + diff --git a/modules/saliency/doc/saliency.rst~ b/modules/saliency/doc/saliency.rst~ new file mode 100644 index 000000000..e202f40ae --- /dev/null +++ b/modules/saliency/doc/saliency.rst~ @@ -0,0 +1,52 @@ +Saliency API +============ + +.. highlight:: cpp + +Many computer vision applications may benefit from understanding where humans focus given a scene. Other than cognitively understanding the way human perceive images and scenes, finding salient regions and objects in the images helps various tasks such as speeding up object detection, object recognition, object tracking and content-aware image editing. + +About the saliency, there is a rich literature but the development is very fragmented. The principal purpose of this API is to give a +unique interface, a unique framework for use and plug sever saliency algorithms, also with very different nature and methodology, but they share the same purpose, organizing algorithms into three main categories: + +**Static Saliency**: algorithms belonging to this category, exploit different image features that allow to detect salient objects in a non dynamic scenarios. + +**Motion Saliency**: algorithms belonging to this category, are particularly focused to detect salient objects over time (hence also over frame), then there is a temporal component sealing cosider that allows to detect "moving" objects as salient, meaning therefore also the more general sense of detection the changes in the scene. + +**Objectness**: Objectness is usually represented as a value which reflects how likely an image window covers an object of any category. Algorithms belonging to this category, avoid making decisions early on, by proposing a small number of category-independent proposals, that are expected to cover all objects in an image. Being able to perceive objects before identifying them is closely related to bottom up visual attention (saliency). + + +UML design: + +----------- + +**Saliency diagram** + +.. image:: pics/saliency.png + :width: 80% + :alt: Saliency diagram + :align: center + +To see how API works, try tracker demo: https://github.com/fpuja/opencv_contrib/blob/saliencyModuleDevelop/modules/saliency/samples/computeSaliency.cpp + + +.. note:: This Tracking API has been designed with PlantUML. If you modify this API please change UML files under modules/tracking/misc/ + +The following reference was used in the API + +.. [SR] Hou, Xiaodi, and Liqing Zhang. "Saliency detection: A spectral residual approach." Computer Vision and Pattern Recognition, 2007. CVPR'07. IEEE Conference on. IEEE, 2007. + +.. [BING] Cheng, Ming-Ming, et al. "BING: Binarized normed gradients for objectness estimation at 300fps." IEEE CVPR. 2014. + + +Saliency classes: +---------------- + +.. toctree:: + :maxdepth: 2 + + saliency_categories + static_saliency_algorithms + motion_saliency_algorithms + objectness_algorithms + + diff --git a/modules/saliency/doc/saliencyAPI.rst~ b/modules/saliency/doc/saliencyAPI.rst~ new file mode 100644 index 000000000..65292c1d9 --- /dev/null +++ b/modules/saliency/doc/saliencyAPI.rst~ @@ -0,0 +1,34 @@ +Saliency API +============ + +.. highlight:: cpp + + +UML design: +----------- + +**Saliency diagram** + +.. image:: pics/saliency.png + :width: 80% + :alt: Tracker diagram + :align: center + +To see how API works, try tracker demo: + + +.. note:: This Tracking API has been designed with PlantUML. If you modify this API please change UML files under modules/tracking/misc/ + +The following reference was used in the API + +.. [SR] Hou, Xiaodi, and Liqing Zhang. "Saliency detection: A spectral residual approach." Computer Vision and Pattern Recognition, 2007. CVPR'07. IEEE Conference on. IEEE, 2007. + +.. [BING] Cheng, Ming-Ming, et al. "BING: Binarized normed gradients for objectness estimation at 300fps." IEEE CVPR. 2014. + + +Saliency classes: +---------------- + +.. toctree:: + :maxdepth: 2 + diff --git a/modules/saliency/doc/saliency_categories.rst b/modules/saliency/doc/saliency_categories.rst new file mode 100644 index 000000000..984458774 --- /dev/null +++ b/modules/saliency/doc/saliency_categories.rst @@ -0,0 +1,6 @@ +Saliency categories +============================ + +.. highlight:: cpp + + diff --git a/modules/saliency/doc/saliency_categories.rst~ b/modules/saliency/doc/saliency_categories.rst~ new file mode 100644 index 000000000..70d682f9c --- /dev/null +++ b/modules/saliency/doc/saliency_categories.rst~ @@ -0,0 +1,6 @@ +Common Interfaces of Tracker +============================ + +.. highlight:: cpp + + diff --git a/modules/saliency/doc/static_saliency_algorithms.rst b/modules/saliency/doc/static_saliency_algorithms.rst new file mode 100644 index 000000000..5284c6fea --- /dev/null +++ b/modules/saliency/doc/static_saliency_algorithms.rst @@ -0,0 +1,5 @@ +Static Saliency algorithms +============================ + +.. highlight:: cpp + diff --git a/modules/saliency/doc/static_saliency_algorithms.rst~ b/modules/saliency/doc/static_saliency_algorithms.rst~ new file mode 100644 index 000000000..ee922c31a --- /dev/null +++ b/modules/saliency/doc/static_saliency_algorithms.rst~ @@ -0,0 +1,5 @@ +Static Saliency categories +============================ + +.. highlight:: cpp + diff --git a/modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp b/modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp index 91e5e6968..8787ae36a 100644 --- a/modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp +++ b/modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp @@ -46,24 +46,10 @@ #include "BING/kyheader.h" #include "BING/ValStructVec.h" #include "BING/FilterTIG.h" -#include "SuBSENSE/BackgroundSubtractorLBSP.h" #include #include #include -//! defines the default value for BackgroundSubtractorLBSP::m_fRelLBSPThreshold -#define BGSSUBSENSE_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD (0.333f) -//! defines the default value for BackgroundSubtractorLBSP::m_nDescDistThreshold -#define BGSSUBSENSE_DEFAULT_DESC_DIST_THRESHOLD (3) -//! defines the default value for BackgroundSubtractorSuBSENSE::m_nMinColorDistThreshold -#define BGSSUBSENSE_DEFAULT_COLOR_DIST_THRESHOLD (30) -//! defines the default value for BackgroundSubtractorSuBSENSE::m_nBGSamples -#define BGSSUBSENSE_DEFAULT_NB_BG_SAMPLES (50) -//! defines the default value for BackgroundSubtractorSuBSENSE::m_nRequiredBGSamples -#define BGSSUBSENSE_DEFAULT_REQUIRED_NB_BG_SAMPLES (2) -//! defines the default value for BackgroundSubtractorSuBSENSE::m_nSamplesForMovingAvgs -#define BGSSUBSENSE_DEFAULT_N_SAMPLES_FOR_MV_AVGS (25) - namespace cv { @@ -99,10 +85,6 @@ class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency /************************************ Specific Motion Saliency Specialized Classes ************************************/ - - - - /************************************ Specific Objectness Specialized Classes ************************************/ /** @@ -119,35 +101,10 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness void read(); void write() const; - // Load trained model. - int loadTrainedModel( std::string modelName = "" ); // Return -1, 0, or 1 if partial, none, or all loaded - - // Get potential bounding boxes, each of which is represented by a Vec4i for (minX, minY, maxX, maxY). - // The trained model should be prepared before calling this function: loadTrainedModel() or trainStageI() + trainStageII(). - // Use numDet to control the final number of proposed bounding boxes, and number of per size (scale and aspect ratio) - void getObjBndBoxes( CMat &img3u, ValStructVec &valBoxes, int numDetPerSize = 120 ); - void getObjBndBoxesForSingleImage( Mat img, ValStructVec &boxes, int numDetPerSize ); vector getobjectnessValues(); - - void setColorSpace( int clr = MAXBGR ); void setTrainingPath( string trainingPath ); void setBBResDir( string resultsDir ); - // Read matrix from binary file - static bool matRead( const std::string& filename, Mat& M ); - - enum - { - MAXBGR, - HSV, - G - }; - - inline static float LoG( float x, float y, float delta ) - { - float d = - ( x * x + y * y ) / ( 2 * delta * delta ); - return -1.0f / ( (float) ( CV_PI ) * pow( delta, 4 ) ) * ( 1 + d ) * exp( d ); - } // Laplacian of Gaussian protected: bool computeSaliencyImpl( const InputArray src, OutputArray dst ); @@ -155,6 +112,14 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness private: // Parameters + + enum + { + MAXBGR, + HSV, + G + }; + double _base, _logBase; // base for window size quantization int _W; // As described in the paper: #Size, Size(_W, _H) of feature window. int _NSS; // Size for non-maximal suppress @@ -177,7 +142,27 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness //vector objectnessBoundingBox; private: - // Help functions + // functions + + inline static float LoG( float x, float y, float delta ) + { + float d = - ( x * x + y * y ) / ( 2 * delta * delta ); + return -1.0f / ( (float) ( CV_PI ) * pow( delta, 4 ) ) * ( 1 + d ) * exp( d ); + } // Laplacian of Gaussian + + // Read matrix from binary file + static bool matRead( const std::string& filename, Mat& M ); + + void setColorSpace( int clr = MAXBGR ); + + // Load trained model. + int loadTrainedModel( std::string modelName = "" ); // Return -1, 0, or 1 if partial, none, or all loaded + + // Get potential bounding boxes, each of which is represented by a Vec4i for (minX, minY, maxX, maxY). + // The trained model should be prepared before calling this function: loadTrainedModel() or trainStageI() + trainStageII(). + // Use numDet to control the final number of proposed bounding boxes, and number of per size (scale and aspect ratio) + void getObjBndBoxes( CMat &img3u, ValStructVec &valBoxes, int numDetPerSize = 120 ); + void getObjBndBoxesForSingleImage( Mat img, ValStructVec &boxes, int numDetPerSize ); bool filtersLoaded() {