diff --git a/modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp b/modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp index 292c9c0a3..551b70ce8 100644 --- a/modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp +++ b/modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp @@ -50,12 +50,6 @@ #include #include -//TODO delete -//#define SALIENCY_DEBUG true -#ifdef SALIENCY_DEBUG -#include -#endif - namespace cv { @@ -68,13 +62,6 @@ namespace cv class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency { public: - /*struct CV_EXPORTS Params - { - Params(); - Size resizedImageSize; - void read( const FileNode& fn ); - void write( FileStorage& fs ) const; - }; */ //StaticSaliencySpectralResidual( const StaticSaliencySpectralResidual::Params ¶meters = StaticSaliencySpectralResidual::Params() ); StaticSaliencySpectralResidual(); @@ -91,11 +78,8 @@ class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency protected: bool computeSaliencyImpl( const InputArray src, OutputArray dst ); - AlgorithmInfo* info() const; - CV_PROP_RW Ptr resizedImageSize; - - private: - //Params params; + AlgorithmInfo* info() const;CV_PROP_RW + Ptr resizedImageSize; }; @@ -109,12 +93,6 @@ class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency class CV_EXPORTS_W MotionSaliencyPBAS : public MotionSaliency { public: - /* struct CV_EXPORTS Params - { - Params(); - void read( const FileNode& fn ); - void write( FileStorage& fs ) const; - }; */ //MotionSaliencyPBAS( const MotionSaliencyPBAS::Params ¶meters = MotionSaliencyPBAS::Params() ); MotionSaliencyPBAS(); @@ -127,8 +105,6 @@ class CV_EXPORTS_W MotionSaliencyPBAS : public MotionSaliency bool computeSaliencyImpl( const InputArray src, OutputArray dst ); AlgorithmInfo* info() const; - private: - //Params params; }; /************************************ Specific Objectness Specialized Classes ************************************/ @@ -148,72 +124,94 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness 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 - + 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 ); AlgorithmInfo* info() const; - private: // Parameters - 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 - int _maxT, _minT, _numT; // The minimal and maximal dimensions of the template - - int _Clr; // - static const char* _clrName[3]; - - // Names and paths to read model and to store results - std:: string _modelName, _bbResDir, _trainingPath, _resultsDir; - - vecI _svmSzIdxs; // Indexes of active size. It's equal to _svmFilters.size() and _svmReW1f.rows - Mat _svmFilter; // Filters learned at stage I, each is a _H by _W CV_32F matrix - FilterTIG _tigF; // TIG filter - Mat _svmReW1f; // Re-weight parameters learned at stage II. - - // List of the rectangles' objectness value, in the same order as - // the vector objectnessBoundingBox returned by the algorithm (in computeSaliencyImpl function) - vector objectnessValues; - //vector objectnessBoundingBox; - - private: // Help functions + private: + // Parameters + 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 + int _maxT, _minT, _numT; // The minimal and maximal dimensions of the template - bool filtersLoaded() {int n = _svmSzIdxs.size(); return n > 0 && _svmReW1f.size() == Size(2, n) && _svmFilter.size() == Size(_W, _W);} - void predictBBoxSI(CMat &mag3u, ValStructVec &valBoxes, vecI &sz, int NUM_WIN_PSZ = 100, bool fast = true); - void predictBBoxSII(ValStructVec &valBoxes, const vecI &sz); + int _Clr; // + static const char* _clrName[3]; - // Calculate the image gradient: center option as in VLFeat - void gradientMag(CMat &imgBGR3u, Mat &mag1u); + // Names and paths to read model and to store results + std::string _modelName, _bbResDir, _trainingPath, _resultsDir; - static void gradientRGB(CMat &bgr3u, Mat &mag1u); - static void gradientGray(CMat &bgr3u, Mat &mag1u); - static void gradientHSV(CMat &bgr3u, Mat &mag1u); - static void gradientXY(CMat &x1i, CMat &y1i, Mat &mag1u); + vecI _svmSzIdxs; // Indexes of active size. It's equal to _svmFilters.size() and _svmReW1f.rows + Mat _svmFilter; // Filters learned at stage I, each is a _H by _W CV_32F matrix + FilterTIG _tigF; // TIG filter + Mat _svmReW1f; // Re-weight parameters learned at stage II. - 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]);} + // List of the rectangles' objectness value, in the same order as + // the vector objectnessBoundingBox returned by the algorithm (in computeSaliencyImpl function) + vector objectnessValues; + //vector objectnessBoundingBox; - //Non-maximal suppress - static void nonMaxSup(CMat &matchCost1f, ValStructVec &matchCost, int NSS = 1, int maxPoint = 50, bool fast = true); + private: + // Help functions + + bool filtersLoaded() + { + int n = _svmSzIdxs.size(); + return n > 0 && _svmReW1f.size() == Size( 2, n ) && _svmFilter.size() == Size( _W, _W ); + } + void predictBBoxSI( CMat &mag3u, ValStructVec &valBoxes, vecI &sz, int NUM_WIN_PSZ = 100, bool fast = true ); + void predictBBoxSII( ValStructVec &valBoxes, const vecI &sz ); + + // Calculate the image gradient: center option as in VLFeat + void gradientMag( CMat &imgBGR3u, Mat &mag1u ); + + static void gradientRGB( CMat &bgr3u, Mat &mag1u ); + static void gradientGray( CMat &bgr3u, Mat &mag1u ); + static void gradientHSV( CMat &bgr3u, Mat &mag1u ); + static void gradientXY( CMat &x1i, CMat &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] ); + } + + //Non-maximal suppress + static void nonMaxSup( CMat &matchCost1f, ValStructVec &matchCost, int NSS = 1, int maxPoint = 50, bool fast = true ); }; diff --git a/modules/saliency/samples/computeSaliency.cpp b/modules/saliency/samples/computeSaliency.cpp index e7792fdb5..acc24eee6 100644 --- a/modules/saliency/samples/computeSaliency.cpp +++ b/modules/saliency/samples/computeSaliency.cpp @@ -1,3 +1,44 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + #include #include #include @@ -63,8 +104,6 @@ int main( int argc, char** argv ) Mat binaryMap; Mat image; - Mat image2=imread("/home/puja/src/BING_beta2_linux/VOC2007/oneVideoJpeg4Test/0011.jpg"); - cap >> frame; if( frame.empty() ) { @@ -104,7 +143,7 @@ int main( int argc, char** argv ) saliencyAlgorithm.dynamicCast()->setTrainingPath( training_path ); saliencyAlgorithm.dynamicCast()->setBBResDir(training_path + "/Results" ); - if( saliencyAlgorithm->computeSaliency( image2, saliencyMap ) ) + if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) ) { std::cout << "-----------------OBJECTNESS-----------" << std::endl; std::cout << "OBJECTNESS BOUNDING BOX VECTOR SIZE" << saliencyMap.size() << std::endl; diff --git a/modules/saliency/src/CmFile.cpp b/modules/saliency/src/CmFile.cpp index 1a7c89c05..7a6c505ff 100644 --- a/modules/saliency/src/CmFile.cpp +++ b/modules/saliency/src/CmFile.cpp @@ -1,3 +1,44 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + #include "kyheader.h" #include "CmFile.h" @@ -55,8 +96,8 @@ int CmFile::GetNames(CStr& rootFolder, CStr &fileW, vecS &names) int subNum = CmFile::GetSubFolders(rootFolder, subFolders);// for (int i = 0; i < subNum; i++){ subFolders[i] += "/"; - int subNum = GetNames(rootFolder + subFolders[i], fileW, tmpNames); - for (int j = 0; j < subNum; j++) + int subNum_ = GetNames(rootFolder + subFolders[i], fileW, tmpNames); + for (int j = 0; j < subNum_; j++) names.push_back(subFolders[i] + tmpNames[j]); } return (int)names.size(); diff --git a/modules/saliency/src/CmFile.h b/modules/saliency/src/CmFile.h index e20d14852..365299a68 100644 --- a/modules/saliency/src/CmFile.h +++ b/modules/saliency/src/CmFile.h @@ -1,3 +1,44 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + #pragma once #ifdef _WIN32 diff --git a/modules/saliency/src/CmShow.cpp b/modules/saliency/src/CmShow.cpp index 6e788ba11..2c4ec3f82 100644 --- a/modules/saliency/src/CmShow.cpp +++ b/modules/saliency/src/CmShow.cpp @@ -1,3 +1,44 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + #include "kyheader.h" #include "CmShow.h" #include "opencv2/core.hpp" diff --git a/modules/saliency/src/CmShow.h b/modules/saliency/src/CmShow.h index 972498f7f..8348e9b23 100644 --- a/modules/saliency/src/CmShow.h +++ b/modules/saliency/src/CmShow.h @@ -1,3 +1,44 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + #pragma once class CmShow { diff --git a/modules/saliency/src/CmTimer.h b/modules/saliency/src/CmTimer.h index 27bfbc421..77d66d3dc 100644 --- a/modules/saliency/src/CmTimer.h +++ b/modules/saliency/src/CmTimer.h @@ -1,3 +1,44 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + #pragma once #ifndef CMTIMER_H #define CMTIMER_H @@ -58,7 +99,7 @@ void CmTimer::Stop() void CmTimer::Reset() { if (is_started) { - printf("CmTimer '%s'is started during reset request.\n Only reset cumulative time.\n"); + printf("CmTimer '%s'is started during reset request.\n Only reset cumulative time.\n", title.c_str()); return; } cumulative_clock = 0; diff --git a/modules/saliency/src/FilterTIG.cpp b/modules/saliency/src/FilterTIG.cpp index b1769dce7..b1e71977a 100644 --- a/modules/saliency/src/FilterTIG.cpp +++ b/modules/saliency/src/FilterTIG.cpp @@ -1,3 +1,44 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + #include "kyheader.h" #include "FilterTIG.h" #include "CmShow.h" diff --git a/modules/saliency/src/FilterTIG.h b/modules/saliency/src/FilterTIG.h index 820a3a508..f275ae22a 100644 --- a/modules/saliency/src/FilterTIG.h +++ b/modules/saliency/src/FilterTIG.h @@ -1,3 +1,44 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + #pragma once #include "kyheader.h" class FilterTIG diff --git a/modules/saliency/src/ValStructVec.h b/modules/saliency/src/ValStructVec.h index 54444b8fb..53bf38536 100644 --- a/modules/saliency/src/ValStructVec.h +++ b/modules/saliency/src/ValStructVec.h @@ -1,3 +1,44 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + #pragma once /************************************************************************/ @@ -74,7 +115,7 @@ void ValStructVec::append( const ValStructVec &newVals, int star { int newValsSize = newVals.size(); for ( int i = 0; i < newValsSize; i++ ) - pushBack( (float) ( ( i + 300 ) * startV )/*newVals(i)*/, newVals[i] ); + pushBack( (float) ( ( i + 300 ) * startV ), newVals[i] ); } template @@ -101,16 +142,3 @@ vector > ValStructVec::getvalIdxes() return valIdxes; } -/* - void valStructVecDemo() - { - ValStructVec sVals; - sVals.pushBack(3, "String 3"); - sVals.pushBack(5, "String 5"); - sVals.pushBack(4, "String 4"); - sVals.pushBack(1, "String 1"); - sVals.sort(false); - for (int i = 0; i < sVals.size(); i++) - printf("%d, %s\n", sVals(i), _S(sVals[i])); - } - */ diff --git a/modules/saliency/src/kyheader.h b/modules/saliency/src/kyheader.h index 724b148ff..faf3d3afb 100644 --- a/modules/saliency/src/kyheader.h +++ b/modules/saliency/src/kyheader.h @@ -1,3 +1,44 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + #ifndef KYHEADER_H #define KYHEADER_H @@ -13,8 +54,6 @@ #include #include - - // TODO: reference additional headers your program requires here //#include "LibLinear/linear.h" //#include @@ -51,7 +90,12 @@ typedef std::vector vecM; typedef std::vector vecF; typedef std::vector vecD; -enum{CV_FLIP_BOTH = -1, CV_FLIP_VERTICAL = 0, CV_FLIP_HORIZONTAL = 1}; +enum +{ + CV_FLIP_BOTH = -1, + CV_FLIP_VERTICAL = 0, + CV_FLIP_HORIZONTAL = 1 +}; #define _S(str) ((str).c_str()) #define CHK_IND(p) ((p).x >= 0 && (p).x < _w && (p).y >= 0 && (p).y < _h) #define CV_Assert_(expr, args) \ @@ -66,155 +110,169 @@ using namespace std; // Return -1 if not in the list template -static inline int findFromList(const T &word, const vector &strList) { - //TODO delete test code - //cout << "\n\n" << "word" <<" "<< word << endl; - for(int i=0; i::iterator it = std::find(strList.begin(),strList.end(), word); - if (it == strList.end()) - { - return -1; - } else - { - vector::iterator index = std::distance(strList.begin(), it); - //cout << "index" <<" "<< index << endl; - return index; - } -} -/*template -static inline int findFromList(const string &word, const vector &strList) { - //for(int i=0; i &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; + } + + vector::iterator it = std::find( strList.begin(), strList.end(), word ); + if( it == strList.end() ) + { + return -1; + } + else + { + vector::iterator index = std::distance( strList.begin(), it ); + //cout << "index" <<" "<< index << endl; + return index; } - - return -1; } -*/ +/*template + static inline int findFromList(const string &word, const vector &strList) { + //for(int i=0; i inline T sqr(T x) { return x * x; } // out of range risk for T = byte, ... -template inline T vecSqrDist(const Vec &v1, const Vec &v2) {T s = 0; for (int i=0; i inline T vecDist(const Vec &v1, const Vec &v2) { return sqrt(vecSqrDist(v1, v2)); } // out of range risk for T = byte, ... + return -1; + } + */ -inline Rect Vec4i2Rect(Vec4i &v){return Rect(Point(v[0] - 1, v[1] - 1), Point(v[2], v[3])); } +template inline T sqr( T x ) +{ + return x * x; +} // out of range risk for T = byte, ... +template inline T vecSqrDist( const Vec &v1, const Vec &v2 ) +{ + T s = 0; + for ( int i = 0; i < D; i++ ) + s += sqr( v1[i] - v2[i] ); + return s; +} // out of range risk for T = byte, ... +template inline T vecDist( const Vec &v1, const Vec &v2 ) +{ + return sqrt( vecSqrDist( v1, v2 ) ); +} // out of range risk for T = byte, ... + +inline Rect Vec4i2Rect( Vec4i &v ) +{ + return Rect( Point( v[0] - 1, v[1] - 1 ), Point( v[2], v[3] ) ); +} #ifdef __WIN32 - #define INT64 long long +#define INT64 long long #else - #define INT64 long - typedef unsigned long UINT64; +#define INT64 long +typedef unsigned long UINT64; #endif -///// -#if (_MSC_VER >= 1500) -# include -# define POPCNT(x) __popcnt(x) -# define POPCNT64(x) __popcnt64(x) -#endif +/* + #if (_MSC_VER >= 1500) + # include + # define POPCNT(x) __popcnt(x) + # define POPCNT64(x) __popcnt64(x) + #endif + */ #if defined(__GNUC__) # define POPCNT(x) __builtin_popcount(x) # define POPCNT64(x) __builtin_popcountll(x) #endif -inline int popcnt64(register uint64_t u) +inline int popcnt64( register uint64_t u ) { - u = (u & 0x5555555555555555) + ((u >> 1) & 0x5555555555555555); - u = (u & 0x3333333333333333) + ((u >> 2) & 0x3333333333333333); - u = (u & 0x0f0f0f0f0f0f0f0f) + ((u >> 4) & 0x0f0f0f0f0f0f0f0f); - u = (u & 0x00ff00ff00ff00ff) + ((u >> 8) & 0x00ff00ff00ff00ff); - u = (u & 0x0000ffff0000ffff) + ((u >>16) & 0x0000ffff0000ffff); - u = (u & 0x00000000ffffffff) + ((u >>32) & 0x00000000ffffffff); - return u; + u = ( u & 0x5555555555555555 ) + ( ( u >> 1 ) & 0x5555555555555555 ); + u = ( u & 0x3333333333333333 ) + ( ( u >> 2 ) & 0x3333333333333333 ); + u = ( u & 0x0f0f0f0f0f0f0f0f ) + ( ( u >> 4 ) & 0x0f0f0f0f0f0f0f0f ); + u = ( u & 0x00ff00ff00ff00ff ) + ( ( u >> 8 ) & 0x00ff00ff00ff00ff ); + u = ( u & 0x0000ffff0000ffff ) + ( ( u >> 16 ) & 0x0000ffff0000ffff ); + u = ( u & 0x00000000ffffffff ) + ( ( u >> 32 ) & 0x00000000ffffffff ); + return u; } -inline int popcnt(register uint32_t u) +inline int popcnt( register uint32_t u ) { - u = (u & 0x55555555) + ((u >> 1) & 0x55555555); - u = (u & 0x33333333) + ((u >> 2) & 0x33333333); - u = (u & 0x0f0f0f0f) + ((u >> 4) & 0x0f0f0f0f); - u = (u & 0x00ff00ff) + ((u >> 8) & 0x00ff00ff); - u = (u & 0x0000ffff) + ((u >>16) & 0x0000ffff); - return u; + u = ( u & 0x55555555 ) + ( ( u >> 1 ) & 0x55555555 ); + u = ( u & 0x33333333 ) + ( ( u >> 2 ) & 0x33333333 ); + u = ( u & 0x0f0f0f0f ) + ( ( u >> 4 ) & 0x0f0f0f0f ); + u = ( u & 0x00ff00ff ) + ( ( u >> 8 ) & 0x00ff00ff ); + u = ( u & 0x0000ffff ) + ( ( u >> 16 ) & 0x0000ffff ); + return u; } -inline int popcnt64_nibble(register uint64_t u) +inline int popcnt64_nibble( register uint64_t u ) { - static const uint8_t Table[] = { - 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 - }; - - int c = 0; - while (u) - { - c += Table[u & 0xf]; - u >>= 4; - } - return c; + static const uint8_t Table[] = + { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; + + int c = 0; + while ( u ) + { + c += Table[u & 0xf]; + u >>= 4; + } + return c; } -inline int popcnt_nibble(register uint32_t u) +inline int popcnt_nibble( register uint32_t u ) { - static const uint8_t Table[] = { - 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 - }; - - int c = 0; - while (u) - { - c += Table[u & 0xf]; - u >>= 4; - } - return c; + static const uint8_t Table[] = + { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; + + int c = 0; + while ( u ) + { + c += Table[u & 0xf]; + u >>= 4; + } + return c; } -inline int popcnt64_byte(register uint64_t u) +inline int popcnt64_byte( register uint64_t u ) { #define B2(k) k, k+1, k+1, k+2 #define B4(k) B2(k), B2(k+1), B2(k+1), B2(k+2) #define B6(k) B4(k), B4(k+1), B4(k+1), B4(k+2) - static const uint8_t Table[] = { - B6(0), B6(1), B6(1), B6(2) - }; + static const uint8_t Table[] = + { B6( 0 ), B6( 1 ), B6( 1 ), B6( 2 ) }; #undef B6 #undef B4 #undef B2 - int c = 0; - while (u) - { - c += Table[u & 0xff]; - u >>= 8; - } - return c; + int c = 0; + while ( u ) + { + c += Table[u & 0xff]; + u >>= 8; + } + return c; } -inline int popcnt_byte(register uint32_t u) +inline int popcnt_byte( register uint32_t u ) { #define B2(k) k, k+1, k+1, k+2 #define B4(k) B2(k), B2(k+1), B2(k+1), B2(k+2) #define B6(k) B4(k), B4(k+1), B4(k+1), B4(k+2) - static const uint8_t Table[] = { - B6(0), B6(1), B6(1), B6(2) - }; + static const uint8_t Table[] = + { B6( 0 ), B6( 1 ), B6( 1 ), B6( 2 ) }; #undef B6 #undef B4 #undef B2 - int c = 0; - while (u) - { - c += Table[u & 0xff]; - u >>= 8; - } - return c; + int c = 0; + while ( u ) + { + c += Table[u & 0xff]; + u >>= 8; + } + return c; } - ///// #include "CmTimer.h" #include "CmFile.h" diff --git a/modules/saliency/src/motionSaliency.cpp b/modules/saliency/src/motionSaliency.cpp index 0cb8a389b..7ed29c9cc 100644 --- a/modules/saliency/src/motionSaliency.cpp +++ b/modules/saliency/src/motionSaliency.cpp @@ -48,14 +48,5 @@ namespace cv * Motion Saliency */ -/** - * Parameters - */ - -//MotionSaliency::Params::Params() -//{ -// -//} - }/* namespace cv */ diff --git a/modules/saliency/src/motionSaliencyPBAS.cpp b/modules/saliency/src/motionSaliencyPBAS.cpp index b361baf4e..b15c749d4 100644 --- a/modules/saliency/src/motionSaliencyPBAS.cpp +++ b/modules/saliency/src/motionSaliencyPBAS.cpp @@ -48,25 +48,6 @@ namespace cv * PBAS Motion Saliency */ -/** - * Parameters - -MotionSaliencyPBAS::Params::Params() -{ - -} - -void MotionSaliencyPBAS::Params::read( const cv::FileNode& fn ) -{ - //resizedImageSize=Size(fn["resizedImageSize"]); - -} - -void MotionSaliencyPBAS::Params::write( cv::FileStorage& fs ) const -{ - //fs << "resizedImageSize" << resizedImageSize; -} */ - MotionSaliencyPBAS::MotionSaliencyPBAS() { className = "PBAS"; @@ -77,17 +58,17 @@ MotionSaliencyPBAS::~MotionSaliencyPBAS() } -void MotionSaliencyPBAS::read( const cv::FileNode& /*fn*/ ) +void MotionSaliencyPBAS::read( const cv::FileNode& /*fn*/) { //params.read( fn ); } -void MotionSaliencyPBAS::write( cv::FileStorage& /*fs*/ ) const +void MotionSaliencyPBAS::write( cv::FileStorage& /*fs*/) const { //params.write( fs ); } -bool MotionSaliencyPBAS::computeSaliencyImpl( const InputArray /*src*/, OutputArray /*dst*/ ) +bool MotionSaliencyPBAS::computeSaliencyImpl( const InputArray /*src*/, OutputArray /*dst*/) { return true; diff --git a/modules/saliency/src/objectness.cpp b/modules/saliency/src/objectness.cpp index 163a03292..ea5dea513 100644 --- a/modules/saliency/src/objectness.cpp +++ b/modules/saliency/src/objectness.cpp @@ -48,14 +48,5 @@ namespace cv * Objectness */ -/** - * Parameters - */ - -//Objectness::Params::Params() -//{ -// -//} - }/* namespace cv */ diff --git a/modules/saliency/src/saliency_init.cpp b/modules/saliency/src/saliency_init.cpp index 20975208c..85039497f 100644 --- a/modules/saliency/src/saliency_init.cpp +++ b/modules/saliency/src/saliency_init.cpp @@ -45,15 +45,18 @@ namespace cv { -CV_INIT_ALGORITHM( StaticSaliencySpectralResidual, "SALIENCY.SPECTRAL_RESIDUAL", - obj.info()->addParam(obj, "resizedImageSize", obj.resizedImageSize, false, reinterpret_cast(&StaticSaliencySpectralResidual::getWsize), reinterpret_cast(&StaticSaliencySpectralResidual::setWsize))); +CV_INIT_ALGORITHM( + StaticSaliencySpectralResidual, + "SALIENCY.SPECTRAL_RESIDUAL", + obj.info()->addParam( obj, "resizedImageSize", obj.resizedImageSize, false, + reinterpret_cast( &StaticSaliencySpectralResidual::getWsize ), + reinterpret_cast( &StaticSaliencySpectralResidual::setWsize ) ) ); -CV_INIT_ALGORITHM( MotionSaliencyPBAS, "SALIENCY.PBAS",); +CV_INIT_ALGORITHM( MotionSaliencyPBAS, "SALIENCY.PBAS", ); -CV_INIT_ALGORITHM( ObjectnessBING, "SALIENCY.BING", - obj.info()->addParam(obj, "_base", obj._base); - obj.info()->addParam(obj, "_NSS", obj._NSS); - obj.info()->addParam(obj, "_W", obj._W)); +CV_INIT_ALGORITHM( + ObjectnessBING, "SALIENCY.BING", + obj.info()->addParam(obj, "_base", obj._base); obj.info()->addParam(obj, "_NSS", obj._NSS); obj.info()->addParam(obj, "_W", obj._W) ); bool initModule_saliency( void ) { diff --git a/modules/saliency/src/staticSaliency.cpp b/modules/saliency/src/staticSaliency.cpp index cd4b1e8e9..799277d93 100644 --- a/modules/saliency/src/staticSaliency.cpp +++ b/modules/saliency/src/staticSaliency.cpp @@ -48,14 +48,6 @@ namespace cv * StaticSaliency */ -/** - * Parameters - - -StaticSaliency::Params::Params() -{ - -} */ bool StaticSaliency::computeBinaryMap( const Mat& saliencyMap, Mat& BinaryMap ) { diff --git a/modules/saliency/src/staticSaliencySpectralResidual.cpp b/modules/saliency/src/staticSaliencySpectralResidual.cpp index a9f4ef8e2..2cdf507a2 100644 --- a/modules/saliency/src/staticSaliencySpectralResidual.cpp +++ b/modules/saliency/src/staticSaliencySpectralResidual.cpp @@ -48,38 +48,19 @@ namespace cv * SaliencySpectralResidual */ -/** - * Parameters - - -StaticSaliencySpectralResidual::Params::Params() -{ - resizedImageSize=Size(64,64); -} - -void StaticSaliencySpectralResidual::Params::read( const cv::FileNode& fn ) +cv::Ptr StaticSaliencySpectralResidual::getWsize() { - //resizedImageSize=Size(fn["resizedImageSize"]); - + return resizedImageSize; } - -void StaticSaliencySpectralResidual::Params::write( cv::FileStorage& fs ) const +void StaticSaliencySpectralResidual::setWsize( const cv::Ptr& newSize ) { - //fs << "resizedImageSize" << resizedImageSize; -} */ - -cv::Ptr StaticSaliencySpectralResidual::getWsize(){ - return resizedImageSize; -} -void StaticSaliencySpectralResidual::setWsize(const cv::Ptr& newSize){ resizedImageSize = newSize; } - StaticSaliencySpectralResidual::StaticSaliencySpectralResidual() { className = "SPECTRAL_RESIDUAL"; - resizedImageSize=Ptr(new Size(64,64)); + resizedImageSize = Ptr( new Size( 64, 64 ) ); } StaticSaliencySpectralResidual::~StaticSaliencySpectralResidual() @@ -87,12 +68,12 @@ StaticSaliencySpectralResidual::~StaticSaliencySpectralResidual() } -void StaticSaliencySpectralResidual::read( const cv::FileNode& fn ) +void StaticSaliencySpectralResidual::read( const cv::FileNode& /*fn*/ ) { //params.read( fn ); } -void StaticSaliencySpectralResidual::write( cv::FileStorage& fs ) const +void StaticSaliencySpectralResidual::write( cv::FileStorage& /*fs*/ ) const { //params.write( fs ); } @@ -101,7 +82,7 @@ bool StaticSaliencySpectralResidual::computeSaliencyImpl( const InputArray image { Mat grayTemp, grayDown; std::vector mv; - Mat realImage(*resizedImageSize, CV_64F ); + Mat realImage( *resizedImageSize, CV_64F ); Mat imaginaryImage( *resizedImageSize, CV_64F ); imaginaryImage.setTo( 0 ); Mat combinedImage( *resizedImageSize, CV_64FC2 ); @@ -159,7 +140,6 @@ bool StaticSaliencySpectralResidual::computeSaliencyImpl( const InputArray image imshow( "Saliency Map Interna", saliencyMap ); #endif - return true; }