diff --git a/apps/traincascade/old_ml.hpp b/apps/traincascade/old_ml.hpp index 6ec31a025..bf0cd15f9 100644 --- a/apps/traincascade/old_ml.hpp +++ b/apps/traincascade/old_ml.hpp @@ -122,7 +122,6 @@ CV_INLINE CvParamLattice cvDefaultParamLattice( void ) #define CV_TYPE_NAME_ML_SVM "opencv-ml-svm" #define CV_TYPE_NAME_ML_KNN "opencv-ml-knn" #define CV_TYPE_NAME_ML_NBAYES "opencv-ml-bayesian" -#define CV_TYPE_NAME_ML_EM "opencv-ml-em" #define CV_TYPE_NAME_ML_BOOSTING "opencv-ml-boost-tree" #define CV_TYPE_NAME_ML_TREE "opencv-ml-tree" #define CV_TYPE_NAME_ML_ANN_MLP "opencv-ml-ann-mlp" @@ -562,100 +561,6 @@ private: CvSVM& operator = (const CvSVM&); }; -/****************************************************************************************\ -* Expectation - Maximization * -\****************************************************************************************/ -namespace cv -{ -class EM : public Algorithm -{ -public: - // Type of covariation matrices - enum {COV_MAT_SPHERICAL=0, COV_MAT_DIAGONAL=1, COV_MAT_GENERIC=2, COV_MAT_DEFAULT=COV_MAT_DIAGONAL}; - - // Default parameters - enum {DEFAULT_NCLUSTERS=5, DEFAULT_MAX_ITERS=100}; - - // The initial step - enum {START_E_STEP=1, START_M_STEP=2, START_AUTO_STEP=0}; - - CV_WRAP EM(int nclusters=EM::DEFAULT_NCLUSTERS, int covMatType=EM::COV_MAT_DIAGONAL, - const TermCriteria& termCrit=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, - EM::DEFAULT_MAX_ITERS, FLT_EPSILON)); - - virtual ~EM(); - CV_WRAP virtual void clear(); - - CV_WRAP virtual bool train(InputArray samples, - OutputArray logLikelihoods=noArray(), - OutputArray labels=noArray(), - OutputArray probs=noArray()); - - CV_WRAP virtual bool trainE(InputArray samples, - InputArray means0, - InputArray covs0=noArray(), - InputArray weights0=noArray(), - OutputArray logLikelihoods=noArray(), - OutputArray labels=noArray(), - OutputArray probs=noArray()); - - CV_WRAP virtual bool trainM(InputArray samples, - InputArray probs0, - OutputArray logLikelihoods=noArray(), - OutputArray labels=noArray(), - OutputArray probs=noArray()); - - CV_WRAP Vec2d predict(InputArray sample, - OutputArray probs=noArray()) const; - - CV_WRAP bool isTrained() const; - - AlgorithmInfo* info() const; - virtual void read(const FileNode& fn); - -protected: - - virtual void setTrainData(int startStep, const Mat& samples, - const Mat* probs0, - const Mat* means0, - const std::vector* covs0, - const Mat* weights0); - - bool doTrain(int startStep, - OutputArray logLikelihoods, - OutputArray labels, - OutputArray probs); - virtual void eStep(); - virtual void mStep(); - - void clusterTrainSamples(); - void decomposeCovs(); - void computeLogWeightDivDet(); - - Vec2d computeProbabilities(const Mat& sample, Mat* probs) const; - - // all inner matrices have type CV_64FC1 - CV_PROP_RW int nclusters; - CV_PROP_RW int covMatType; - CV_PROP_RW int maxIters; - CV_PROP_RW double epsilon; - - Mat trainSamples; - Mat trainProbs; - Mat trainLogLikelihoods; - Mat trainLabels; - - CV_PROP Mat weights; - CV_PROP Mat means; - CV_PROP std::vector covs; - - std::vector covsEigenValues; - std::vector covsRotateMats; - std::vector invCovsEigenValues; - Mat logWeightDivDet; -}; -} // namespace cv - /****************************************************************************************\ * Decision Tree * \****************************************************************************************/\ @@ -2155,8 +2060,6 @@ typedef CvGBTreesParams GradientBoostingTreeParams; typedef CvGBTrees GradientBoostingTrees; template<> void DefaultDeleter::operator ()(CvDTreeSplit* obj) const; - -bool initModule_ml(void); } #endif // __cplusplus diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 8b310a2e3..79af5ac35 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -100,7 +100,7 @@ RECURSIVE = YES EXCLUDE = EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = *.inl.hpp *.impl.hpp *_detail.hpp */cudev/**/detail/*.hpp -EXCLUDE_SYMBOLS = cv::DataType<*> int +EXCLUDE_SYMBOLS = cv::DataType<*> int void EXAMPLE_PATH = @CMAKE_DOXYGEN_EXAMPLE_PATH@ EXAMPLE_PATTERNS = * EXAMPLE_RECURSIVE = YES @@ -243,7 +243,8 @@ PREDEFINED = __cplusplus=1 \ CV_NORETURN= \ CV_DEFAULT(x)=" = x" \ CV_NEON=1 \ - FLANN_DEPRECATED= + FLANN_DEPRECATED= \ + "CV_PURE_PROPERTY(type, name)= /**\@{*/ virtual type get##name() const = 0; virtual void set##name(type _##name) = 0; /**\@}*/" EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = YES TAGFILES = diff --git a/modules/calib3d/src/levmarq.cpp b/modules/calib3d/src/levmarq.cpp index d3eb7b556..bcf08e091 100644 --- a/modules/calib3d/src/levmarq.cpp +++ b/modules/calib3d/src/levmarq.cpp @@ -200,8 +200,6 @@ public: void setCallback(const Ptr& _cb) { cb = _cb; } - AlgorithmInfo* info() const; - Ptr cb; double epsx; @@ -211,15 +209,8 @@ public: }; -CV_INIT_ALGORITHM(LMSolverImpl, "LMSolver", - obj.info()->addParam(obj, "epsx", obj.epsx); - obj.info()->addParam(obj, "epsf", obj.epsf); - obj.info()->addParam(obj, "maxIters", obj.maxIters); - obj.info()->addParam(obj, "printInterval", obj.printInterval)) - Ptr createLMSolver(const Ptr& cb, int maxIters) { - CV_Assert( !LMSolverImpl_info_auto.name().empty() ); return makePtr(cb, maxIters); } diff --git a/modules/calib3d/src/ptsetreg.cpp b/modules/calib3d/src/ptsetreg.cpp index 713f8b90f..2a81a33ff 100644 --- a/modules/calib3d/src/ptsetreg.cpp +++ b/modules/calib3d/src/ptsetreg.cpp @@ -256,8 +256,6 @@ public: void setCallback(const Ptr& _cb) { cb = _cb; } - AlgorithmInfo* info() const; - Ptr cb; int modelPoints; bool checkPartialSubsets; @@ -378,25 +376,12 @@ public: return result; } - AlgorithmInfo* info() const; }; - -CV_INIT_ALGORITHM(RANSACPointSetRegistrator, "PointSetRegistrator.RANSAC", - obj.info()->addParam(obj, "threshold", obj.threshold); - obj.info()->addParam(obj, "confidence", obj.confidence); - obj.info()->addParam(obj, "maxIters", obj.maxIters)) - -CV_INIT_ALGORITHM(LMeDSPointSetRegistrator, "PointSetRegistrator.LMeDS", - obj.info()->addParam(obj, "confidence", obj.confidence); - obj.info()->addParam(obj, "maxIters", obj.maxIters)) - - Ptr createRANSACPointSetRegistrator(const Ptr& _cb, int _modelPoints, double _threshold, double _confidence, int _maxIters) { - CV_Assert( !RANSACPointSetRegistrator_info_auto.name().empty() ); return Ptr( new RANSACPointSetRegistrator(_cb, _modelPoints, _threshold, _confidence, _maxIters)); } @@ -405,7 +390,6 @@ Ptr createRANSACPointSetRegistrator(const Ptr createLMeDSPointSetRegistrator(const Ptr& _cb, int _modelPoints, double _confidence, int _maxIters) { - CV_Assert( !LMeDSPointSetRegistrator_info_auto.name().empty() ); return Ptr( new LMeDSPointSetRegistrator(_cb, _modelPoints, _confidence, _maxIters)); } diff --git a/modules/calib3d/src/stereobm.cpp b/modules/calib3d/src/stereobm.cpp index 72802b624..f093f2b2b 100644 --- a/modules/calib3d/src/stereobm.cpp +++ b/modules/calib3d/src/stereobm.cpp @@ -1010,8 +1010,6 @@ public: disp.convertTo(disp0, disp0.type(), 1./(1 << DISPARITY_SHIFT), 0); } - AlgorithmInfo* info() const { return 0; } - int getMinDisparity() const { return params.minDisparity; } void setMinDisparity(int minDisparity) { params.minDisparity = minDisparity; } diff --git a/modules/calib3d/src/stereosgbm.cpp b/modules/calib3d/src/stereosgbm.cpp index 1793ee094..4b0aa5a25 100644 --- a/modules/calib3d/src/stereosgbm.cpp +++ b/modules/calib3d/src/stereosgbm.cpp @@ -865,8 +865,6 @@ public: StereoMatcher::DISP_SCALE*params.speckleRange, buffer); } - AlgorithmInfo* info() const { return 0; } - int getMinDisparity() const { return params.minDisparity; } void setMinDisparity(int minDisparity) { params.minDisparity = minDisparity; } diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index 76fb3fd52..701c0e3a0 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -2745,8 +2745,6 @@ public: //////////////////////////////////////// Algorithm //////////////////////////////////// class CV_EXPORTS Algorithm; -class CV_EXPORTS AlgorithmInfo; -struct CV_EXPORTS AlgorithmInfoData; template struct ParamType {}; @@ -2759,32 +2757,13 @@ matching, graph-cut etc.), background subtraction (which can be done using mixtu models, codebook-based algorithm etc.), optical flow (block matching, Lucas-Kanade, Horn-Schunck etc.). -The class provides the following features for all derived classes: - -- so called "virtual constructor". That is, each Algorithm derivative is registered at program - start and you can get the list of registered algorithms and create instance of a particular - algorithm by its name (see Algorithm::create). If you plan to add your own algorithms, it is - good practice to add a unique prefix to your algorithms to distinguish them from other - algorithms. -- setting/retrieving algorithm parameters by name. If you used video capturing functionality - from OpenCV videoio module, you are probably familar with cvSetCaptureProperty(), - cvGetCaptureProperty(), VideoCapture::set() and VideoCapture::get(). Algorithm provides - similar method where instead of integer id's you specify the parameter names as text strings. - See Algorithm::set and Algorithm::get for details. -- reading and writing parameters from/to XML or YAML files. Every Algorithm derivative can store - all its parameters and then read them back. There is no need to re-implement it each time. - Here is example of SIFT use in your application via Algorithm interface: @code #include "opencv2/opencv.hpp" #include "opencv2/xfeatures2d.hpp" - using namespace cv::xfeatures2d; - ... - Ptr sift = SIFT::create(); - FileStorage fs("sift_params.xml", FileStorage::READ); if( fs.isOpened() ) // if we have file with parameters, read them { @@ -2794,323 +2773,80 @@ Here is example of SIFT use in your application via Algorithm interface: else // else modify the parameters and store them; user can later edit the file to use different parameters { sift->setContrastThreshold(0.01f); // lower the contrast threshold, compared to the default value - { - WriteStructContext ws(fs, "sift_params", CV_NODE_MAP); - sift->write(fs); + WriteStructContext ws(fs, "sift_params", CV_NODE_MAP); + sift->write(fs); } } - Mat image = imread("myimage.png", 0), descriptors; vector keypoints; sift->detectAndCompute(image, noArray(), keypoints, descriptors); @endcode - -Creating Own Algorithms ------------------------ -If you want to make your own algorithm, derived from Algorithm, you should basically follow a few -conventions and add a little semi-standard piece of code to your class: -- Make a class and specify Algorithm as its base class. -- The algorithm parameters should be the class members. See Algorithm::get() for the list of - possible types of the parameters. -- Add public virtual method `AlgorithmInfo* info() const;` to your class. -- Add constructor function, AlgorithmInfo instance and implement the info() method. The simplest - way is to take as - the reference and modify it according to the list of your parameters. -- Add some public function (e.g. `initModule_()`) that calls info() of your algorithm - and put it into the same source file as info() implementation. This is to force C++ linker to - include this object file into the target application. See Algorithm::create() for details. */ class CV_EXPORTS_W Algorithm - { - public: - Algorithm(); - virtual ~Algorithm(); - /**Returns the algorithm name*/ - String name() const; - - /** @brief returns the algorithm parameter - - The method returns value of the particular parameter. Since the compiler can not deduce the - type of the returned parameter, you should specify it explicitly in angle brackets. Here are - the allowed forms of get: - - - myalgo.get\("param_name") - - myalgo.get\("param_name") - - myalgo.get\("param_name") - - myalgo.get\("param_name") - - myalgo.get\("param_name") - - myalgo.get\ \>("param_name") - - myalgo.get\("param_name") (it returns Ptr\). - - In some cases the actual type of the parameter can be cast to the specified type, e.g. integer - parameter can be cast to double, bool can be cast to int. But "dangerous" transformations - (string\<-\>number, double-\>int, 1x1 Mat\<-\>number, ...) are not performed and the method - will throw an exception. In the case of Mat or vector\ parameters the method does not - clone the matrix data, so do not modify the matrices. Use Algorithm::set instead - slower, but - more safe. - @param name The parameter name. - */ - template typename ParamType<_Tp>::member_type get(const String& name) const; - /** @overload */ - template typename ParamType<_Tp>::member_type get(const char* name) const; - - CV_WRAP int getInt(const String& name) const; - CV_WRAP double getDouble(const String& name) const; - CV_WRAP bool getBool(const String& name) const; - CV_WRAP String getString(const String& name) const; - CV_WRAP Mat getMat(const String& name) const; - CV_WRAP std::vector getMatVector(const String& name) const; - CV_WRAP Ptr getAlgorithm(const String& name) const; - - /** @brief Sets the algorithm parameter - - The method sets value of the particular parameter. Some of the algorithm - parameters may be declared as read-only. If you try to set such a - parameter, you will get exception with the corresponding error message. - @param name The parameter name. - @param value The parameter value. - */ - void set(const String& name, int value); - void set(const String& name, double value); - void set(const String& name, bool value); - void set(const String& name, const String& value); - void set(const String& name, const Mat& value); - void set(const String& name, const std::vector& value); - void set(const String& name, const Ptr& value); - template void set(const String& name, const Ptr<_Tp>& value); - - CV_WRAP void setInt(const String& name, int value); - CV_WRAP void setDouble(const String& name, double value); - CV_WRAP void setBool(const String& name, bool value); - CV_WRAP void setString(const String& name, const String& value); - CV_WRAP void setMat(const String& name, const Mat& value); - CV_WRAP void setMatVector(const String& name, const std::vector& value); - CV_WRAP void setAlgorithm(const String& name, const Ptr& value); - template void setAlgorithm(const String& name, const Ptr<_Tp>& value); - - void set(const char* name, int value); - void set(const char* name, double value); - void set(const char* name, bool value); - void set(const char* name, const String& value); - void set(const char* name, const Mat& value); - void set(const char* name, const std::vector& value); - void set(const char* name, const Ptr& value); - template void set(const char* name, const Ptr<_Tp>& value); - - void setInt(const char* name, int value); - void setDouble(const char* name, double value); - void setBool(const char* name, bool value); - void setString(const char* name, const String& value); - void setMat(const char* name, const Mat& value); - void setMatVector(const char* name, const std::vector& value); - void setAlgorithm(const char* name, const Ptr& value); - template void setAlgorithm(const char* name, const Ptr<_Tp>& value); - - CV_WRAP String paramHelp(const String& name) const; - int paramType(const char* name) const; - CV_WRAP int paramType(const String& name) const; - CV_WRAP void getParams(CV_OUT std::vector& names) const; - - /** @brief Stores algorithm parameters in a file storage - - The method stores all the algorithm parameters (in alphabetic order) to - the file storage. The method is virtual. If you define your own - Algorithm derivative, your can override the method and store some extra - information. However, it's rarely needed. Here are some examples: - - SIFT feature detector (from xfeatures2d module). The class only - stores algorithm parameters and no keypoints or their descriptors. - Therefore, it's enough to store the algorithm parameters, which is - what Algorithm::write() does. Therefore, there is no dedicated - SIFT::write(). - - Background subtractor (from video module). It has the algorithm - parameters and also it has the current background model. However, - the background model is not stored. First, it's rather big. Then, - if you have stored the background model, it would likely become - irrelevant on the next run (because of shifted camera, changed - background, different lighting etc.). Therefore, - BackgroundSubtractorMOG and BackgroundSubtractorMOG2 also rely on - the standard Algorithm::write() to store just the algorithm - parameters. - - Expectation Maximization (from ml module). The algorithm finds - mixture of gaussians that approximates user data best of all. In - this case the model may be re-used on the next run to test new - data against the trained statistical model. So EM needs to store - the model. However, since the model is described by a few - parameters that are available as read-only algorithm parameters - (i.e. they are available via EM::get()), EM also relies on - Algorithm::write() to store both EM parameters and the model - (represented by read-only algorithm parameters). - @param fs File storage. - */ - virtual void write(FileStorage& fs) const; - - /** @brief Reads algorithm parameters from a file storage - - The method reads all the algorithm parameters from the specified node of - a file storage. Similarly to Algorithm::write(), if you implement an - algorithm that needs to read some extra data and/or re-compute some - internal data, you may override the method. - @param fn File node of the file storage. - */ - virtual void read(const FileNode& fn); - - typedef Algorithm* (*Constructor)(void); - typedef int (Algorithm::*Getter)() const; - typedef void (Algorithm::*Setter)(int); - - /** @brief Returns the list of registered algorithms - - This static method returns the list of registered algorithms in - alphabetical order. Here is how to use it : - @code{.cpp} - vector algorithms; - Algorithm::getList(algorithms); - cout << "Algorithms: " << algorithms.size() << endl; - for (size_t i=0; i < algorithms.size(); i++) - cout << algorithms[i] << endl; - @endcode - @param algorithms The output vector of algorithm names. - */ - CV_WRAP static void getList(CV_OUT std::vector& algorithms); - CV_WRAP static Ptr _create(const String& name); - - /** @brief Creates algorithm instance by name - - This static method creates a new instance of the specified algorithm. If - there is no such algorithm, the method will silently return a null - pointer. Also, you should specify the particular Algorithm subclass as - _Tp (or simply Algorithm if you do not know it at that point). : - @code{.cpp} - Ptr bgfg = Algorithm::create("BackgroundSubtractor.MOG2"); - @endcode - @note This is important note about seemingly mysterious behavior of - Algorithm::create() when it returns NULL while it should not. The reason - is simple - Algorithm::create() resides in OpenCV's core module and the - algorithms are implemented in other modules. If you create algorithms - dynamically, C++ linker may decide to throw away the modules where the - actual algorithms are implemented, since you do not call any functions - from the modules. To avoid this problem, you need to call - initModule_\(); somewhere in the beginning of the program - before Algorithm::create(). For example, call initModule_xfeatures2d() - in order to use SURF/SIFT, call initModule_ml() to use expectation - maximization etc. - @param name The algorithm name, one of the names returned by Algorithm::getList(). - */ - template static Ptr<_Tp> create(const String& name); - - virtual AlgorithmInfo* info() const /* TODO: make it = 0;*/ { return 0; } -}; - -/** @todo document */ -class CV_EXPORTS AlgorithmInfo { public: - friend class Algorithm; - AlgorithmInfo(const String& name, Algorithm::Constructor create); - ~AlgorithmInfo(); - void get(const Algorithm* algo, const char* name, int argType, void* value) const; - void addParam_(Algorithm& algo, const char* name, int argType, - void* value, bool readOnly, - Algorithm::Getter getter, Algorithm::Setter setter, - const String& help=String()); - String paramHelp(const char* name) const; - int paramType(const char* name) const; - void getParams(std::vector& names) const; + Algorithm(); + virtual ~Algorithm(); - void write(const Algorithm* algo, FileStorage& fs) const; - void read(Algorithm* algo, const FileNode& fn) const; - String name() const; + /** @brief Stores algorithm parameters in a file storage + */ + virtual void write(FileStorage& fs) const { (void)fs; } - void addParam(Algorithm& algo, const char* name, - int& value, bool readOnly=false, - int (Algorithm::*getter)()=0, - void (Algorithm::*setter)(int)=0, - const String& help=String()); - void addParam(Algorithm& algo, const char* name, - bool& value, bool readOnly=false, - int (Algorithm::*getter)()=0, - void (Algorithm::*setter)(int)=0, - const String& help=String()); - void addParam(Algorithm& algo, const char* name, - double& value, bool readOnly=false, - double (Algorithm::*getter)()=0, - void (Algorithm::*setter)(double)=0, - const String& help=String()); - void addParam(Algorithm& algo, const char* name, - String& value, bool readOnly=false, - String (Algorithm::*getter)()=0, - void (Algorithm::*setter)(const String&)=0, - const String& help=String()); - void addParam(Algorithm& algo, const char* name, - Mat& value, bool readOnly=false, - Mat (Algorithm::*getter)()=0, - void (Algorithm::*setter)(const Mat&)=0, - const String& help=String()); - void addParam(Algorithm& algo, const char* name, - std::vector& value, bool readOnly=false, - std::vector (Algorithm::*getter)()=0, - void (Algorithm::*setter)(const std::vector&)=0, - const String& help=String()); - void addParam(Algorithm& algo, const char* name, - Ptr& value, bool readOnly=false, - Ptr (Algorithm::*getter)()=0, - void (Algorithm::*setter)(const Ptr&)=0, - const String& help=String()); - void addParam(Algorithm& algo, const char* name, - float& value, bool readOnly=false, - float (Algorithm::*getter)()=0, - void (Algorithm::*setter)(float)=0, - const String& help=String()); - void addParam(Algorithm& algo, const char* name, - unsigned int& value, bool readOnly=false, - unsigned int (Algorithm::*getter)()=0, - void (Algorithm::*setter)(unsigned int)=0, - const String& help=String()); - void addParam(Algorithm& algo, const char* name, - uint64& value, bool readOnly=false, - uint64 (Algorithm::*getter)()=0, - void (Algorithm::*setter)(uint64)=0, - const String& help=String()); - void addParam(Algorithm& algo, const char* name, - uchar& value, bool readOnly=false, - uchar (Algorithm::*getter)()=0, - void (Algorithm::*setter)(uchar)=0, - const String& help=String()); - template void addParam(Algorithm& algo, const char* name, - Ptr<_Tp>& value, bool readOnly=false, - Ptr<_Tp> (Algorithm::*getter)()=0, - void (Algorithm::*setter)(const Ptr<_Tp>&)=0, - const String& help=String()); - template void addParam(Algorithm& algo, const char* name, - Ptr<_Tp>& value, bool readOnly=false, - Ptr<_Tp> (Algorithm::*getter)()=0, - void (Algorithm::*setter)(const Ptr<_Tp>&)=0, - const String& help=String()); -protected: - AlgorithmInfoData* data; - void set(Algorithm* algo, const char* name, int argType, - const void* value, bool force=false) const; + /** @brief Reads algorithm parameters from a file storage + */ + virtual void read(const FileNode& fn) { (void)fn; } }; -/** @todo document */ -struct CV_EXPORTS Param -{ - enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7, UNSIGNED_INT=8, UINT64=9, UCHAR=11 }; +// define properties - Param(); - Param(int _type, bool _readonly, int _offset, - Algorithm::Getter _getter=0, - Algorithm::Setter _setter=0, - const String& _help=String()); - int type; - int offset; - bool readonly; - Algorithm::Getter getter; - Algorithm::Setter setter; - String help; +#define CV_PURE_PROPERTY(type, name) \ + CV_WRAP virtual type get##name() const = 0; \ + CV_WRAP virtual void set##name(type _##name) = 0; + +#define CV_PURE_PROPERTY_S(type, name) \ + CV_WRAP virtual type get##name() const = 0; \ + CV_WRAP virtual void set##name(const type & _##name) = 0; + +#define CV_PURE_PROPERTY_RO(type, name) \ + CV_WRAP virtual type get##name() const = 0; + +// basic property implementation + +#define CV_IMPL_PROPERTY(type, name, member) \ + type get##name() const \ + { \ + return member; \ + } \ + void set##name(type val) \ + { \ + member = val; \ + } + +#define CV_IMPL_PROPERTY_S(type, name, member) \ + type get##name() const \ + { \ + return member; \ + } \ + void set##name(const type &val) \ + { \ + member = val; \ + } + +#define CV_IMPL_PROPERTY_RO(type, name, member) \ + type get##name() const \ + { \ + return member; \ + } + + +struct Param { + enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7, + UNSIGNED_INT=8, UINT64=9, UCHAR=11 }; }; + + template<> struct ParamType { typedef bool const_param_type; diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index dd9fe1e7b..067140abb 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -412,84 +412,6 @@ int print(const Matx<_Tp, m, n>& matx, FILE* stream = stdout) return print(Formatter::get()->format(cv::Mat(matx)), stream); } - - -////////////////////////////////////////// Algorithm ////////////////////////////////////////// - -template inline -Ptr<_Tp> Algorithm::create(const String& name) -{ - return _create(name).dynamicCast<_Tp>(); -} - -template inline -void Algorithm::set(const char* _name, const Ptr<_Tp>& value) -{ - Ptr algo_ptr = value. template dynamicCast(); - if (!algo_ptr) { - CV_Error( Error::StsUnsupportedFormat, "unknown/unsupported Ptr type of the second parameter of the method Algorithm::set"); - } - info()->set(this, _name, ParamType::type, &algo_ptr); -} - -template inline -void Algorithm::set(const String& _name, const Ptr<_Tp>& value) -{ - this->set<_Tp>(_name.c_str(), value); -} - -template inline -void Algorithm::setAlgorithm(const char* _name, const Ptr<_Tp>& value) -{ - Ptr algo_ptr = value. template ptr(); - if (!algo_ptr) { - CV_Error( Error::StsUnsupportedFormat, "unknown/unsupported Ptr type of the second parameter of the method Algorithm::set"); - } - info()->set(this, _name, ParamType::type, &algo_ptr); -} - -template inline -void Algorithm::setAlgorithm(const String& _name, const Ptr<_Tp>& value) -{ - this->set<_Tp>(_name.c_str(), value); -} - -template inline -typename ParamType<_Tp>::member_type Algorithm::get(const String& _name) const -{ - typename ParamType<_Tp>::member_type value; - info()->get(this, _name.c_str(), ParamType<_Tp>::type, &value); - return value; -} - -template inline -typename ParamType<_Tp>::member_type Algorithm::get(const char* _name) const -{ - typename ParamType<_Tp>::member_type value; - info()->get(this, _name, ParamType<_Tp>::type, &value); - return value; -} - -template inline -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, Ptr<_Tp>& value, bool readOnly, - Ptr<_Tp> (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr<_Tp>&), - const String& help) -{ - //TODO: static assert: _Tp inherits from _Base - addParam_(algo, parameter, ParamType<_Base>::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - -template inline -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, Ptr<_Tp>& value, bool readOnly, - Ptr<_Tp> (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr<_Tp>&), - const String& help) -{ - //TODO: static assert: _Tp inherits from Algorithm - addParam_(algo, parameter, ParamType::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - //! @endcond /****************************************************************************************\ diff --git a/modules/core/include/opencv2/core/private.hpp b/modules/core/include/opencv2/core/private.hpp index c9b2bf66d..38d18e300 100644 --- a/modules/core/include/opencv2/core/private.hpp +++ b/modules/core/include/opencv2/core/private.hpp @@ -129,40 +129,6 @@ namespace cv CV_EXPORTS const char* currentParallelFramework(); } //namespace cv -#define CV_INIT_ALGORITHM(classname, algname, memberinit) \ - static inline ::cv::Algorithm* create##classname##_hidden() \ - { \ - return new classname; \ - } \ - \ - static inline ::cv::Ptr< ::cv::Algorithm> create##classname##_ptr_hidden() \ - { \ - return ::cv::makePtr(); \ - } \ - \ - static inline ::cv::AlgorithmInfo& classname##_info() \ - { \ - static ::cv::AlgorithmInfo classname##_info_var(algname, create##classname##_hidden); \ - return classname##_info_var; \ - } \ - \ - static ::cv::AlgorithmInfo& classname##_info_auto = classname##_info(); \ - \ - ::cv::AlgorithmInfo* classname::info() const \ - { \ - static volatile bool initialized = false; \ - \ - if( !initialized ) \ - { \ - initialized = true; \ - classname obj; \ - memberinit; \ - } \ - return &classname##_info(); \ - } - - - /****************************************************************************************\ * Common declarations * \****************************************************************************************/ diff --git a/modules/core/src/algorithm.cpp b/modules/core/src/algorithm.cpp index f817a987b..b10a28988 100644 --- a/modules/core/src/algorithm.cpp +++ b/modules/core/src/algorithm.cpp @@ -45,127 +45,6 @@ namespace cv { -template struct sorted_vector -{ - sorted_vector() {} - void clear() { vec.clear(); } - size_t size() const { return vec.size(); } - _ValueTp& operator [](size_t idx) { return vec[idx]; } - const _ValueTp& operator [](size_t idx) const { return vec[idx]; } - - void add(const _KeyTp& k, const _ValueTp& val) - { - std::pair<_KeyTp, _ValueTp> p(k, val); - vec.push_back(p); - size_t i = vec.size()-1; - for( ; i > 0 && vec[i].first < vec[i-1].first; i-- ) - std::swap(vec[i-1], vec[i]); - CV_Assert( i == 0 || vec[i].first != vec[i-1].first ); - } - - bool find(const _KeyTp& key, _ValueTp& value) const - { - size_t a = 0, b = vec.size(); - while( b > a ) - { - size_t c = (a + b)/2; - if( vec[c].first < key ) - a = c+1; - else - b = c; - } - - if( a < vec.size() && vec[a].first == key ) - { - value = vec[a].second; - return true; - } - return false; - } - - void get_keys(std::vector<_KeyTp>& keys) const - { - size_t i = 0, n = vec.size(); - keys.resize(n); - - for( i = 0; i < n; i++ ) - keys[i] = vec[i].first; - } - - std::vector > vec; -}; - - -template inline const _ValueTp* findstr(const sorted_vector& vec, - const char* key) -{ - if( !key ) - return 0; - - size_t a = 0, b = vec.vec.size(); - while( b > a ) - { - size_t c = (a + b)/2; - if( strcmp(vec.vec[c].first.c_str(), key) < 0 ) - a = c+1; - else - b = c; - } - - if( ( a < vec.vec.size() ) && ( strcmp(vec.vec[a].first.c_str(), key) == 0 )) - return &vec.vec[a].second; - return 0; -} - - -Param::Param() -{ - type = 0; - offset = 0; - readonly = false; - getter = 0; - setter = 0; -} - - -Param::Param(int _type, bool _readonly, int _offset, - Algorithm::Getter _getter, Algorithm::Setter _setter, - const String& _help) -{ - type = _type; - readonly = _readonly; - offset = _offset; - getter = _getter; - setter = _setter; - help = _help; -} - -struct CV_EXPORTS AlgorithmInfoData -{ - sorted_vector params; - String _name; -}; - - -static sorted_vector& alglist() -{ - static sorted_vector alglist_var; - return alglist_var; -} - -void Algorithm::getList(std::vector& algorithms) -{ - alglist().get_keys(algorithms); -} - -Ptr Algorithm::_create(const String& name) -{ - Algorithm::Constructor c = 0; - if( !alglist().find(name, c) ) - return Ptr(); - return Ptr(c()); -} - Algorithm::Algorithm() { } @@ -174,1052 +53,6 @@ Algorithm::~Algorithm() { } -String Algorithm::name() const -{ - return info()->name(); -} - -void Algorithm::set(const String& parameter, int value) -{ - info()->set(this, parameter.c_str(), ParamType::type, &value); -} - -void Algorithm::set(const String& parameter, double value) -{ - info()->set(this, parameter.c_str(), ParamType::type, &value); -} - -void Algorithm::set(const String& parameter, bool value) -{ - info()->set(this, parameter.c_str(), ParamType::type, &value); -} - -void Algorithm::set(const String& parameter, const String& value) -{ - info()->set(this, parameter.c_str(), ParamType::type, &value); -} - -void Algorithm::set(const String& parameter, const Mat& value) -{ - info()->set(this, parameter.c_str(), ParamType::type, &value); -} - -void Algorithm::set(const String& parameter, const std::vector& value) -{ - info()->set(this, parameter.c_str(), ParamType >::type, &value); -} - -void Algorithm::set(const String& parameter, const Ptr& value) -{ - info()->set(this, parameter.c_str(), ParamType::type, &value); -} - -void Algorithm::set(const char* parameter, int value) -{ - info()->set(this, parameter, ParamType::type, &value); -} - -void Algorithm::set(const char* parameter, double value) -{ - info()->set(this, parameter, ParamType::type, &value); -} - -void Algorithm::set(const char* parameter, bool value) -{ - info()->set(this, parameter, ParamType::type, &value); -} - -void Algorithm::set(const char* parameter, const String& value) -{ - info()->set(this, parameter, ParamType::type, &value); -} - -void Algorithm::set(const char* parameter, const Mat& value) -{ - info()->set(this, parameter, ParamType::type, &value); -} - -void Algorithm::set(const char* parameter, const std::vector& value) -{ - info()->set(this, parameter, ParamType >::type, &value); -} - -void Algorithm::set(const char* parameter, const Ptr& value) -{ - info()->set(this, parameter, ParamType::type, &value); -} - - -void Algorithm::setInt(const String& parameter, int value) -{ - info()->set(this, parameter.c_str(), ParamType::type, &value); -} - -void Algorithm::setDouble(const String& parameter, double value) -{ - info()->set(this, parameter.c_str(), ParamType::type, &value); -} - -void Algorithm::setBool(const String& parameter, bool value) -{ - info()->set(this, parameter.c_str(), ParamType::type, &value); -} - -void Algorithm::setString(const String& parameter, const String& value) -{ - info()->set(this, parameter.c_str(), ParamType::type, &value); -} - -void Algorithm::setMat(const String& parameter, const Mat& value) -{ - info()->set(this, parameter.c_str(), ParamType::type, &value); -} - -void Algorithm::setMatVector(const String& parameter, const std::vector& value) -{ - info()->set(this, parameter.c_str(), ParamType >::type, &value); -} - -void Algorithm::setAlgorithm(const String& parameter, const Ptr& value) -{ - info()->set(this, parameter.c_str(), ParamType::type, &value); -} - -void Algorithm::setInt(const char* parameter, int value) -{ - info()->set(this, parameter, ParamType::type, &value); -} - -void Algorithm::setDouble(const char* parameter, double value) -{ - info()->set(this, parameter, ParamType::type, &value); -} - -void Algorithm::setBool(const char* parameter, bool value) -{ - info()->set(this, parameter, ParamType::type, &value); -} - -void Algorithm::setString(const char* parameter, const String& value) -{ - info()->set(this, parameter, ParamType::type, &value); -} - -void Algorithm::setMat(const char* parameter, const Mat& value) -{ - info()->set(this, parameter, ParamType::type, &value); -} - -void Algorithm::setMatVector(const char* parameter, const std::vector& value) -{ - info()->set(this, parameter, ParamType >::type, &value); -} - -void Algorithm::setAlgorithm(const char* parameter, const Ptr& value) -{ - info()->set(this, parameter, ParamType::type, &value); -} - - - -int Algorithm::getInt(const String& parameter) const -{ - return get(parameter); -} - -double Algorithm::getDouble(const String& parameter) const -{ - return get(parameter); -} - -bool Algorithm::getBool(const String& parameter) const -{ - return get(parameter); -} - -String Algorithm::getString(const String& parameter) const -{ - return get(parameter); -} - -Mat Algorithm::getMat(const String& parameter) const -{ - return get(parameter); -} - -std::vector Algorithm::getMatVector(const String& parameter) const -{ - return get >(parameter); -} - -Ptr Algorithm::getAlgorithm(const String& parameter) const -{ - return get(parameter); -} - -String Algorithm::paramHelp(const String& parameter) const -{ - return info()->paramHelp(parameter.c_str()); -} - -int Algorithm::paramType(const String& parameter) const -{ - return info()->paramType(parameter.c_str()); -} - -int Algorithm::paramType(const char* parameter) const -{ - return info()->paramType(parameter); -} - -void Algorithm::getParams(std::vector& names) const -{ - info()->getParams(names); -} - -void Algorithm::write(FileStorage& fs) const -{ - info()->write(this, fs); -} - -void Algorithm::read(const FileNode& fn) -{ - info()->read(this, fn); -} - - -AlgorithmInfo::AlgorithmInfo(const String& _name, Algorithm::Constructor create) -{ - data = new AlgorithmInfoData; - data->_name = _name; - if (!alglist().find(_name, create)) - alglist().add(_name, create); -} - -AlgorithmInfo::~AlgorithmInfo() -{ - delete data; -} - -void AlgorithmInfo::write(const Algorithm* algo, FileStorage& fs) const -{ - size_t i = 0, nparams = data->params.vec.size(); - cv::write(fs, "name", algo->name()); - for( i = 0; i < nparams; i++ ) - { - const Param& p = data->params.vec[i].second; - const String& pname = data->params.vec[i].first; - if( p.type == Param::INT ) - cv::write(fs, pname, algo->get(pname)); - else if( p.type == Param::BOOLEAN ) - cv::write(fs, pname, (int)algo->get(pname)); - else if( p.type == Param::REAL ) - cv::write(fs, pname, algo->get(pname)); - else if( p.type == Param::STRING ) - cv::write(fs, pname, algo->get(pname)); - else if( p.type == Param::MAT ) - cv::write(fs, pname, algo->get(pname)); - else if( p.type == Param::MAT_VECTOR ) - cv::write(fs, pname, algo->get >(pname)); - else if( p.type == Param::ALGORITHM ) - { - cv::internal::WriteStructContext ws(fs, pname, CV_NODE_MAP); - Ptr nestedAlgo = algo->get(pname); - nestedAlgo->write(fs); - } - else if( p.type == Param::FLOAT) - cv::write(fs, pname, algo->getDouble(pname)); - else if( p.type == Param::UNSIGNED_INT) - cv::write(fs, pname, algo->getInt(pname));//TODO: implement cv::write(, , unsigned int) - else if( p.type == Param::UINT64) - cv::write(fs, pname, algo->getInt(pname));//TODO: implement cv::write(, , uint64) - else if( p.type == Param::UCHAR) - cv::write(fs, pname, algo->getInt(pname)); - else - { - String msg = format("unknown/unsupported type of '%s' parameter == %d", pname.c_str(), p.type); - CV_Error( CV_StsUnsupportedFormat, msg.c_str()); - } - } -} - -void AlgorithmInfo::read(Algorithm* algo, const FileNode& fn) const -{ - size_t i = 0, nparams = data->params.vec.size(); - AlgorithmInfo* info = algo->info(); - - for( i = 0; i < nparams; i++ ) - { - const Param& p = data->params.vec[i].second; - const String& pname = data->params.vec[i].first; - const FileNode n = fn[pname]; - if( n.empty() ) - continue; - if( p.type == Param::INT ) - { - int val = (int)n; - info->set(algo, pname.c_str(), p.type, &val, true); - } - else if( p.type == Param::BOOLEAN ) - { - bool val = (int)n != 0; - info->set(algo, pname.c_str(), p.type, &val, true); - } - else if( p.type == Param::REAL ) - { - double val = (double)n; - info->set(algo, pname.c_str(), p.type, &val, true); - } - else if( p.type == Param::STRING ) - { - String val = (String)n; - info->set(algo, pname.c_str(), p.type, &val, true); - } - else if( p.type == Param::MAT ) - { - Mat m; - cv::read(n, m); - info->set(algo, pname.c_str(), p.type, &m, true); - } - else if( p.type == Param::MAT_VECTOR ) - { - std::vector mv; - cv::read(n, mv); - info->set(algo, pname.c_str(), p.type, &mv, true); - } - else if( p.type == Param::ALGORITHM ) - { - Ptr nestedAlgo = Algorithm::_create((String)n["name"]); - CV_Assert( nestedAlgo ); - nestedAlgo->read(n); - info->set(algo, pname.c_str(), p.type, &nestedAlgo, true); - } - else if( p.type == Param::FLOAT ) - { - float val = (float)n; - info->set(algo, pname.c_str(), p.type, &val, true); - } - else if( p.type == Param::UNSIGNED_INT ) - { - unsigned int val = (unsigned int)((int)n);//TODO: implement conversion (unsigned int)FileNode - info->set(algo, pname.c_str(), p.type, &val, true); - } - else if( p.type == Param::UINT64) - { - uint64 val = (uint64)((int)n);//TODO: implement conversion (uint64)FileNode - info->set(algo, pname.c_str(), p.type, &val, true); - } - else if( p.type == Param::UCHAR) - { - uchar val = (uchar)((int)n); - info->set(algo, pname.c_str(), p.type, &val, true); - } - else - { - String msg = format("unknown/unsupported type of '%s' parameter == %d", pname.c_str(), p.type); - CV_Error( CV_StsUnsupportedFormat, msg.c_str()); - } - } -} - -String AlgorithmInfo::name() const -{ - return data->_name; -} - -union GetSetParam -{ - int (Algorithm::*get_int)() const; - bool (Algorithm::*get_bool)() const; - double (Algorithm::*get_double)() const; - String (Algorithm::*get_string)() const; - Mat (Algorithm::*get_mat)() const; - std::vector (Algorithm::*get_mat_vector)() const; - Ptr (Algorithm::*get_algo)() const; - float (Algorithm::*get_float)() const; - unsigned int (Algorithm::*get_uint)() const; - uint64 (Algorithm::*get_uint64)() const; - uchar (Algorithm::*get_uchar)() const; - - void (Algorithm::*set_int)(int); - void (Algorithm::*set_bool)(bool); - void (Algorithm::*set_double)(double); - void (Algorithm::*set_string)(const String&); - void (Algorithm::*set_mat)(const Mat&); - void (Algorithm::*set_mat_vector)(const std::vector&); - void (Algorithm::*set_algo)(const Ptr&); - void (Algorithm::*set_float)(float); - void (Algorithm::*set_uint)(unsigned int); - void (Algorithm::*set_uint64)(uint64); - void (Algorithm::*set_uchar)(uchar); -}; - -static String getNameOfType(int argType); - -static String getNameOfType(int argType) -{ - switch(argType) - { - case Param::INT: return "integer"; - case Param::BOOLEAN: return "boolean"; - case Param::REAL: return "double"; - case Param::STRING: return "string"; - case Param::MAT: return "cv::Mat"; - case Param::MAT_VECTOR: return "std::vector"; - case Param::ALGORITHM: return "algorithm"; - case Param::FLOAT: return "float"; - case Param::UNSIGNED_INT: return "unsigned int"; - case Param::UINT64: return "unsigned int64"; - case Param::UCHAR: return "unsigned char"; - default: CV_Error(CV_StsBadArg, "Wrong argument type"); - } - return ""; -} - -static String getErrorMessageForWrongArgumentInSetter(String algoName, String paramName, int paramType, int argType) -{ - String message = String("Argument error: the setter") - + " method was called for the parameter '" + paramName + "' of the algorithm '" + algoName - +"', the parameter has " + getNameOfType(paramType) + " type, "; - - if (paramType == Param::INT || paramType == Param::BOOLEAN || paramType == Param::REAL - || paramType == Param::FLOAT || paramType == Param::UNSIGNED_INT || paramType == Param::UINT64 || paramType == Param::UCHAR) - { - message = message + "so it should be set by integer, unsigned integer, uint64, unsigned char, boolean, float or double value, "; - } - message = message + "but the setter was called with " + getNameOfType(argType) + " value"; - - return message; -} - -static String getErrorMessageForWrongArgumentInGetter(String algoName, String paramName, int paramType, int argType) -{ - String message = String("Argument error: the getter") - + " method was called for the parameter '" + paramName + "' of the algorithm '" + algoName - +"', the parameter has " + getNameOfType(paramType) + " type, "; - - if (paramType == Param::BOOLEAN) - { - message = message + "so it should be get as integer, unsigned integer, uint64, boolean, unsigned char, float or double value, "; - } - else if (paramType == Param::INT || paramType == Param::UNSIGNED_INT || paramType == Param::UINT64 || paramType == Param::UCHAR) - { - message = message + "so it should be get as integer, unsigned integer, uint64, unsigned char, float or double value, "; - } - message = message + "but the getter was called to get a " + getNameOfType(argType) + " value"; - - return message; -} - -void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, const void* value, bool force) const -{ - const Param* p = findstr(data->params, parameter); - - if( !p ) - CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "") ); - - if( !force && p->readonly ) - CV_Error_( CV_StsError, ("Parameter '%s' is readonly", parameter)); - - GetSetParam f; - f.set_int = p->setter; - - if( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL - || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR) - { - if ( !( p->type == Param::INT || p->type == Param::REAL || p->type == Param::BOOLEAN - || p->type == Param::UNSIGNED_INT || p->type == Param::UINT64 || p->type == Param::FLOAT || p->type == Param::UCHAR) ) - { - String message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - - if( p->type == Param::INT ) - { - bool is_ok = true; - int val = argType == Param::INT ? *(const int*)value : - argType == Param::BOOLEAN ? (int)*(const bool*)value : - argType == Param::REAL ? saturate_cast(*(const double*)value) : - argType == Param::FLOAT ? saturate_cast(*(const float*)value) : - argType == Param::UNSIGNED_INT ? (int)*(const unsigned int*)value : - argType == Param::UINT64 ? (int)*(const uint64*)value : - argType == Param::UCHAR ? (int)*(const uchar*)value : - (int)(is_ok = false); - - if (!is_ok) - { - CV_Error(CV_StsBadArg, "Wrong argument type in the setter"); - } - - if( p->setter ) - (algo->*f.set_int)(val); - else - *(int*)((uchar*)algo + p->offset) = val; - } - else if( p->type == Param::BOOLEAN ) - { - bool is_ok = true; - bool val = argType == Param::INT ? *(const int*)value != 0 : - argType == Param::BOOLEAN ? *(const bool*)value : - argType == Param::REAL ? (*(const double*)value != 0) : - argType == Param::FLOAT ? (*(const float*)value != 0) : - argType == Param::UNSIGNED_INT ? (*(const unsigned int*)value != 0): - argType == Param::UINT64 ? (*(const uint64*)value != 0): - argType == Param::UCHAR ? (*(const uchar*)value != 0): - (int)(is_ok = false); - - if (!is_ok) - { - CV_Error(CV_StsBadArg, "Wrong argument type in the setter"); - } - - if( p->setter ) - (algo->*f.set_bool)(val); - else - *(bool*)((uchar*)algo + p->offset) = val; - } - else if( p->type == Param::REAL ) - { - bool is_ok = true; - double val = argType == Param::INT ? (double)*(const int*)value : - argType == Param::BOOLEAN ? (double)*(const bool*)value : - argType == Param::REAL ? (double)(*(const double*)value ) : - argType == Param::FLOAT ? (double)(*(const float*)value ) : - argType == Param::UNSIGNED_INT ? (double)(*(const unsigned int*)value ) : - argType == Param::UINT64 ? (double)(*(const uint64*)value ) : - argType == Param::UCHAR ? (double)(*(const uchar*)value ) : - (double)(is_ok = false); - - if (!is_ok) - { - CV_Error(CV_StsBadArg, "Wrong argument type in the setter"); - } - if( p->setter ) - (algo->*f.set_double)(val); - else - *(double*)((uchar*)algo + p->offset) = val; - } - else if( p->type == Param::FLOAT ) - { - bool is_ok = true; - double val = argType == Param::INT ? (double)*(const int*)value : - argType == Param::BOOLEAN ? (double)*(const bool*)value : - argType == Param::REAL ? (double)(*(const double*)value ) : - argType == Param::FLOAT ? (double)(*(const float*)value ) : - argType == Param::UNSIGNED_INT ? (double)(*(const unsigned int*)value ) : - argType == Param::UINT64 ? (double)(*(const uint64*)value ) : - argType == Param::UCHAR ? (double)(*(const uchar*)value ) : - (double)(is_ok = false); - - if (!is_ok) - { - CV_Error(CV_StsBadArg, "Wrong argument type in the setter"); - } - if( p->setter ) - (algo->*f.set_float)((float)val); - else - *(float*)((uchar*)algo + p->offset) = (float)val; - } - else if( p->type == Param::UNSIGNED_INT ) - { - bool is_ok = true; - unsigned int val = argType == Param::INT ? (unsigned int)*(const int*)value : - argType == Param::BOOLEAN ? (unsigned int)*(const bool*)value : - argType == Param::REAL ? saturate_cast(*(const double*)value ) : - argType == Param::FLOAT ? saturate_cast(*(const float*)value ) : - argType == Param::UNSIGNED_INT ? (unsigned int)(*(const unsigned int*)value ) : - argType == Param::UINT64 ? (unsigned int)(*(const uint64*)value ) : - argType == Param::UCHAR ? (unsigned int)(*(const uchar*)value ) : - (int)(is_ok = false); - - if (!is_ok) - { - CV_Error(CV_StsBadArg, "Wrong argument type in the setter"); - } - if( p->setter ) - (algo->*f.set_uint)(val); - else - *(unsigned int*)((uchar*)algo + p->offset) = val; - } - else if( p->type == Param::UINT64 ) - { - bool is_ok = true; - uint64 val = argType == Param::INT ? (uint64)*(const int*)value : - argType == Param::BOOLEAN ? (uint64)*(const bool*)value : - argType == Param::REAL ? saturate_cast(*(const double*)value ) : - argType == Param::FLOAT ? saturate_cast(*(const float*)value ) : - argType == Param::UNSIGNED_INT ? (uint64)(*(const unsigned int*)value ) : - argType == Param::UINT64 ? (uint64)(*(const uint64*)value ) : - argType == Param::UCHAR ? (uint64)(*(const uchar*)value ) : - (int)(is_ok = false); - - if (!is_ok) - { - CV_Error(CV_StsBadArg, "Wrong argument type in the setter"); - } - if( p->setter ) - (algo->*f.set_uint64)(val); - else - *(uint64*)((uchar*)algo + p->offset) = val; - } - else if( p->type == Param::UCHAR ) - { - bool is_ok = true; - uchar val = argType == Param::INT ? (uchar)*(const int*)value : - argType == Param::BOOLEAN ? (uchar)*(const bool*)value : - argType == Param::REAL ? saturate_cast(*(const double*)value ) : - argType == Param::FLOAT ? saturate_cast(*(const float*)value ) : - argType == Param::UNSIGNED_INT ? (uchar)(*(const unsigned int*)value ) : - argType == Param::UINT64 ? (uchar)(*(const uint64*)value ) : - argType == Param::UCHAR ? (uchar)(*(const uchar*)value ) : - (int)(is_ok = false); - - if (!is_ok) - { - CV_Error(CV_StsBadArg, "Wrong argument type in the setter"); - } - if( p->setter ) - (algo->*f.set_uchar)(val); - else - *(uchar*)((uchar*)algo + p->offset) = val; - } - else - CV_Error(CV_StsBadArg, "Wrong parameter type in the setter"); - } - else if( argType == Param::STRING ) - { - if( p->type != Param::STRING ) - { - String message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - - const String& val = *(const String*)value; - if( p->setter ) - (algo->*f.set_string)(val); - else - *(String*)((uchar*)algo + p->offset) = val; - } - else if( argType == Param::MAT ) - { - if( p->type != Param::MAT ) - { - String message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - - const Mat& val = *(const Mat*)value; - if( p->setter ) - (algo->*f.set_mat)(val); - else - *(Mat*)((uchar*)algo + p->offset) = val; - } - else if( argType == Param::MAT_VECTOR ) - { - if( p->type != Param::MAT_VECTOR ) - { - String message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - - const std::vector& val = *(const std::vector*)value; - if( p->setter ) - (algo->*f.set_mat_vector)(val); - else - *(std::vector*)((uchar*)algo + p->offset) = val; - } - else if( argType == Param::ALGORITHM ) - { - if( p->type != Param::ALGORITHM ) - { - String message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - - const Ptr& val = *(const Ptr*)value; - if( p->setter ) - (algo->*f.set_algo)(val); - else - *(Ptr*)((uchar*)algo + p->offset) = val; - } - else - CV_Error(CV_StsBadArg, "Unknown/unsupported parameter type"); -} - -void AlgorithmInfo::get(const Algorithm* algo, const char* parameter, int argType, void* value) const -{ - const Param* p = findstr(data->params, parameter); - if( !p ) - CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "") ); - - GetSetParam f; - f.get_int = p->getter; - - if( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL - || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR) - { - if( p->type == Param::INT ) - { - if (!( argType == Param::INT || argType == Param::REAL || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR)) - { - String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - int val = p->getter ? (algo->*f.get_int)() : *(int*)((uchar*)algo + p->offset); - - if( argType == Param::INT ) - *(int*)value = (int)val; - else if ( argType == Param::REAL ) - *(double*)value = (double)val; - else if ( argType == Param::FLOAT) - *(float*)value = (float)val; - else if ( argType == Param::UNSIGNED_INT ) - *(unsigned int*)value = (unsigned int)val; - else if ( argType == Param::UINT64 ) - *(uint64*)value = (uint64)val; - else if ( argType == Param::UCHAR) - *(uchar*)value = (uchar)val; - else - CV_Error(CV_StsBadArg, "Wrong argument type"); - - } - else if( p->type == Param::BOOLEAN ) - { - if (!( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR)) - { - String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - bool val = p->getter ? (algo->*f.get_bool)() : *(bool*)((uchar*)algo + p->offset); - - if( argType == Param::INT ) - *(int*)value = (int)val; - else if( argType == Param::BOOLEAN ) - *(bool*)value = val; - else if ( argType == Param::REAL ) - *(double*)value = (int)val; - else if ( argType == Param::FLOAT) - *(float*)value = (float)((int)val); - else if ( argType == Param::UNSIGNED_INT ) - *(unsigned int*)value = (unsigned int)val; - else if ( argType == Param::UINT64 ) - *(uint64*)value = (int)val; - else if ( argType == Param::UCHAR) - *(uchar*)value = (uchar)val; - else - CV_Error(CV_StsBadArg, "Wrong argument type"); - } - else if( p->type == Param::REAL ) - { - if(!( argType == Param::REAL || argType == Param::FLOAT)) - { - String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - double val = p->getter ? (algo->*f.get_double)() : *(double*)((uchar*)algo + p->offset); - - if ( argType == Param::REAL ) - *(double*)value = val; - else if ( argType == Param::FLOAT) - *(float*)value = (float)val; - else - CV_Error(CV_StsBadArg, "Wrong argument type"); - } - else if( p->type == Param::FLOAT ) - { - if(!( argType == Param::REAL || argType == Param::FLOAT)) - { - String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - float val = p->getter ? (algo->*f.get_float)() : *(float*)((uchar*)algo + p->offset); - - if ( argType == Param::REAL ) - *(double*)value = (double)val; - else if ( argType == Param::FLOAT) - *(float*)value = (float)val; - else - CV_Error(CV_StsBadArg, "Wrong argument type"); - } - else if( p->type == Param::UNSIGNED_INT ) - { - if (!( argType == Param::INT || argType == Param::REAL || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR)) - { - String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - unsigned int val = p->getter ? (algo->*f.get_uint)() : *(unsigned int*)((uchar*)algo + p->offset); - - if( argType == Param::INT ) - *(int*)value = (int)val; - else if ( argType == Param::REAL ) - *(double*)value = (double)val; - else if ( argType == Param::FLOAT) - *(float*)value = (float)val; - else if ( argType == Param::UNSIGNED_INT ) - *(unsigned int*)value = (unsigned int)val; - else if ( argType == Param::UINT64 ) - *(uint64*)value = (uint64)val; - else if ( argType == Param::UCHAR) - *(uchar*)value = (uchar)val; - else - CV_Error(CV_StsBadArg, "Wrong argument type"); - } - else if( p->type == Param::UINT64 ) - { - if (!( argType == Param::INT || argType == Param::REAL || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR)) - { - String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - uint64 val = p->getter ? (algo->*f.get_uint64)() : *(uint64*)((uchar*)algo + p->offset); - - if( argType == Param::INT ) - *(int*)value = (int)val; - else if ( argType == Param::REAL ) - *(double*)value = (double)val; - else if ( argType == Param::FLOAT) - *(float*)value = (float)val; - else if ( argType == Param::UNSIGNED_INT ) - *(unsigned int*)value = (unsigned int)val; - else if ( argType == Param::UINT64 ) - *(uint64*)value = (uint64)val; - else if ( argType == Param::UCHAR) - *(uchar*)value = (uchar)val; - else - CV_Error(CV_StsBadArg, "Wrong argument type"); - } - else if( p->type == Param::UCHAR ) - { - if (!( argType == Param::INT || argType == Param::REAL || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR)) - { - String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - uchar val = p->getter ? (algo->*f.get_uchar)() : *(uchar*)((uchar*)algo + p->offset); - - if( argType == Param::INT ) - *(int*)value = val; - else if ( argType == Param::REAL ) - *(double*)value = val; - else if ( argType == Param::FLOAT) - *(float*)value = val; - else if ( argType == Param::UNSIGNED_INT ) - *(unsigned int*)value = val; - else if ( argType == Param::UINT64 ) - *(uint64*)value = val; - else if ( argType == Param::UCHAR) - *(uchar*)value = val; - else - CV_Error(CV_StsBadArg, "Wrong argument type"); - - } - else - CV_Error(CV_StsBadArg, "Unknown/unsupported parameter type"); - } - else if( argType == Param::STRING ) - { - if( p->type != Param::STRING ) - { - String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - - *(String*)value = p->getter ? (algo->*f.get_string)() : - *(String*)((uchar*)algo + p->offset); - } - else if( argType == Param::MAT ) - { - if( p->type != Param::MAT ) - { - String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - - *(Mat*)value = p->getter ? (algo->*f.get_mat)() : - *(Mat*)((uchar*)algo + p->offset); - } - else if( argType == Param::MAT_VECTOR ) - { - if( p->type != Param::MAT_VECTOR ) - { - String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - - *(std::vector*)value = p->getter ? (algo->*f.get_mat_vector)() : - *(std::vector*)((uchar*)algo + p->offset); - } - else if( argType == Param::ALGORITHM ) - { - if( p->type != Param::ALGORITHM ) - { - String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } - - *(Ptr*)value = p->getter ? (algo->*f.get_algo)() : - *(Ptr*)((uchar*)algo + p->offset); - } - else - { - String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); - CV_Error(CV_StsBadArg, message); - } -} - - -int AlgorithmInfo::paramType(const char* parameter) const -{ - const Param* p = findstr(data->params, parameter); - if( !p ) - CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "") ); - return p->type; -} - - -String AlgorithmInfo::paramHelp(const char* parameter) const -{ - const Param* p = findstr(data->params, parameter); - if( !p ) - CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "") ); - return p->help; -} - - -void AlgorithmInfo::getParams(std::vector& names) const -{ - data->params.get_keys(names); -} - - -void AlgorithmInfo::addParam_(Algorithm& algo, const char* parameter, int argType, - void* value, bool readOnly, - Algorithm::Getter getter, Algorithm::Setter setter, - const String& help) -{ - CV_Assert( argType == Param::INT || argType == Param::BOOLEAN || - argType == Param::REAL || argType == Param::STRING || - argType == Param::MAT || argType == Param::MAT_VECTOR || - argType == Param::ALGORITHM - || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 - || argType == Param::UCHAR); - data->params.add(String(parameter), Param(argType, readOnly, - (int)((size_t)value - (size_t)(void*)&algo), - getter, setter, help)); -} - - -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - int& value, bool readOnly, - int (Algorithm::*getter)(), - void (Algorithm::*setter)(int), - const String& help) -{ - addParam_(algo, parameter, ParamType::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - bool& value, bool readOnly, - int (Algorithm::*getter)(), - void (Algorithm::*setter)(int), - const String& help) -{ - addParam_(algo, parameter, ParamType::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - double& value, bool readOnly, - double (Algorithm::*getter)(), - void (Algorithm::*setter)(double), - const String& help) -{ - addParam_(algo, parameter, ParamType::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - String& value, bool readOnly, - String (Algorithm::*getter)(), - void (Algorithm::*setter)(const String&), - const String& help) -{ - addParam_(algo, parameter, ParamType::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - Mat& value, bool readOnly, - Mat (Algorithm::*getter)(), - void (Algorithm::*setter)(const Mat&), - const String& help) -{ - addParam_(algo, parameter, ParamType::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - std::vector& value, bool readOnly, - std::vector (Algorithm::*getter)(), - void (Algorithm::*setter)(const std::vector&), - const String& help) -{ - addParam_(algo, parameter, ParamType >::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - Ptr& value, bool readOnly, - Ptr (Algorithm::*getter)(), - void (Algorithm::*setter)(const Ptr&), - const String& help) -{ - addParam_(algo, parameter, ParamType::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - float& value, bool readOnly, - float (Algorithm::*getter)(), - void (Algorithm::*setter)(float), - const String& help) -{ - addParam_(algo, parameter, ParamType::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - unsigned int& value, bool readOnly, - unsigned int (Algorithm::*getter)(), - void (Algorithm::*setter)(unsigned int), - const String& help) -{ - addParam_(algo, parameter, ParamType::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - uint64& value, bool readOnly, - uint64 (Algorithm::*getter)(), - void (Algorithm::*setter)(uint64), - const String& help) -{ - addParam_(algo, parameter, ParamType::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - -void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - uchar& value, bool readOnly, - uchar (Algorithm::*getter)(), - void (Algorithm::*setter)(uchar), - const String& help) -{ - addParam_(algo, parameter, ParamType::type, &value, readOnly, - (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); -} - } /* End of file. */ diff --git a/modules/cudaimgproc/src/histogram.cpp b/modules/cudaimgproc/src/histogram.cpp index e942e9eb8..0ccce205a 100644 --- a/modules/cudaimgproc/src/histogram.cpp +++ b/modules/cudaimgproc/src/histogram.cpp @@ -140,8 +140,6 @@ namespace public: CLAHE_Impl(double clipLimit = 40.0, int tilesX = 8, int tilesY = 8); - cv::AlgorithmInfo* info() const; - void apply(cv::InputArray src, cv::OutputArray dst); void apply(InputArray src, OutputArray dst, Stream& stream); @@ -167,11 +165,6 @@ namespace { } - CV_INIT_ALGORITHM(CLAHE_Impl, "CLAHE_CUDA", - obj.info()->addParam(obj, "clipLimit", obj.clipLimit_); - obj.info()->addParam(obj, "tilesX", obj.tilesX_); - obj.info()->addParam(obj, "tilesY", obj.tilesY_)) - void CLAHE_Impl::apply(cv::InputArray _src, cv::OutputArray _dst) { apply(_src, _dst, Stream::Null()); diff --git a/modules/cudaoptflow/perf/perf_optflow.cpp b/modules/cudaoptflow/perf/perf_optflow.cpp index 32040f282..8480425cc 100644 --- a/modules/cudaoptflow/perf/perf_optflow.cpp +++ b/modules/cudaoptflow/perf/perf_optflow.cpp @@ -310,10 +310,10 @@ PERF_TEST_P(ImagePair, OpticalFlowDual_TVL1, { cv::Mat flow; - cv::Ptr alg = cv::createOptFlow_DualTVL1(); - alg->set("medianFiltering", 1); - alg->set("innerIterations", 1); - alg->set("outerIterations", 300); + cv::Ptr alg = cv::createOptFlow_DualTVL1(); + alg->setMedianFiltering(1); + alg->setInnerIterations(1); + alg->setOuterIterations(300); TEST_CYCLE() alg->calc(frame0, frame1, flow); CPU_SANITY_CHECK(flow); diff --git a/modules/cudaoptflow/test/test_optflow.cpp b/modules/cudaoptflow/test/test_optflow.cpp index c5b2ad847..63bc461bb 100644 --- a/modules/cudaoptflow/test/test_optflow.cpp +++ b/modules/cudaoptflow/test/test_optflow.cpp @@ -369,11 +369,11 @@ CUDA_TEST_P(OpticalFlowDual_TVL1, Accuracy) cv::cuda::GpuMat d_flow; d_alg->calc(loadMat(frame0), loadMat(frame1), d_flow); - cv::Ptr alg = cv::createOptFlow_DualTVL1(); - alg->set("medianFiltering", 1); - alg->set("innerIterations", 1); - alg->set("outerIterations", d_alg->getNumIterations()); - alg->set("gamma", gamma); + cv::Ptr alg = cv::createOptFlow_DualTVL1(); + alg->setMedianFiltering(1); + alg->setInnerIterations(1); + alg->setOuterIterations(d_alg->getNumIterations()); + alg->setGamma(gamma); cv::Mat flow; alg->calc(frame0, frame1, flow); diff --git a/modules/imgproc/src/clahe.cpp b/modules/imgproc/src/clahe.cpp index 06fc73153..75edd18e4 100644 --- a/modules/imgproc/src/clahe.cpp +++ b/modules/imgproc/src/clahe.cpp @@ -320,8 +320,6 @@ namespace public: CLAHE_Impl(double clipLimit = 40.0, int tilesX = 8, int tilesY = 8); - cv::AlgorithmInfo* info() const; - void apply(cv::InputArray src, cv::OutputArray dst); void setClipLimit(double clipLimit); @@ -351,11 +349,6 @@ namespace { } - CV_INIT_ALGORITHM(CLAHE_Impl, "CLAHE", - obj.info()->addParam(obj, "clipLimit", obj.clipLimit_); - obj.info()->addParam(obj, "tilesX", obj.tilesX_); - obj.info()->addParam(obj, "tilesY", obj.tilesY_)) - void CLAHE_Impl::apply(cv::InputArray _src, cv::OutputArray _dst) { CV_Assert( _src.type() == CV_8UC1 || _src.type() == CV_16UC1 ); diff --git a/modules/shape/include/opencv2/shape.hpp b/modules/shape/include/opencv2/shape.hpp index 093d8575d..6999476a7 100644 --- a/modules/shape/include/opencv2/shape.hpp +++ b/modules/shape/include/opencv2/shape.hpp @@ -52,11 +52,6 @@ @defgroup shape Shape Distance and Matching */ -namespace cv -{ -CV_EXPORTS bool initModule_shape(); -} - #endif /* End of file. */ diff --git a/modules/shape/src/aff_trans.cpp b/modules/shape/src/aff_trans.cpp index a309d85fc..ec2342f47 100644 --- a/modules/shape/src/aff_trans.cpp +++ b/modules/shape/src/aff_trans.cpp @@ -66,8 +66,6 @@ public: { } - virtual AlgorithmInfo* info() const { return 0; } - //! the main operator virtual void estimateTransformation(InputArray transformingShape, InputArray targetShape, std::vector &matches); virtual float applyTransformation(InputArray input, OutputArray output=noArray()); diff --git a/modules/shape/src/haus_dis.cpp b/modules/shape/src/haus_dis.cpp index ff5bd8c3d..6f2679f1a 100644 --- a/modules/shape/src/haus_dis.cpp +++ b/modules/shape/src/haus_dis.cpp @@ -60,8 +60,6 @@ public: { } - virtual AlgorithmInfo* info() const { return 0; } - //! the main operator virtual float computeDistance(InputArray contour1, InputArray contour2); diff --git a/modules/shape/src/hist_cost.cpp b/modules/shape/src/hist_cost.cpp index 4e18687ad..53c2c68ec 100644 --- a/modules/shape/src/hist_cost.cpp +++ b/modules/shape/src/hist_cost.cpp @@ -62,8 +62,6 @@ public: { } - virtual AlgorithmInfo* info() const { return 0; } - //! the main operator virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix); @@ -189,8 +187,6 @@ public: { } - virtual AlgorithmInfo* info() const { return 0; } - //! the main operator virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix); @@ -327,8 +323,6 @@ public: { } - virtual AlgorithmInfo* info() const { return 0; } - //! the main operator virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix); @@ -445,8 +439,6 @@ public: { } - virtual AlgorithmInfo* info() const { return 0; } - //! the main operator virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix); diff --git a/modules/shape/src/sc_dis.cpp b/modules/shape/src/sc_dis.cpp index d67907494..3f11e8b1b 100644 --- a/modules/shape/src/sc_dis.cpp +++ b/modules/shape/src/sc_dis.cpp @@ -79,8 +79,6 @@ public: { } - virtual AlgorithmInfo* info() const { return 0; } - //! the main operator virtual float computeDistance(InputArray contour1, InputArray contour2); diff --git a/modules/shape/src/tps_trans.cpp b/modules/shape/src/tps_trans.cpp index 61758bd0b..038fd2a67 100644 --- a/modules/shape/src/tps_trans.cpp +++ b/modules/shape/src/tps_trans.cpp @@ -68,8 +68,6 @@ public: { } - virtual AlgorithmInfo* info() const { return 0; } - //! the main operators virtual void estimateTransformation(InputArray transformingShape, InputArray targetShape, std::vector &matches); virtual float applyTransformation(InputArray inPts, OutputArray output=noArray()); diff --git a/modules/superres/include/opencv2/superres.hpp b/modules/superres/include/opencv2/superres.hpp index e5bca4b31..0639b1042 100644 --- a/modules/superres/include/opencv2/superres.hpp +++ b/modules/superres/include/opencv2/superres.hpp @@ -44,6 +44,7 @@ #define __OPENCV_SUPERRES_HPP__ #include "opencv2/core.hpp" +#include "opencv2/superres/optical_flow.hpp" /** @defgroup superres Super Resolution @@ -62,8 +63,6 @@ namespace cv //! @addtogroup superres //! @{ - CV_EXPORTS bool initModule_superres(); - class CV_EXPORTS FrameSource { public: @@ -105,6 +104,36 @@ namespace cv */ virtual void collectGarbage(); + //! @name Scale factor + CV_PURE_PROPERTY(int, Scale) + + //! @name Iterations count + CV_PURE_PROPERTY(int, Iterations) + + //! @name Asymptotic value of steepest descent method + CV_PURE_PROPERTY(double, Tau) + + //! @name Weight parameter to balance data term and smoothness term + CV_PURE_PROPERTY(double, Labmda) + + //! @name Parameter of spacial distribution in Bilateral-TV + CV_PURE_PROPERTY(double, Alpha) + + //! @name Kernel size of Bilateral-TV filter + CV_PURE_PROPERTY(int, KernelSize) + + //! @name Gaussian blur kernel size + CV_PURE_PROPERTY(int, BlurKernelSize) + + //! @name Gaussian blur sigma + CV_PURE_PROPERTY(double, BlurSigma) + + //! @name Radius of the temporal search area + CV_PURE_PROPERTY(int, TemporalAreaRadius) + + //! @name Dense optical flow algorithm + CV_PURE_PROPERTY_S(Ptr, OpticalFlow) + protected: SuperResolution(); @@ -139,7 +168,6 @@ namespace cv */ CV_EXPORTS Ptr createSuperResolution_BTVL1(); CV_EXPORTS Ptr createSuperResolution_BTVL1_CUDA(); - CV_EXPORTS Ptr createSuperResolution_BTVL1_OCL(); //! @} superres diff --git a/modules/superres/include/opencv2/superres/optical_flow.hpp b/modules/superres/include/opencv2/superres/optical_flow.hpp index d4362c4fe..7bc64782c 100644 --- a/modules/superres/include/opencv2/superres/optical_flow.hpp +++ b/modules/superres/include/opencv2/superres/optical_flow.hpp @@ -60,20 +60,68 @@ namespace cv virtual void collectGarbage() = 0; }; - CV_EXPORTS Ptr createOptFlow_Farneback(); - CV_EXPORTS Ptr createOptFlow_Farneback_CUDA(); - CV_EXPORTS Ptr createOptFlow_Farneback_OCL(); - CV_EXPORTS Ptr createOptFlow_Simple(); + class CV_EXPORTS FarnebackOpticalFlow : public virtual DenseOpticalFlowExt + { + public: + CV_PURE_PROPERTY(double, PyrScale) + CV_PURE_PROPERTY(int, LevelsNumber) + CV_PURE_PROPERTY(int, WindowSize) + CV_PURE_PROPERTY(int, Iterations) + CV_PURE_PROPERTY(int, PolyN) + CV_PURE_PROPERTY(double, PolySigma) + CV_PURE_PROPERTY(int, Flags) + }; + CV_EXPORTS Ptr createOptFlow_Farneback(); + CV_EXPORTS Ptr createOptFlow_Farneback_CUDA(); - CV_EXPORTS Ptr createOptFlow_DualTVL1(); - CV_EXPORTS Ptr createOptFlow_DualTVL1_CUDA(); - CV_EXPORTS Ptr createOptFlow_DualTVL1_OCL(); - CV_EXPORTS Ptr createOptFlow_Brox_CUDA(); +// CV_EXPORTS Ptr createOptFlow_Simple(); - CV_EXPORTS Ptr createOptFlow_PyrLK_CUDA(); - CV_EXPORTS Ptr createOptFlow_PyrLK_OCL(); + + class CV_EXPORTS DualTVL1OpticalFlow : public virtual DenseOpticalFlowExt + { + public: + CV_PURE_PROPERTY(double, Tau) + CV_PURE_PROPERTY(double, Lambda) + CV_PURE_PROPERTY(double, Theta) + CV_PURE_PROPERTY(int, ScalesNumber) + CV_PURE_PROPERTY(int, WarpingsNumber) + CV_PURE_PROPERTY(double, Epsilon) + CV_PURE_PROPERTY(int, Iterations) + CV_PURE_PROPERTY(bool, UseInitialFlow) + }; + CV_EXPORTS Ptr createOptFlow_DualTVL1(); + CV_EXPORTS Ptr createOptFlow_DualTVL1_CUDA(); + + + class CV_EXPORTS BroxOpticalFlow : public virtual DenseOpticalFlowExt + { + public: + //! @name Flow smoothness + CV_PURE_PROPERTY(double, Alpha) + //! @name Gradient constancy importance + CV_PURE_PROPERTY(double, Gamma) + //! @name Pyramid scale factor + CV_PURE_PROPERTY(double, ScaleFactor) + //! @name Number of lagged non-linearity iterations (inner loop) + CV_PURE_PROPERTY(int, InnerIterations) + //! @name Number of warping iterations (number of pyramid levels) + CV_PURE_PROPERTY(int, OuterIterations) + //! @name Number of linear system solver iterations + CV_PURE_PROPERTY(int, SolverIterations) + }; + CV_EXPORTS Ptr createOptFlow_Brox_CUDA(); + + + class PyrLKOpticalFlow : public virtual DenseOpticalFlowExt + { + public: + CV_PURE_PROPERTY(int, WindowSize) + CV_PURE_PROPERTY(int, MaxLevel) + CV_PURE_PROPERTY(int, Iterations) + }; + CV_EXPORTS Ptr createOptFlow_PyrLK_CUDA(); //! @} diff --git a/modules/superres/perf/perf_superres.cpp b/modules/superres/perf/perf_superres.cpp index e8b3ef754..f9c881aff 100644 --- a/modules/superres/perf/perf_superres.cpp +++ b/modules/superres/perf/perf_superres.cpp @@ -138,10 +138,10 @@ PERF_TEST_P(Size_MatType, SuperResolution_BTVL1, { Ptr superRes = createSuperResolution_BTVL1_CUDA(); - superRes->set("scale", scale); - superRes->set("iterations", iterations); - superRes->set("temporalAreaRadius", temporalAreaRadius); - superRes->set("opticalFlow", opticalFlow); + superRes->setScale(scale); + superRes->setIterations(iterations); + superRes->setTemporalAreaRadius(temporalAreaRadius); + superRes->setOpticalFlow(opticalFlow); superRes->setInput(makePtr(GpuMat(frame))); @@ -156,10 +156,10 @@ PERF_TEST_P(Size_MatType, SuperResolution_BTVL1, { Ptr superRes = createSuperResolution_BTVL1(); - superRes->set("scale", scale); - superRes->set("iterations", iterations); - superRes->set("temporalAreaRadius", temporalAreaRadius); - superRes->set("opticalFlow", opticalFlow); + superRes->setScale(scale); + superRes->setIterations(iterations); + superRes->setTemporalAreaRadius(temporalAreaRadius); + superRes->setOpticalFlow(opticalFlow); superRes->setInput(makePtr(frame)); @@ -198,10 +198,10 @@ OCL_PERF_TEST_P(SuperResolution_BTVL1 ,BTVL1, Ptr opticalFlow(new ZeroOpticalFlow); Ptr superRes = createSuperResolution_BTVL1(); - superRes->set("scale", scale); - superRes->set("iterations", iterations); - superRes->set("temporalAreaRadius", temporalAreaRadius); - superRes->set("opticalFlow", opticalFlow); + superRes->setScale(scale); + superRes->setIterations(iterations); + superRes->setTemporalAreaRadius(temporalAreaRadius); + superRes->setOpticalFlow(opticalFlow); superRes->setInput(makePtr(frame)); diff --git a/modules/superres/src/btv_l1.cpp b/modules/superres/src/btv_l1.cpp index 6b6c3c3e7..291fa1bcb 100644 --- a/modules/superres/src/btv_l1.cpp +++ b/modules/superres/src/btv_l1.cpp @@ -460,7 +460,7 @@ namespace func(_src, _dst, btvKernelSize, btvWeights); } - class BTVL1_Base + class BTVL1_Base : public cv::superres::SuperResolution { public: BTVL1_Base(); @@ -470,6 +470,17 @@ namespace void collectGarbage(); + CV_IMPL_PROPERTY(int, Scale, scale_) + CV_IMPL_PROPERTY(int, Iterations, iterations_) + CV_IMPL_PROPERTY(double, Tau, tau_) + CV_IMPL_PROPERTY(double, Labmda, lambda_) + CV_IMPL_PROPERTY(double, Alpha, alpha_) + CV_IMPL_PROPERTY(int, KernelSize, btvKernelSize_) + CV_IMPL_PROPERTY(int, BlurKernelSize, blurKernelSize_) + CV_IMPL_PROPERTY(double, BlurSigma, blurSigma_) + CV_IMPL_PROPERTY(int, TemporalAreaRadius, temporalAreaRadius_) + CV_IMPL_PROPERTY_S(Ptr, OpticalFlow, opticalFlow_) + protected: int scale_; int iterations_; @@ -479,7 +490,8 @@ namespace int btvKernelSize_; int blurKernelSize_; double blurSigma_; - Ptr opticalFlow_; + int temporalAreaRadius_; // not used in some implementations + Ptr opticalFlow_; private: bool ocl_process(InputArrayOfArrays src, OutputArray dst, InputArrayOfArrays forwardMotions, @@ -539,6 +551,7 @@ namespace btvKernelSize_ = 7; blurKernelSize_ = 5; blurSigma_ = 0.0; + temporalAreaRadius_ = 0; opticalFlow_ = createOptFlow_Farneback(); curBlurKernelSize_ = -1; @@ -781,12 +794,9 @@ namespace //////////////////////////////////////////////////////////////////// - class BTVL1 : - public SuperResolution, private BTVL1_Base + class BTVL1 : public BTVL1_Base { public: - AlgorithmInfo* info() const; - BTVL1(); void collectGarbage(); @@ -799,8 +809,6 @@ namespace bool ocl_processImpl(Ptr& frameSource, OutputArray output); private: - int temporalAreaRadius_; - void readNextFrame(Ptr& frameSource); bool ocl_readNextFrame(Ptr& frameSource); @@ -841,18 +849,6 @@ namespace #endif }; - CV_INIT_ALGORITHM(BTVL1, "SuperResolution.BTVL1", - obj.info()->addParam(obj, "scale", obj.scale_, false, 0, 0, "Scale factor."); - obj.info()->addParam(obj, "iterations", obj.iterations_, false, 0, 0, "Iteration count."); - obj.info()->addParam(obj, "tau", obj.tau_, false, 0, 0, "Asymptotic value of steepest descent method."); - obj.info()->addParam(obj, "lambda", obj.lambda_, false, 0, 0, "Weight parameter to balance data term and smoothness term."); - obj.info()->addParam(obj, "alpha", obj.alpha_, false, 0, 0, "Parameter of spacial distribution in Bilateral-TV."); - obj.info()->addParam(obj, "btvKernelSize", obj.btvKernelSize_, false, 0, 0, "Kernel size of Bilateral-TV filter."); - obj.info()->addParam(obj, "blurKernelSize", obj.blurKernelSize_, false, 0, 0, "Gaussian blur kernel size."); - obj.info()->addParam(obj, "blurSigma", obj.blurSigma_, false, 0, 0, "Gaussian blur sigma."); - obj.info()->addParam(obj, "temporalAreaRadius", obj.temporalAreaRadius_, false, 0, 0, "Radius of the temporal search area."); - obj.info()->addParam(obj, "opticalFlow", obj.opticalFlow_, false, 0, 0, "Dense optical flow algorithm.")) - BTVL1::BTVL1() { temporalAreaRadius_ = 4; @@ -1101,7 +1097,7 @@ namespace } } -Ptr cv::superres::createSuperResolution_BTVL1() +Ptr cv::superres::createSuperResolution_BTVL1() { return makePtr(); } diff --git a/modules/superres/src/btv_l1_cuda.cpp b/modules/superres/src/btv_l1_cuda.cpp index f72e3846e..b8d3eace1 100644 --- a/modules/superres/src/btv_l1_cuda.cpp +++ b/modules/superres/src/btv_l1_cuda.cpp @@ -207,7 +207,7 @@ namespace funcs[src.channels()](src, dst, ksize); } - class BTVL1_CUDA_Base + class BTVL1_CUDA_Base : public cv::superres::SuperResolution { public: BTVL1_CUDA_Base(); @@ -218,6 +218,17 @@ namespace void collectGarbage(); + CV_IMPL_PROPERTY(int, Scale, scale_) + CV_IMPL_PROPERTY(int, Iterations, iterations_) + CV_IMPL_PROPERTY(double, Tau, tau_) + CV_IMPL_PROPERTY(double, Labmda, lambda_) + CV_IMPL_PROPERTY(double, Alpha, alpha_) + CV_IMPL_PROPERTY(int, KernelSize, btvKernelSize_) + CV_IMPL_PROPERTY(int, BlurKernelSize, blurKernelSize_) + CV_IMPL_PROPERTY(double, BlurSigma, blurSigma_) + CV_IMPL_PROPERTY(int, TemporalAreaRadius, temporalAreaRadius_) + CV_IMPL_PROPERTY_S(Ptr, OpticalFlow, opticalFlow_) + protected: int scale_; int iterations_; @@ -227,7 +238,8 @@ namespace int btvKernelSize_; int blurKernelSize_; double blurSigma_; - Ptr opticalFlow_; + int temporalAreaRadius_; + Ptr opticalFlow_; private: std::vector > filters_; @@ -272,6 +284,7 @@ namespace #else opticalFlow_ = createOptFlow_Farneback(); #endif + temporalAreaRadius_ = 0; curBlurKernelSize_ = -1; curBlurSigma_ = -1.0; @@ -401,11 +414,9 @@ namespace //////////////////////////////////////////////////////////// - class BTVL1_CUDA : public SuperResolution, private BTVL1_CUDA_Base + class BTVL1_CUDA : public BTVL1_CUDA_Base { public: - AlgorithmInfo* info() const; - BTVL1_CUDA(); void collectGarbage(); @@ -415,8 +426,6 @@ namespace void processImpl(Ptr& frameSource, OutputArray output); private: - int temporalAreaRadius_; - void readNextFrame(Ptr& frameSource); void processFrame(int idx); @@ -438,18 +447,6 @@ namespace GpuMat finalOutput_; }; - CV_INIT_ALGORITHM(BTVL1_CUDA, "SuperResolution.BTVL1_CUDA", - obj.info()->addParam(obj, "scale", obj.scale_, false, 0, 0, "Scale factor."); - obj.info()->addParam(obj, "iterations", obj.iterations_, false, 0, 0, "Iteration count."); - obj.info()->addParam(obj, "tau", obj.tau_, false, 0, 0, "Asymptotic value of steepest descent method."); - obj.info()->addParam(obj, "lambda", obj.lambda_, false, 0, 0, "Weight parameter to balance data term and smoothness term."); - obj.info()->addParam(obj, "alpha", obj.alpha_, false, 0, 0, "Parameter of spacial distribution in Bilateral-TV."); - obj.info()->addParam(obj, "btvKernelSize", obj.btvKernelSize_, false, 0, 0, "Kernel size of Bilateral-TV filter."); - obj.info()->addParam(obj, "blurKernelSize", obj.blurKernelSize_, false, 0, 0, "Gaussian blur kernel size."); - obj.info()->addParam(obj, "blurSigma", obj.blurSigma_, false, 0, 0, "Gaussian blur sigma."); - obj.info()->addParam(obj, "temporalAreaRadius", obj.temporalAreaRadius_, false, 0, 0, "Radius of the temporal search area."); - obj.info()->addParam(obj, "opticalFlow", obj.opticalFlow_, false, 0, 0, "Dense optical flow algorithm.")); - BTVL1_CUDA::BTVL1_CUDA() { temporalAreaRadius_ = 4; diff --git a/modules/superres/src/optical_flow.cpp b/modules/superres/src/optical_flow.cpp index 52fc2648e..a08a58bd9 100644 --- a/modules/superres/src/optical_flow.cpp +++ b/modules/superres/src/optical_flow.cpp @@ -53,7 +53,7 @@ using namespace cv::superres::detail; namespace { - class CpuOpticalFlow : public DenseOpticalFlowExt + class CpuOpticalFlow : public virtual cv::superres::DenseOpticalFlowExt { public: explicit CpuOpticalFlow(int work_type); @@ -173,12 +173,20 @@ namespace namespace { - class Farneback : public CpuOpticalFlow + class Farneback : public CpuOpticalFlow, public cv::superres::FarnebackOpticalFlow { public: - AlgorithmInfo* info() const; - Farneback(); + void calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2); + void collectGarbage(); + + CV_IMPL_PROPERTY(double, PyrScale, pyrScale_) + CV_IMPL_PROPERTY(int, LevelsNumber, numLevels_) + CV_IMPL_PROPERTY(int, WindowSize, winSize_) + CV_IMPL_PROPERTY(int, Iterations, numIters_) + CV_IMPL_PROPERTY(int, PolyN, polyN_) + CV_IMPL_PROPERTY(double, PolySigma, polySigma_) + CV_IMPL_PROPERTY(int, Flags, flags_) protected: void impl(InputArray input0, InputArray input1, OutputArray dst); @@ -193,15 +201,6 @@ namespace int flags_; }; - CV_INIT_ALGORITHM(Farneback, "DenseOpticalFlowExt.Farneback", - obj.info()->addParam(obj, "pyrScale", obj.pyrScale_); - obj.info()->addParam(obj, "numLevels", obj.numLevels_); - obj.info()->addParam(obj, "winSize", obj.winSize_); - obj.info()->addParam(obj, "numIters", obj.numIters_); - obj.info()->addParam(obj, "polyN", obj.polyN_); - obj.info()->addParam(obj, "polySigma", obj.polySigma_); - obj.info()->addParam(obj, "flags", obj.flags_)) - Farneback::Farneback() : CpuOpticalFlow(CV_8UC1) { pyrScale_ = 0.5; @@ -213,6 +212,16 @@ namespace flags_ = 0; } + void Farneback::calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2) + { + CpuOpticalFlow::calc(frame0, frame1, flow1, flow2); + } + + void Farneback::collectGarbage() + { + CpuOpticalFlow::collectGarbage(); + } + void Farneback::impl(InputArray input0, InputArray input1, OutputArray dst) { calcOpticalFlowFarneback(input0, input1, (InputOutputArray)dst, pyrScale_, @@ -221,7 +230,7 @@ namespace } } -Ptr cv::superres::createOptFlow_Farneback() +Ptr cv::superres::createOptFlow_Farneback() { return makePtr(); } @@ -319,65 +328,53 @@ Ptr cv::superres::createOptFlow_Simple() namespace { - class DualTVL1 : public CpuOpticalFlow + #define CV_WRAP_PROPERTY(type, name, internal_name, internal_obj) \ + type get##name() const \ + { \ + return internal_obj->get##internal_name(); \ + } \ + void set##name(type _name) \ + { \ + internal_obj->set##internal_name(_name); \ + } + + #define CV_WRAP_SAME_PROPERTY(type, name, internal_obj) CV_WRAP_PROPERTY(type, name, name, internal_obj) + + class DualTVL1 : public CpuOpticalFlow, public virtual cv::superres::DualTVL1OpticalFlow { public: - AlgorithmInfo* info() const; - DualTVL1(); - + void calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2); void collectGarbage(); + CV_WRAP_SAME_PROPERTY(double, Tau, alg_) + CV_WRAP_SAME_PROPERTY(double, Lambda, alg_) + CV_WRAP_SAME_PROPERTY(double, Theta, alg_) + CV_WRAP_SAME_PROPERTY(int, ScalesNumber, alg_) + CV_WRAP_SAME_PROPERTY(int, WarpingsNumber, alg_) + CV_WRAP_SAME_PROPERTY(double, Epsilon, alg_) + CV_WRAP_PROPERTY(int, Iterations, OuterIterations, alg_) + CV_WRAP_SAME_PROPERTY(bool, UseInitialFlow, alg_) + protected: void impl(InputArray input0, InputArray input1, OutputArray dst); private: - double tau_; - double lambda_; - double theta_; - int nscales_; - int warps_; - double epsilon_; - int iterations_; - bool useInitialFlow_; - - Ptr alg_; + Ptr alg_; }; - CV_INIT_ALGORITHM(DualTVL1, "DenseOpticalFlowExt.DualTVL1", - obj.info()->addParam(obj, "tau", obj.tau_); - obj.info()->addParam(obj, "lambda", obj.lambda_); - obj.info()->addParam(obj, "theta", obj.theta_); - obj.info()->addParam(obj, "nscales", obj.nscales_); - obj.info()->addParam(obj, "warps", obj.warps_); - obj.info()->addParam(obj, "epsilon", obj.epsilon_); - obj.info()->addParam(obj, "iterations", obj.iterations_); - obj.info()->addParam(obj, "useInitialFlow", obj.useInitialFlow_)) - DualTVL1::DualTVL1() : CpuOpticalFlow(CV_8UC1) { alg_ = cv::createOptFlow_DualTVL1(); - tau_ = alg_->getDouble("tau"); - lambda_ = alg_->getDouble("lambda"); - theta_ = alg_->getDouble("theta"); - nscales_ = alg_->getInt("nscales"); - warps_ = alg_->getInt("warps"); - epsilon_ = alg_->getDouble("epsilon"); - iterations_ = alg_->getInt("iterations"); - useInitialFlow_ = alg_->getBool("useInitialFlow"); + } + + void DualTVL1::calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2) + { + CpuOpticalFlow::calc(frame0, frame1, flow1, flow2); } void DualTVL1::impl(InputArray input0, InputArray input1, OutputArray dst) { - alg_->set("tau", tau_); - alg_->set("lambda", lambda_); - alg_->set("theta", theta_); - alg_->set("nscales", nscales_); - alg_->set("warps", warps_); - alg_->set("epsilon", epsilon_); - alg_->set("iterations", iterations_); - alg_->set("useInitialFlow", useInitialFlow_); - alg_->calc(input0, input1, (InputOutputArray)dst); } @@ -388,7 +385,7 @@ namespace } } -Ptr cv::superres::createOptFlow_DualTVL1() +Ptr cv::superres::createOptFlow_DualTVL1() { return makePtr(); } @@ -398,35 +395,35 @@ Ptr cv::superres::createOptFlow_DualTVL1() #ifndef HAVE_OPENCV_CUDAOPTFLOW -Ptr cv::superres::createOptFlow_Farneback_CUDA() +Ptr cv::superres::createOptFlow_Farneback_CUDA() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); - return Ptr(); + return Ptr(); } -Ptr cv::superres::createOptFlow_DualTVL1_CUDA() +Ptr cv::superres::createOptFlow_DualTVL1_CUDA() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); - return Ptr(); + return Ptr(); } -Ptr cv::superres::createOptFlow_Brox_CUDA() +Ptr cv::superres::createOptFlow_Brox_CUDA() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); - return Ptr(); + return Ptr(); } -Ptr cv::superres::createOptFlow_PyrLK_CUDA() +Ptr cv::superres::createOptFlow_PyrLK_CUDA() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); - return Ptr(); + return Ptr(); } #else // HAVE_OPENCV_CUDAOPTFLOW namespace { - class GpuOpticalFlow : public DenseOpticalFlowExt + class GpuOpticalFlow : public virtual cv::superres::DenseOpticalFlowExt { public: explicit GpuOpticalFlow(int work_type); @@ -494,15 +491,20 @@ namespace namespace { - class Brox_CUDA : public GpuOpticalFlow + class Brox_CUDA : public GpuOpticalFlow, public virtual cv::superres::BroxOpticalFlow { public: - AlgorithmInfo* info() const; - Brox_CUDA(); - + void calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2); void collectGarbage(); + CV_IMPL_PROPERTY(double, Alpha, alpha_) + CV_IMPL_PROPERTY(double, Gamma, gamma_) + CV_IMPL_PROPERTY(double, ScaleFactor, scaleFactor_) + CV_IMPL_PROPERTY(int, InnerIterations, innerIterations_) + CV_IMPL_PROPERTY(int, OuterIterations, outerIterations_) + CV_IMPL_PROPERTY(int, SolverIterations, solverIterations_) + protected: void impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2); @@ -517,14 +519,6 @@ namespace Ptr alg_; }; - CV_INIT_ALGORITHM(Brox_CUDA, "DenseOpticalFlowExt.Brox_CUDA", - obj.info()->addParam(obj, "alpha", obj.alpha_, false, 0, 0, "Flow smoothness"); - obj.info()->addParam(obj, "gamma", obj.gamma_, false, 0, 0, "Gradient constancy importance"); - obj.info()->addParam(obj, "scaleFactor", obj.scaleFactor_, false, 0, 0, "Pyramid scale factor"); - obj.info()->addParam(obj, "innerIterations", obj.innerIterations_, false, 0, 0, "Number of lagged non-linearity iterations (inner loop)"); - obj.info()->addParam(obj, "outerIterations", obj.outerIterations_, false, 0, 0, "Number of warping iterations (number of pyramid levels)"); - obj.info()->addParam(obj, "solverIterations", obj.solverIterations_, false, 0, 0, "Number of linear system solver iterations")) - Brox_CUDA::Brox_CUDA() : GpuOpticalFlow(CV_32FC1) { alg_ = cuda::BroxOpticalFlow::create(0.197f, 50.0f, 0.8f, 10, 77, 10); @@ -537,6 +531,11 @@ namespace solverIterations_ = alg_->getSolverIterations(); } + void Brox_CUDA::calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2) + { + GpuOpticalFlow::calc(frame0, frame1, flow1, flow2); + } + void Brox_CUDA::impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2) { alg_->setFlowSmoothness(alpha_); @@ -563,7 +562,7 @@ namespace } } -Ptr cv::superres::createOptFlow_Brox_CUDA() +Ptr cv::superres::createOptFlow_Brox_CUDA() { return makePtr(); } @@ -573,15 +572,17 @@ Ptr cv::superres::createOptFlow_Brox_CUDA() namespace { - class PyrLK_CUDA : public GpuOpticalFlow + class PyrLK_CUDA : public GpuOpticalFlow, public cv::superres::PyrLKOpticalFlow { public: - AlgorithmInfo* info() const; - PyrLK_CUDA(); - + void calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2); void collectGarbage(); + CV_IMPL_PROPERTY(int, WindowSize, winSize_) + CV_IMPL_PROPERTY(int, MaxLevel, maxLevel_) + CV_IMPL_PROPERTY(int, Iterations, iterations_) + protected: void impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2); @@ -593,11 +594,6 @@ namespace Ptr alg_; }; - CV_INIT_ALGORITHM(PyrLK_CUDA, "DenseOpticalFlowExt.PyrLK_CUDA", - obj.info()->addParam(obj, "winSize", obj.winSize_); - obj.info()->addParam(obj, "maxLevel", obj.maxLevel_); - obj.info()->addParam(obj, "iterations", obj.iterations_)) - PyrLK_CUDA::PyrLK_CUDA() : GpuOpticalFlow(CV_8UC1) { alg_ = cuda::DensePyrLKOpticalFlow::create(); @@ -607,6 +603,11 @@ namespace iterations_ = alg_->getNumIters(); } + void PyrLK_CUDA::calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2) + { + GpuOpticalFlow::calc(frame0, frame1, flow1, flow2); + } + void PyrLK_CUDA::impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2) { alg_->setWinSize(Size(winSize_, winSize_)); @@ -630,7 +631,7 @@ namespace } } -Ptr cv::superres::createOptFlow_PyrLK_CUDA() +Ptr cv::superres::createOptFlow_PyrLK_CUDA() { return makePtr(); } @@ -640,15 +641,21 @@ Ptr cv::superres::createOptFlow_PyrLK_CUDA() namespace { - class Farneback_CUDA : public GpuOpticalFlow + class Farneback_CUDA : public GpuOpticalFlow, public cv::superres::FarnebackOpticalFlow { public: - AlgorithmInfo* info() const; - Farneback_CUDA(); - + void calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2); void collectGarbage(); + CV_IMPL_PROPERTY(double, PyrScale, pyrScale_) + CV_IMPL_PROPERTY(int, LevelsNumber, numLevels_) + CV_IMPL_PROPERTY(int, WindowSize, winSize_) + CV_IMPL_PROPERTY(int, Iterations, numIters_) + CV_IMPL_PROPERTY(int, PolyN, polyN_) + CV_IMPL_PROPERTY(double, PolySigma, polySigma_) + CV_IMPL_PROPERTY(int, Flags, flags_) + protected: void impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2); @@ -664,15 +671,6 @@ namespace Ptr alg_; }; - CV_INIT_ALGORITHM(Farneback_CUDA, "DenseOpticalFlowExt.Farneback_CUDA", - obj.info()->addParam(obj, "pyrScale", obj.pyrScale_); - obj.info()->addParam(obj, "numLevels", obj.numLevels_); - obj.info()->addParam(obj, "winSize", obj.winSize_); - obj.info()->addParam(obj, "numIters", obj.numIters_); - obj.info()->addParam(obj, "polyN", obj.polyN_); - obj.info()->addParam(obj, "polySigma", obj.polySigma_); - obj.info()->addParam(obj, "flags", obj.flags_)) - Farneback_CUDA::Farneback_CUDA() : GpuOpticalFlow(CV_8UC1) { alg_ = cuda::FarnebackOpticalFlow::create(); @@ -686,6 +684,11 @@ namespace flags_ = alg_->getFlags(); } + void Farneback_CUDA::calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2) + { + GpuOpticalFlow::calc(frame0, frame1, flow1, flow2); + } + void Farneback_CUDA::impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2) { alg_->setPyrScale(pyrScale_); @@ -713,7 +716,7 @@ namespace } } -Ptr cv::superres::createOptFlow_Farneback_CUDA() +Ptr cv::superres::createOptFlow_Farneback_CUDA() { return makePtr(); } @@ -723,15 +726,22 @@ Ptr cv::superres::createOptFlow_Farneback_CUDA() namespace { - class DualTVL1_CUDA : public GpuOpticalFlow + class DualTVL1_CUDA : public GpuOpticalFlow, public cv::superres::DualTVL1OpticalFlow { public: - AlgorithmInfo* info() const; - DualTVL1_CUDA(); - + void calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2); void collectGarbage(); + CV_IMPL_PROPERTY(double, Tau, tau_) + CV_IMPL_PROPERTY(double, Lambda, lambda_) + CV_IMPL_PROPERTY(double, Theta, theta_) + CV_IMPL_PROPERTY(int, ScalesNumber, nscales_) + CV_IMPL_PROPERTY(int, WarpingsNumber, warps_) + CV_IMPL_PROPERTY(double, Epsilon, epsilon_) + CV_IMPL_PROPERTY(int, Iterations, iterations_) + CV_IMPL_PROPERTY(bool, UseInitialFlow, useInitialFlow_) + protected: void impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2); @@ -748,16 +758,6 @@ namespace Ptr alg_; }; - CV_INIT_ALGORITHM(DualTVL1_CUDA, "DenseOpticalFlowExt.DualTVL1_CUDA", - obj.info()->addParam(obj, "tau", obj.tau_); - obj.info()->addParam(obj, "lambda", obj.lambda_); - obj.info()->addParam(obj, "theta", obj.theta_); - obj.info()->addParam(obj, "nscales", obj.nscales_); - obj.info()->addParam(obj, "warps", obj.warps_); - obj.info()->addParam(obj, "epsilon", obj.epsilon_); - obj.info()->addParam(obj, "iterations", obj.iterations_); - obj.info()->addParam(obj, "useInitialFlow", obj.useInitialFlow_)) - DualTVL1_CUDA::DualTVL1_CUDA() : GpuOpticalFlow(CV_8UC1) { alg_ = cuda::OpticalFlowDual_TVL1::create(); @@ -772,6 +772,11 @@ namespace useInitialFlow_ = alg_->getUseInitialFlow(); } + void DualTVL1_CUDA::calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2) + { + GpuOpticalFlow::calc(frame0, frame1, flow1, flow2); + } + void DualTVL1_CUDA::impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2) { alg_->setTau(tau_); @@ -800,7 +805,7 @@ namespace } } -Ptr cv::superres::createOptFlow_DualTVL1_CUDA() +Ptr cv::superres::createOptFlow_DualTVL1_CUDA() { return makePtr(); } diff --git a/modules/superres/src/super_resolution.cpp b/modules/superres/src/super_resolution.cpp index 215416dd7..3eae5a6fd 100644 --- a/modules/superres/src/super_resolution.cpp +++ b/modules/superres/src/super_resolution.cpp @@ -45,11 +45,6 @@ using namespace cv; using namespace cv::superres; -bool cv::superres::initModule_superres() -{ - return !createSuperResolution_BTVL1().empty(); -} - cv::superres::SuperResolution::SuperResolution() { frameSource_ = createFrameSource_Empty(); diff --git a/modules/superres/test/test_superres.cpp b/modules/superres/test/test_superres.cpp index 980c8ed60..74a90bdc2 100644 --- a/modules/superres/test/test_superres.cpp +++ b/modules/superres/test/test_superres.cpp @@ -222,11 +222,11 @@ void SuperResolution::RunTest(cv::Ptr superRes) ASSERT_FALSE( superRes.empty() ); - const int btvKernelSize = superRes->getInt("btvKernelSize"); + const int btvKernelSize = superRes->getKernelSize(); - superRes->set("scale", scale); - superRes->set("iterations", iterations); - superRes->set("temporalAreaRadius", temporalAreaRadius); + superRes->setScale(scale); + superRes->setIterations(iterations); + superRes->setTemporalAreaRadius(temporalAreaRadius); cv::Ptr goldSource(new AllignedFrameSource(cv::superres::createFrameSource_Video(inputVideoName), scale)); cv::Ptr lowResSource(new DegradeFrameSource( diff --git a/modules/video/include/opencv2/video/tracking.hpp b/modules/video/include/opencv2/video/tracking.hpp index d54547ef7..40e9ffab8 100644 --- a/modules/video/include/opencv2/video/tracking.hpp +++ b/modules/video/include/opencv2/video/tracking.hpp @@ -380,6 +380,21 @@ public: }; +class CV_EXPORTS_W DenseOpticalFlow : public Algorithm +{ +public: + /** @brief Calculates an optical flow. + + @param I0 first 8-bit single-channel input image. + @param I1 second input image of the same size and the same type as prev. + @param flow computed flow image that has the same size as prev and type CV_32FC2. + */ + CV_WRAP virtual void calc( InputArray I0, InputArray I1, InputOutputArray flow ) = 0; + /** @brief Releases all inner buffers. + */ + CV_WRAP virtual void collectGarbage() = 0; +}; + /** @brief "Dual TV L1" Optical Flow Algorithm. The class implements the "Dual TV L1" optical flow algorithm described in @cite Zach2007 and @@ -422,24 +437,38 @@ constructing the class instance: C. Zach, T. Pock and H. Bischof, "A Duality Based Approach for Realtime TV-L1 Optical Flow". Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation". */ -class CV_EXPORTS_W DenseOpticalFlow : public Algorithm +class CV_EXPORTS_W DualTVL1OpticalFlow : public DenseOpticalFlow { public: - /** @brief Calculates an optical flow. - - @param I0 first 8-bit single-channel input image. - @param I1 second input image of the same size and the same type as prev. - @param flow computed flow image that has the same size as prev and type CV_32FC2. - */ - CV_WRAP virtual void calc( InputArray I0, InputArray I1, InputOutputArray flow ) = 0; - /** @brief Releases all inner buffers. - */ - CV_WRAP virtual void collectGarbage() = 0; + //! @name Time step of the numerical scheme + CV_PURE_PROPERTY(double, Tau) + //! @name Weight parameter for the data term, attachment parameter + CV_PURE_PROPERTY(double, Lambda) + //! @name Weight parameter for (u - v)^2, tightness parameter + CV_PURE_PROPERTY(double, Theta) + //! @name coefficient for additional illumination variation term + CV_PURE_PROPERTY(double, Gamma) + //! @name Number of scales used to create the pyramid of images + CV_PURE_PROPERTY(int, ScalesNumber) + //! @name Number of warpings per scale + CV_PURE_PROPERTY(int, WarpingsNumber) + //! @name Stopping criterion threshold used in the numerical scheme, which is a trade-off between precision and running time + CV_PURE_PROPERTY(double, Epsilon) + //! @name Inner iterations (between outlier filtering) used in the numerical scheme + CV_PURE_PROPERTY(int, InnerIterations) + //! @name Outer iterations (number of inner loops) used in the numerical scheme + CV_PURE_PROPERTY(int, OuterIterations) + //! @name Use initial flow + CV_PURE_PROPERTY(bool, UseInitialFlow) + //! @name Step between scales (<1) + CV_PURE_PROPERTY(double, ScaleStep) + //! @name Median filter kernel size (1 = no filter) (3 or 5) + CV_PURE_PROPERTY(int, MedianFiltering) }; /** @brief Creates instance of cv::DenseOpticalFlow */ -CV_EXPORTS_W Ptr createOptFlow_DualTVL1(); +CV_EXPORTS_W Ptr createOptFlow_DualTVL1(); //! @} video_track diff --git a/modules/video/perf/opencl/perf_optflow_dualTVL1.cpp b/modules/video/perf/opencl/perf_optflow_dualTVL1.cpp index 90e656d81..4f862f04b 100644 --- a/modules/video/perf/opencl/perf_optflow_dualTVL1.cpp +++ b/modules/video/perf/opencl/perf_optflow_dualTVL1.cpp @@ -87,11 +87,11 @@ OCL_PERF_TEST_P(OpticalFlowDualTVL1Fixture, OpticalFlowDualTVL1, declare.in(uFrame0, uFrame1, WARMUP_READ).out(uFlow, WARMUP_READ); //create algorithm - cv::Ptr alg = cv::createOptFlow_DualTVL1(); + cv::Ptr alg = cv::createOptFlow_DualTVL1(); //set parameters - alg->set("scaleStep", scaleStep); - alg->setInt("medianFiltering", medianFiltering); + alg->setScaleStep(scaleStep); + alg->setMedianFiltering(medianFiltering); if (useInitFlow) { @@ -100,7 +100,7 @@ OCL_PERF_TEST_P(OpticalFlowDualTVL1Fixture, OpticalFlowDualTVL1, } //set flag to use initial flow - alg->setBool("useInitialFlow", useInitFlow); + alg->setUseInitialFlow(useInitFlow); OCL_TEST_CYCLE() alg->calc(uFrame0, uFrame1, uFlow); @@ -109,4 +109,4 @@ OCL_PERF_TEST_P(OpticalFlowDualTVL1Fixture, OpticalFlowDualTVL1, } } // namespace cvtest::ocl -#endif // HAVE_OPENCL \ No newline at end of file +#endif // HAVE_OPENCL diff --git a/modules/video/src/bgfg_KNN.cpp b/modules/video/src/bgfg_KNN.cpp index 63ef300e0..c551ce4c9 100755 --- a/modules/video/src/bgfg_KNN.cpp +++ b/modules/video/src/bgfg_KNN.cpp @@ -160,8 +160,6 @@ public: nNextLongUpdate = Scalar::all(0); } - virtual AlgorithmInfo* info() const { return 0; } - virtual int getHistory() const { return history; } virtual void setHistory(int _nframes) { history = _nframes; } diff --git a/modules/video/src/bgfg_gaussmix2.cpp b/modules/video/src/bgfg_gaussmix2.cpp index e2d875517..226af9dc0 100644 --- a/modules/video/src/bgfg_gaussmix2.cpp +++ b/modules/video/src/bgfg_gaussmix2.cpp @@ -230,8 +230,6 @@ public: } } - virtual AlgorithmInfo* info() const { return 0; } - virtual int getHistory() const { return history; } virtual void setHistory(int _nframes) { history = _nframes; } diff --git a/modules/video/src/tvl1flow.cpp b/modules/video/src/tvl1flow.cpp index 8a865a1d2..90fe48f47 100644 --- a/modules/video/src/tvl1flow.cpp +++ b/modules/video/src/tvl1flow.cpp @@ -86,7 +86,7 @@ using namespace cv; namespace { -class OpticalFlowDual_TVL1 : public DenseOpticalFlow +class OpticalFlowDual_TVL1 : public DualTVL1OpticalFlow { public: OpticalFlowDual_TVL1(); @@ -94,7 +94,18 @@ public: void calc(InputArray I0, InputArray I1, InputOutputArray flow); void collectGarbage(); - AlgorithmInfo* info() const; + CV_IMPL_PROPERTY(double, Tau, tau) + CV_IMPL_PROPERTY(double, Lambda, lambda) + CV_IMPL_PROPERTY(double, Theta, theta) + CV_IMPL_PROPERTY(double, Gamma, gamma) + CV_IMPL_PROPERTY(int, ScalesNumber, nscales) + CV_IMPL_PROPERTY(int, WarpingsNumber, warps) + CV_IMPL_PROPERTY(double, Epsilon, epsilon) + CV_IMPL_PROPERTY(int, InnerIterations, innerIterations) + CV_IMPL_PROPERTY(int, OuterIterations, outerIterations) + CV_IMPL_PROPERTY(bool, UseInitialFlow, useInitialFlow) + CV_IMPL_PROPERTY(double, ScaleStep, scaleStep) + CV_IMPL_PROPERTY(int, MedianFiltering, medianFiltering) protected: double tau; @@ -1416,35 +1427,9 @@ void OpticalFlowDual_TVL1::collectGarbage() dum.norm_buf.release(); } - -CV_INIT_ALGORITHM(OpticalFlowDual_TVL1, "DenseOpticalFlow.DualTVL1", - obj.info()->addParam(obj, "tau", obj.tau, false, 0, 0, - "Time step of the numerical scheme"); - obj.info()->addParam(obj, "lambda", obj.lambda, false, 0, 0, - "Weight parameter for the data term, attachment parameter"); - obj.info()->addParam(obj, "theta", obj.theta, false, 0, 0, - "Weight parameter for (u - v)^2, tightness parameter"); - obj.info()->addParam(obj, "nscales", obj.nscales, false, 0, 0, - "Number of scales used to create the pyramid of images"); - obj.info()->addParam(obj, "warps", obj.warps, false, 0, 0, - "Number of warpings per scale"); - obj.info()->addParam(obj, "medianFiltering", obj.medianFiltering, false, 0, 0, - "Median filter kernel size (1 = no filter) (3 or 5)"); - obj.info()->addParam(obj, "scaleStep", obj.scaleStep, false, 0, 0, - "Step between scales (<1)"); - obj.info()->addParam(obj, "epsilon", obj.epsilon, false, 0, 0, - "Stopping criterion threshold used in the numerical scheme, which is a trade-off between precision and running time"); - obj.info()->addParam(obj, "innerIterations", obj.innerIterations, false, 0, 0, - "inner iterations (between outlier filtering) used in the numerical scheme"); - obj.info()->addParam(obj, "outerIterations", obj.outerIterations, false, 0, 0, - "outer iterations (number of inner loops) used in the numerical scheme"); - obj.info()->addParam(obj, "gamma", obj.gamma, false, 0, 0, - "coefficient for additional illumination variation term"); - obj.info()->addParam(obj, "useInitialFlow", obj.useInitialFlow)) - } // namespace -Ptr cv::createOptFlow_DualTVL1() +Ptr cv::createOptFlow_DualTVL1() { return makePtr(); } diff --git a/modules/video/test/ocl/test_optflow_tvl1flow.cpp b/modules/video/test/ocl/test_optflow_tvl1flow.cpp index bd32252b2..67b4a1fd6 100644 --- a/modules/video/test/ocl/test_optflow_tvl1flow.cpp +++ b/modules/video/test/ocl/test_optflow_tvl1flow.cpp @@ -82,11 +82,11 @@ OCL_TEST_P(OpticalFlowTVL1, Mat) cv::Mat flow; cv::UMat uflow; //create algorithm - cv::Ptr alg = cv::createOptFlow_DualTVL1(); + cv::Ptr alg = cv::createOptFlow_DualTVL1(); //set parameters - alg->set("scaleStep", scaleStep); - alg->setInt("medianFiltering", medianFiltering); + alg->setScaleStep(scaleStep); + alg->setMedianFiltering(medianFiltering); //create initial flow as result of algorithm calculation if (useInitFlow) @@ -96,7 +96,7 @@ OCL_TEST_P(OpticalFlowTVL1, Mat) } //set flag to use initial flow as it is ready to use - alg->setBool("useInitialFlow", useInitFlow); + alg->setUseInitialFlow(useInitFlow); OCL_OFF(alg->calc(frame0, frame1, flow)); OCL_ON(alg->calc(frame0, frame1, uflow)); @@ -114,4 +114,4 @@ OCL_INSTANTIATE_TEST_CASE_P(Video, OpticalFlowTVL1, } } // namespace cvtest::ocl -#endif // HAVE_OPENCL \ No newline at end of file +#endif // HAVE_OPENCL diff --git a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp index 6ffc77cdc..ba845dc6d 100755 --- a/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp +++ b/samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp @@ -138,7 +138,7 @@ int main(int argc, char **argv) Stats stats, akaze_stats, orb_stats; Ptr akaze = AKAZE::create(); - akaze->set("threshold", akaze_thresh); + akaze->setThreshold(akaze_thresh); Ptr orb = ORB::create(); orb->setMaxFeatures(stats.keypoints); Ptr matcher = DescriptorMatcher::create("BruteForce-Hamming"); @@ -163,7 +163,7 @@ int main(int argc, char **argv) akaze_draw_stats = stats; } - orb_tracker.getDetector()->set("nFeatures", stats.keypoints); + orb->setMaxFeatures(stats.keypoints); orb_res = orb_tracker.process(frame, stats); orb_stats += stats; if(update_stats) { diff --git a/samples/gpu/super_resolution.cpp b/samples/gpu/super_resolution.cpp index 95147a6d0..f106f76d3 100644 --- a/samples/gpu/super_resolution.cpp +++ b/samples/gpu/super_resolution.cpp @@ -26,32 +26,32 @@ using namespace cv::superres; cout << tm.getTimeSec() << " sec" << endl; \ } -static Ptr createOptFlow(const string& name, bool useGpu) +static Ptr createOptFlow(const string& name, bool useGpu) { if (name == "farneback") { if (useGpu) - return createOptFlow_Farneback_CUDA(); + return cv::superres::createOptFlow_Farneback_CUDA(); else - return createOptFlow_Farneback(); + return cv::superres::createOptFlow_Farneback(); } /*else if (name == "simple") return createOptFlow_Simple();*/ else if (name == "tvl1") { if (useGpu) - return createOptFlow_DualTVL1_CUDA(); + return cv::superres::createOptFlow_DualTVL1_CUDA(); else - return createOptFlow_DualTVL1(); + return cv::superres::createOptFlow_DualTVL1(); } else if (name == "brox") - return createOptFlow_Brox_CUDA(); + return cv::superres::createOptFlow_Brox_CUDA(); else if (name == "pyrlk") - return createOptFlow_PyrLK_CUDA(); + return cv::superres::createOptFlow_PyrLK_CUDA(); else cerr << "Incorrect Optical Flow algorithm - " << name << endl; - return Ptr(); + return Ptr(); } int main(int argc, const char* argv[]) @@ -92,15 +92,15 @@ int main(int argc, const char* argv[]) else superRes = createSuperResolution_BTVL1(); - Ptr of = createOptFlow(optFlow, useCuda); + Ptr of = createOptFlow(optFlow, useCuda); if (of.empty()) return EXIT_FAILURE; - superRes->set("opticalFlow", of); + superRes->setOpticalFlow(of); - superRes->set("scale", scale); - superRes->set("iterations", iterations); - superRes->set("temporalAreaRadius", temporalAreaRadius); + superRes->setScale(scale); + superRes->setIterations(iterations); + superRes->setTemporalAreaRadius(temporalAreaRadius); Ptr frameSource; if (useCuda) diff --git a/samples/gpu/surf_keypoint_matcher.cpp b/samples/gpu/surf_keypoint_matcher.cpp index 0a8554d71..522c8a1e1 100644 --- a/samples/gpu/surf_keypoint_matcher.cpp +++ b/samples/gpu/surf_keypoint_matcher.cpp @@ -62,19 +62,17 @@ int main(int argc, char* argv[]) cout << "FOUND " << keypoints2GPU.cols << " keypoints on second image" << endl; // matching descriptors - BFMatcher_CUDA matcher(surf.defaultNorm()); - GpuMat trainIdx, distance; - matcher.matchSingle(descriptors1GPU, descriptors2GPU, trainIdx, distance); + Ptr matcher = cv::cuda::DescriptorMatcher::createBFMatcher(surf.defaultNorm()); + vector matches; + matcher->match(descriptors1GPU, descriptors2GPU, matches); // downloading results vector keypoints1, keypoints2; vector descriptors1, descriptors2; - vector matches; surf.downloadKeypoints(keypoints1GPU, keypoints1); surf.downloadKeypoints(keypoints2GPU, keypoints2); surf.downloadDescriptors(descriptors1GPU, descriptors1); surf.downloadDescriptors(descriptors2GPU, descriptors2); - BFMatcher_CUDA::matchDownload(trainIdx, distance, matches); // drawing the results Mat img_matches;