Commit 5b2d6a66 authored by Minh Ngo's avatar Minh Ngo Committed by Vladislav Sovrasov

Exporting saliency classes to Python

Fixing compilation

Patched the saliency module to use ObjectivenessBING bounding box
proposals from python.

Usage:

```
bing = cv2.saliency.ObjectnessBING()
img = cv2.imread('/home/ignotus/Pictures/10376146_973700932714682_2056967515849182952_n.jpg')
bing.computeSaliency(img)
```
parent 1df640a6
set(the_description "Saliency API") set(the_description "Saliency API")
set(OPENCV_MODULE_IS_PART_OF_WORLD OFF) set(OPENCV_MODULE_IS_PART_OF_WORLD OFF)
add_definitions(-DOBJECTNESS_MODELS_PATH="${CMAKE_INSTALL_PREFIX}/${OPENCV_OTHER_INSTALL_PATH}/Objectness")
file(GLOB OBJECTNESS_TRAINED_MODELS samples/ObjectnessTrainedModel/*.yml.gz)
install(FILES ${OBJECTNESS_TRAINED_MODELS} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/Objectness COMPONENT libs)
install(DIRECTORY DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/Objectness/Results)
ocv_define_module(saliency opencv_imgproc opencv_highgui opencv_features2d WRAP python) ocv_define_module(saliency opencv_imgproc opencv_highgui opencv_features2d WRAP python)
...@@ -59,7 +59,7 @@ namespace saliency ...@@ -59,7 +59,7 @@ namespace saliency
/************************************ Saliency Base Class ************************************/ /************************************ Saliency Base Class ************************************/
class CV_EXPORTS Saliency : public virtual Algorithm class CV_EXPORTS_W Saliency : public virtual Algorithm
{ {
public: public:
/** /**
...@@ -78,7 +78,7 @@ class CV_EXPORTS Saliency : public virtual Algorithm ...@@ -78,7 +78,7 @@ class CV_EXPORTS 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( InputArray image, OutputArray saliencyMap ); CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap );
/** /**
* \brief Get the name of the specific saliency type * \brief Get the name of the specific saliency type
...@@ -93,7 +93,7 @@ class CV_EXPORTS Saliency : public virtual Algorithm ...@@ -93,7 +93,7 @@ class CV_EXPORTS Saliency : public virtual Algorithm
}; };
/************************************ Static Saliency Base Class ************************************/ /************************************ Static Saliency Base Class ************************************/
class CV_EXPORTS StaticSaliency : public virtual Saliency class CV_EXPORTS_W StaticSaliency : public virtual Saliency
{ {
public: public:
...@@ -112,14 +112,14 @@ class CV_EXPORTS StaticSaliency : public virtual Saliency ...@@ -112,14 +112,14 @@ class CV_EXPORTS StaticSaliency : public virtual Saliency
@param saliencyMap the saliency map obtained through one of the specialized algorithms @param saliencyMap the saliency map obtained through one of the specialized algorithms
@param binaryMap the binary map @param binaryMap the binary map
*/ */
bool computeBinaryMap( const Mat& saliencyMap, Mat& binaryMap ); CV_WRAP bool computeBinaryMap( const Mat& saliencyMap, Mat& binaryMap );
protected: protected:
virtual bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap )=0; virtual bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap )=0;
}; };
/************************************ Motion Saliency Base Class ************************************/ /************************************ Motion Saliency Base Class ************************************/
class CV_EXPORTS MotionSaliency : public virtual Saliency class CV_EXPORTS_W MotionSaliency : public virtual Saliency
{ {
protected: protected:
...@@ -128,7 +128,7 @@ class CV_EXPORTS MotionSaliency : public virtual Saliency ...@@ -128,7 +128,7 @@ class CV_EXPORTS MotionSaliency : public virtual Saliency
}; };
/************************************ Objectness Base Class ************************************/ /************************************ Objectness Base Class ************************************/
class CV_EXPORTS Objectness : public virtual Saliency class CV_EXPORTS_W Objectness : public virtual Saliency
{ {
protected: protected:
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <stdint.h> #include <stdint.h>
#include "saliencyBaseClasses.hpp"
#include "opencv2/core.hpp" #include "opencv2/core.hpp"
namespace cv namespace cv
...@@ -66,37 +67,37 @@ pre-attentive visual search. The algorithm analyze the log spectrum of each imag ...@@ -66,37 +67,37 @@ pre-attentive visual search. The algorithm analyze the log spectrum of each imag
spectral residual. Then transform the spectral residual to spatial domain to obtain the saliency spectral residual. Then transform the spectral residual to spatial domain to obtain the saliency
map, which suggests the positions of proto-objects. map, which suggests the positions of proto-objects.
*/ */
class CV_EXPORTS StaticSaliencySpectralResidual : public StaticSaliency class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency
{ {
public: public:
StaticSaliencySpectralResidual(); CV_WRAP StaticSaliencySpectralResidual();
virtual ~StaticSaliencySpectralResidual(); virtual ~StaticSaliencySpectralResidual();
void read( const FileNode& fn ); CV_WRAP void read( const FileNode& fn );
void write( FileStorage& fs ) const; void write( FileStorage& fs ) const;
int getImageWidth() const CV_WRAP int getImageWidth() const
{ {
return resImWidth; return resImWidth;
} }
inline void setImageWidth(int val) CV_WRAP inline void setImageWidth(int val)
{ {
resImWidth = val; resImWidth = val;
} }
int getImageHeight() const CV_WRAP int getImageHeight() const
{ {
return resImHeight; return resImHeight;
} }
void setImageHeight(int val) CV_WRAP void setImageHeight(int val)
{ {
resImHeight = val; resImHeight = val;
} }
protected: protected:
bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap ); bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap );
int resImWidth; CV_PROP_RW int resImWidth;
int resImHeight; CV_PROP_RW int resImHeight;
}; };
...@@ -111,10 +112,10 @@ protected: ...@@ -111,10 +112,10 @@ protected:
*/ */
/** @brief the Fast Self-tuning Background Subtraction Algorithm from @cite BinWangApr2014 /** @brief the Fast Self-tuning Background Subtraction Algorithm from @cite BinWangApr2014
*/ */
class CV_EXPORTS MotionSaliencyBinWangApr2014 : public MotionSaliency class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency
{ {
public: public:
MotionSaliencyBinWangApr2014(); CV_WRAP MotionSaliencyBinWangApr2014();
virtual ~MotionSaliencyBinWangApr2014(); virtual ~MotionSaliencyBinWangApr2014();
/** @brief This is a utility function that allows to set the correct size (taken from the input image) in the /** @brief This is a utility function that allows to set the correct size (taken from the input image) in the
...@@ -122,25 +123,25 @@ public: ...@@ -122,25 +123,25 @@ public:
@param W width of input image @param W width of input image
@param H height of input image @param H height of input image
*/ */
void setImagesize( int W, int H ); CV_WRAP void setImagesize( int W, int H );
/** @brief This function allows the correct initialization of all data structures that will be used by the /** @brief This function allows the correct initialization of all data structures that will be used by the
algorithm. algorithm.
*/ */
bool init(); CV_WRAP bool init();
int getImageWidth() const CV_WRAP int getImageWidth() const
{ {
return imageWidth; return imageWidth;
} }
inline void setImageWidth(int val) CV_WRAP inline void setImageWidth(int val)
{ {
imageWidth = val; imageWidth = val;
} }
int getImageHeight() const CV_WRAP int getImageHeight() const
{ {
return imageHeight; return imageHeight;
} }
void setImageHeight(int val) CV_WRAP void setImageHeight(int val)
{ {
imageHeight = val; imageHeight = val;
} }
...@@ -177,8 +178,8 @@ private: ...@@ -177,8 +178,8 @@ private:
//fixed parameter //fixed parameter
bool neighborhoodCheck; bool neighborhoodCheck;
int N_DS;// Number of template to be downsampled and used in lowResolutionDetection function int N_DS;// Number of template to be downsampled and used in lowResolutionDetection function
int imageWidth;// Width of input image CV_PROP_RW int imageWidth;// Width of input image
int imageHeight;//Height of input image CV_PROP_RW int imageHeight;//Height of input image
int K;// Number of background model template int K;// Number of background model template
int N;// NxN is the size of the block for downsampling in the lowlowResolutionDetection int N;// NxN is the size of the block for downsampling in the lowlowResolutionDetection
float alpha;// Learning rate float alpha;// Learning rate
...@@ -200,11 +201,11 @@ private: ...@@ -200,11 +201,11 @@ private:
/** @brief the Binarized normed gradients algorithm from @cite BING /** @brief the Binarized normed gradients algorithm from @cite BING
*/ */
class CV_EXPORTS ObjectnessBING : public Objectness class CV_EXPORTS_W ObjectnessBING : public Objectness
{ {
public: public:
ObjectnessBING(); CV_WRAP ObjectnessBING();
virtual ~ObjectnessBING(); virtual ~ObjectnessBING();
void read(); void read();
......
...@@ -71,6 +71,9 @@ ObjectnessBING::ObjectnessBING() ...@@ -71,6 +71,9 @@ ObjectnessBING::ObjectnessBING()
setColorSpace( _Clr ); setColorSpace( _Clr );
className = "BING"; className = "BING";
setTrainingPath(OBJECTNESS_MODELS_PATH);
setBBResDir(OBJECTNESS_MODELS_PATH "/Results");
} }
ObjectnessBING::~ObjectnessBING() ObjectnessBING::~ObjectnessBING()
......
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