123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513 |
- #ifndef __OPENCV_SALIENCY_SPECIALIZED_CLASSES_HPP__
- #define __OPENCV_SALIENCY_SPECIALIZED_CLASSES_HPP__
- #include <cstdio>
- #include <string>
- #include <iostream>
- #include <stdint.h>
- #include "saliencyBaseClasses.hpp"
- #include "opencv2/core.hpp"
- namespace cv
- {
- namespace saliency
- {
- class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency
- {
- public:
- StaticSaliencySpectralResidual();
- virtual ~StaticSaliencySpectralResidual();
- CV_WRAP static Ptr<StaticSaliencySpectralResidual> create()
- {
- return makePtr<StaticSaliencySpectralResidual>();
- }
- CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap )
- {
- if( image.empty() )
- return false;
- return computeSaliencyImpl( image, saliencyMap );
- }
- CV_WRAP void read( const FileNode& fn );
- void write( FileStorage& fs ) const;
- CV_WRAP int getImageWidth() const
- {
- return resImWidth;
- }
- CV_WRAP inline void setImageWidth(int val)
- {
- resImWidth = val;
- }
- CV_WRAP int getImageHeight() const
- {
- return resImHeight;
- }
- CV_WRAP void setImageHeight(int val)
- {
- resImHeight = val;
- }
- protected:
- bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap );
- CV_PROP_RW int resImWidth;
- CV_PROP_RW int resImHeight;
- };
- class CV_EXPORTS_W StaticSaliencyFineGrained : public StaticSaliency
- {
- public:
- StaticSaliencyFineGrained();
- CV_WRAP static Ptr<StaticSaliencyFineGrained> create()
- {
- return makePtr<StaticSaliencyFineGrained>();
- }
- CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap )
- {
- if( image.empty() )
- return false;
- return computeSaliencyImpl( image, saliencyMap );
- }
- virtual ~StaticSaliencyFineGrained();
- protected:
- bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap );
- private:
- void calcIntensityChannel(Mat src, Mat dst);
- void copyImage(Mat src, Mat dst);
- void getIntensityScaled(Mat integralImage, Mat gray, Mat saliencyOn, Mat saliencyOff, int neighborhood);
- float getMean(Mat srcArg, Point2i PixArg, int neighbourhood, int centerVal);
- void mixScales(Mat *saliencyOn, Mat intensityOn, Mat *saliencyOff, Mat intensityOff, const int numScales);
- void mixOnOff(Mat intensityOn, Mat intensityOff, Mat intensity);
- void getIntensity(Mat srcArg, Mat dstArg, Mat dstOnArg, Mat dstOffArg, bool generateOnOff);
- };
- class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency
- {
- public:
- MotionSaliencyBinWangApr2014();
- virtual ~MotionSaliencyBinWangApr2014();
- CV_WRAP static Ptr<MotionSaliencyBinWangApr2014> create()
- {
- return makePtr<MotionSaliencyBinWangApr2014>();
- }
- CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap )
- {
- if( image.empty() )
- return false;
- return computeSaliencyImpl( image, saliencyMap );
- }
-
- CV_WRAP void setImagesize( int W, int H );
-
- CV_WRAP bool init();
- CV_WRAP int getImageWidth() const
- {
- return imageWidth;
- }
- CV_WRAP inline void setImageWidth(int val)
- {
- imageWidth = val;
- }
- CV_WRAP int getImageHeight() const
- {
- return imageHeight;
- }
- CV_WRAP void setImageHeight(int val)
- {
- imageHeight = val;
- }
- protected:
-
- bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap );
- private:
-
- bool fullResolutionDetection( const Mat& image, Mat& highResBFMask );
- bool lowResolutionDetection( const Mat& image, Mat& lowResBFMask );
-
- bool templateOrdering();
- bool templateReplacement( const Mat& finalBFMask, const Mat& image );
-
- bool activityControl(const Mat& current_noisePixelsMask);
- bool decisionThresholdAdaptation();
-
- std::vector<Ptr<Mat> > backgroundModel;
-
-
- Mat potentialBackground;
-
- Mat epslonPixelsValue;
- Mat activityPixelsValue;
-
- Mat noisePixelMask;
-
-
-
-
- bool activityControlFlag;
- bool neighborhoodCheck;
- int N_DS;
- CV_PROP_RW int imageWidth;
- CV_PROP_RW int imageHeight;
- int K;
- int N;
- float alpha;
- int L0, L1;
- int thetaL;
- int thetaA;
- int gamma;
-
-
- uchar Ainc;
- int Bmax;
- int Bth;
- int Binc, Bdec;
- float deltaINC, deltaDEC;
- int epslonMIN, epslonMAX;
- };
- class CV_EXPORTS_W ObjectnessBING : public Objectness
- {
- public:
- ObjectnessBING();
- virtual ~ObjectnessBING();
- CV_WRAP static Ptr<ObjectnessBING> create()
- {
- return makePtr<ObjectnessBING>();
- }
- CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap )
- {
- if( image.empty() )
- return false;
- return computeSaliencyImpl( image, saliencyMap );
- }
- CV_WRAP void read();
- CV_WRAP void write() const;
-
- CV_WRAP std::vector<float> getobjectnessValues();
-
- CV_WRAP void setTrainingPath( const String& trainingPath );
-
- CV_WRAP void setBBResDir( const String& resultsDir );
- CV_WRAP double getBase() const
- {
- return _base;
- }
- CV_WRAP inline void setBase(double val)
- {
- _base = val;
- }
- CV_WRAP int getNSS() const
- {
- return _NSS;
- }
- CV_WRAP void setNSS(int val)
- {
- _NSS = val;
- }
- CV_WRAP int getW() const
- {
- return _W;
- }
- CV_WRAP void setW(int val)
- {
- _W = val;
- }
- protected:
-
- bool computeSaliencyImpl( InputArray image, OutputArray objectnessBoundingBox );
- private:
- class FilterTIG
- {
- public:
- void update( Mat &w );
-
- Mat matchTemplate( const Mat &mag1u );
- float dot( int64_t tig1, int64_t tig2, int64_t tig4, int64_t tig8 );
- void reconstruct( Mat &w );
- private:
- static const int NUM_COMP = 2;
- static const int D = 64;
- int64_t _bTIGs[NUM_COMP];
- float _coeffs1[NUM_COMP];
-
- float _coeffs2[NUM_COMP], _coeffs4[NUM_COMP], _coeffs8[NUM_COMP];
- };
- template<typename VT, typename ST>
- struct ValStructVec
- {
- ValStructVec();
- int size() const;
- void clear();
- void reserve( int resSz );
- void pushBack( const VT& val, const ST& structVal );
- const VT& operator ()( int i ) const;
- const ST& operator []( int i ) const;
- VT& operator ()( int i );
- ST& operator []( int i );
- void sort( bool descendOrder = true );
- const std::vector<ST> &getSortedStructVal();
- std::vector<std::pair<VT, int> > getvalIdxes();
- void append( const ValStructVec<VT, ST> &newVals, int startV = 0 );
- std::vector<ST> structVals;
- int sz;
- std::vector<std::pair<VT, int> > valIdxes;
- bool smaller()
- {
- return true;
- }
- std::vector<ST> sortedStructVals;
- };
- enum
- {
- MAXBGR,
- HSV,
- G
- };
- double _base, _logBase;
- int _W;
- int _NSS;
- int _maxT, _minT, _numT;
- int _Clr;
- static const char* _clrName[3];
- std::string _modelName, _bbResDir, _trainingPath, _resultsDir;
- std::vector<int> _svmSzIdxs;
- Mat _svmFilter;
- FilterTIG _tigF;
- Mat _svmReW1f;
- std::vector<float> objectnessValues;
- private:
- 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 );
- }
- static bool matRead( const std::string& filename, Mat& M );
- void setColorSpace( int clr = MAXBGR );
- int loadTrainedModel( std::string modelName = "" );
- void getObjBndBoxes( Mat &img3u, ValStructVec<float, Vec4i> &valBoxes, int numDetPerSize = 120 );
- void getObjBndBoxesForSingleImage( Mat img, ValStructVec<float, Vec4i> &boxes, int numDetPerSize );
- bool filtersLoaded()
- {
- int n = (int) _svmSzIdxs.size();
- return n > 0 && _svmReW1f.size() == Size( 2, n ) && _svmFilter.size() == Size( _W, _W );
- }
- void predictBBoxSI( Mat &mag3u, ValStructVec<float, Vec4i> &valBoxes, std::vector<int> &sz, int NUM_WIN_PSZ = 100, bool fast = true );
- void predictBBoxSII( ValStructVec<float, Vec4i> &valBoxes, const std::vector<int> &sz );
- void gradientMag( Mat &imgBGR3u, Mat &mag1u );
- static void gradientRGB( Mat &bgr3u, Mat &mag1u );
- static void gradientGray( Mat &bgr3u, Mat &mag1u );
- static void gradientHSV( Mat &bgr3u, Mat &mag1u );
- static void gradientXY( Mat &x1i, Mat &y1i, Mat &mag1u );
- static inline int bgrMaxDist( const Vec3b &u, const Vec3b &v )
- {
- int b = abs( u[0] - v[0] ), g = abs( u[1] - v[1] ), r = abs( u[2] - v[2] );
- b = max( b, g );
- return max( b, r );
- }
- static inline int vecDist3b( const Vec3b &u, const Vec3b &v )
- {
- return abs( u[0] - v[0] ) + abs( u[1] - v[1] ) + abs( u[2] - v[2] );
- }
- static void nonMaxSup( Mat &matchCost1f, ValStructVec<float, Point> &matchCost, int NSS = 1, int maxPoint = 50, bool fast = true );
- };
- }
- }
- #endif
|