Remove deprecated methods from cv::Algorithm

This commit is contained in:
Maksim Shabunin 2015-02-05 17:40:15 +03:00
parent fdf31ec14f
commit da383e65e2
37 changed files with 411 additions and 2037 deletions

View File

@ -122,7 +122,6 @@ CV_INLINE CvParamLattice cvDefaultParamLattice( void )
#define CV_TYPE_NAME_ML_SVM "opencv-ml-svm" #define CV_TYPE_NAME_ML_SVM "opencv-ml-svm"
#define CV_TYPE_NAME_ML_KNN "opencv-ml-knn" #define CV_TYPE_NAME_ML_KNN "opencv-ml-knn"
#define CV_TYPE_NAME_ML_NBAYES "opencv-ml-bayesian" #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_BOOSTING "opencv-ml-boost-tree"
#define CV_TYPE_NAME_ML_TREE "opencv-ml-tree" #define CV_TYPE_NAME_ML_TREE "opencv-ml-tree"
#define CV_TYPE_NAME_ML_ANN_MLP "opencv-ml-ann-mlp" #define CV_TYPE_NAME_ML_ANN_MLP "opencv-ml-ann-mlp"
@ -562,100 +561,6 @@ private:
CvSVM& operator = (const CvSVM&); 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<Mat>* 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<Mat> covs;
std::vector<Mat> covsEigenValues;
std::vector<Mat> covsRotateMats;
std::vector<Mat> invCovsEigenValues;
Mat logWeightDivDet;
};
} // namespace cv
/****************************************************************************************\ /****************************************************************************************\
* Decision Tree * * Decision Tree *
\****************************************************************************************/\ \****************************************************************************************/\
@ -2155,8 +2060,6 @@ typedef CvGBTreesParams GradientBoostingTreeParams;
typedef CvGBTrees GradientBoostingTrees; typedef CvGBTrees GradientBoostingTrees;
template<> void DefaultDeleter<CvDTreeSplit>::operator ()(CvDTreeSplit* obj) const; template<> void DefaultDeleter<CvDTreeSplit>::operator ()(CvDTreeSplit* obj) const;
bool initModule_ml(void);
} }
#endif // __cplusplus #endif // __cplusplus

View File

@ -100,7 +100,7 @@ RECURSIVE = YES
EXCLUDE = EXCLUDE =
EXCLUDE_SYMLINKS = NO EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS = *.inl.hpp *.impl.hpp *_detail.hpp */cudev/**/detail/*.hpp 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_PATH = @CMAKE_DOXYGEN_EXAMPLE_PATH@
EXAMPLE_PATTERNS = * EXAMPLE_PATTERNS = *
EXAMPLE_RECURSIVE = YES EXAMPLE_RECURSIVE = YES
@ -243,7 +243,8 @@ PREDEFINED = __cplusplus=1 \
CV_NORETURN= \ CV_NORETURN= \
CV_DEFAULT(x)=" = x" \ CV_DEFAULT(x)=" = x" \
CV_NEON=1 \ 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 = EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES SKIP_FUNCTION_MACROS = YES
TAGFILES = TAGFILES =

View File

@ -200,8 +200,6 @@ public:
void setCallback(const Ptr<LMSolver::Callback>& _cb) { cb = _cb; } void setCallback(const Ptr<LMSolver::Callback>& _cb) { cb = _cb; }
AlgorithmInfo* info() const;
Ptr<LMSolver::Callback> cb; Ptr<LMSolver::Callback> cb;
double epsx; 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<LMSolver> createLMSolver(const Ptr<LMSolver::Callback>& cb, int maxIters) Ptr<LMSolver> createLMSolver(const Ptr<LMSolver::Callback>& cb, int maxIters)
{ {
CV_Assert( !LMSolverImpl_info_auto.name().empty() );
return makePtr<LMSolverImpl>(cb, maxIters); return makePtr<LMSolverImpl>(cb, maxIters);
} }

View File

@ -256,8 +256,6 @@ public:
void setCallback(const Ptr<PointSetRegistrator::Callback>& _cb) { cb = _cb; } void setCallback(const Ptr<PointSetRegistrator::Callback>& _cb) { cb = _cb; }
AlgorithmInfo* info() const;
Ptr<PointSetRegistrator::Callback> cb; Ptr<PointSetRegistrator::Callback> cb;
int modelPoints; int modelPoints;
bool checkPartialSubsets; bool checkPartialSubsets;
@ -378,25 +376,12 @@ public:
return result; 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<PointSetRegistrator> createRANSACPointSetRegistrator(const Ptr<PointSetRegistrator::Callback>& _cb, Ptr<PointSetRegistrator> createRANSACPointSetRegistrator(const Ptr<PointSetRegistrator::Callback>& _cb,
int _modelPoints, double _threshold, int _modelPoints, double _threshold,
double _confidence, int _maxIters) double _confidence, int _maxIters)
{ {
CV_Assert( !RANSACPointSetRegistrator_info_auto.name().empty() );
return Ptr<PointSetRegistrator>( return Ptr<PointSetRegistrator>(
new RANSACPointSetRegistrator(_cb, _modelPoints, _threshold, _confidence, _maxIters)); new RANSACPointSetRegistrator(_cb, _modelPoints, _threshold, _confidence, _maxIters));
} }
@ -405,7 +390,6 @@ Ptr<PointSetRegistrator> createRANSACPointSetRegistrator(const Ptr<PointSetRegis
Ptr<PointSetRegistrator> createLMeDSPointSetRegistrator(const Ptr<PointSetRegistrator::Callback>& _cb, Ptr<PointSetRegistrator> createLMeDSPointSetRegistrator(const Ptr<PointSetRegistrator::Callback>& _cb,
int _modelPoints, double _confidence, int _maxIters) int _modelPoints, double _confidence, int _maxIters)
{ {
CV_Assert( !LMeDSPointSetRegistrator_info_auto.name().empty() );
return Ptr<PointSetRegistrator>( return Ptr<PointSetRegistrator>(
new LMeDSPointSetRegistrator(_cb, _modelPoints, _confidence, _maxIters)); new LMeDSPointSetRegistrator(_cb, _modelPoints, _confidence, _maxIters));
} }

View File

@ -1010,8 +1010,6 @@ public:
disp.convertTo(disp0, disp0.type(), 1./(1 << DISPARITY_SHIFT), 0); disp.convertTo(disp0, disp0.type(), 1./(1 << DISPARITY_SHIFT), 0);
} }
AlgorithmInfo* info() const { return 0; }
int getMinDisparity() const { return params.minDisparity; } int getMinDisparity() const { return params.minDisparity; }
void setMinDisparity(int minDisparity) { params.minDisparity = minDisparity; } void setMinDisparity(int minDisparity) { params.minDisparity = minDisparity; }

View File

@ -865,8 +865,6 @@ public:
StereoMatcher::DISP_SCALE*params.speckleRange, buffer); StereoMatcher::DISP_SCALE*params.speckleRange, buffer);
} }
AlgorithmInfo* info() const { return 0; }
int getMinDisparity() const { return params.minDisparity; } int getMinDisparity() const { return params.minDisparity; }
void setMinDisparity(int minDisparity) { params.minDisparity = minDisparity; } void setMinDisparity(int minDisparity) { params.minDisparity = minDisparity; }

View File

@ -2745,8 +2745,6 @@ public:
//////////////////////////////////////// Algorithm //////////////////////////////////// //////////////////////////////////////// Algorithm ////////////////////////////////////
class CV_EXPORTS Algorithm; class CV_EXPORTS Algorithm;
class CV_EXPORTS AlgorithmInfo;
struct CV_EXPORTS AlgorithmInfoData;
template<typename _Tp> struct ParamType {}; template<typename _Tp> 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 models, codebook-based algorithm etc.), optical flow (block matching, Lucas-Kanade, Horn-Schunck
etc.). 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: Here is example of SIFT use in your application via Algorithm interface:
@code @code
#include "opencv2/opencv.hpp" #include "opencv2/opencv.hpp"
#include "opencv2/xfeatures2d.hpp" #include "opencv2/xfeatures2d.hpp"
using namespace cv::xfeatures2d; using namespace cv::xfeatures2d;
...
Ptr<Feature2D> sift = SIFT::create(); Ptr<Feature2D> sift = SIFT::create();
FileStorage fs("sift_params.xml", FileStorage::READ); FileStorage fs("sift_params.xml", FileStorage::READ);
if( fs.isOpened() ) // if we have file with parameters, read them 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 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 sift->setContrastThreshold(0.01f); // lower the contrast threshold, compared to the default value
{ {
WriteStructContext ws(fs, "sift_params", CV_NODE_MAP); WriteStructContext ws(fs, "sift_params", CV_NODE_MAP);
sift->write(fs); sift->write(fs);
} }
} }
Mat image = imread("myimage.png", 0), descriptors; Mat image = imread("myimage.png", 0), descriptors;
vector<KeyPoint> keypoints; vector<KeyPoint> keypoints;
sift->detectAndCompute(image, noArray(), keypoints, descriptors); sift->detectAndCompute(image, noArray(), keypoints, descriptors);
@endcode @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 <https://github.com/Itseez/opencv/tree/master/modules/ml/src/ml_init.cpp> as
the reference and modify it according to the list of your parameters.
- Add some public function (e.g. `initModule_<mymodule>()`) 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 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\<int\>("param_name")
- myalgo.get\<double\>("param_name")
- myalgo.get\<bool\>("param_name")
- myalgo.get\<String\>("param_name")
- myalgo.get\<Mat\>("param_name")
- myalgo.get\<vector\<Mat\> \>("param_name")
- myalgo.get\<Algorithm\>("param_name") (it returns Ptr\<Algorithm\>).
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\<Mat\> 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 _Tp> typename ParamType<_Tp>::member_type get(const String& name) const;
/** @overload */
template<typename _Tp> 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<Mat> getMatVector(const String& name) const;
CV_WRAP Ptr<Algorithm> 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<Mat>& value);
void set(const String& name, const Ptr<Algorithm>& value);
template<typename _Tp> 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<Mat>& value);
CV_WRAP void setAlgorithm(const String& name, const Ptr<Algorithm>& value);
template<typename _Tp> 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<Mat>& value);
void set(const char* name, const Ptr<Algorithm>& value);
template<typename _Tp> 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<Mat>& value);
void setAlgorithm(const char* name, const Ptr<Algorithm>& value);
template<typename _Tp> 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<String>& 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<String> 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<String>& algorithms);
CV_WRAP static Ptr<Algorithm> _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<BackgroundSubtractor> bgfg = Algorithm::create<BackgroundSubtractor>("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_\<modulename\>(); 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<typename _Tp> static Ptr<_Tp> create(const String& name);
virtual AlgorithmInfo* info() const /* TODO: make it = 0;*/ { return 0; }
};
/** @todo document */
class CV_EXPORTS AlgorithmInfo
{ {
public: public:
friend class Algorithm; Algorithm();
AlgorithmInfo(const String& name, Algorithm::Constructor create); virtual ~Algorithm();
~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<String>& names) const;
void write(const Algorithm* algo, FileStorage& fs) const; /** @brief Stores algorithm parameters in a file storage
void read(Algorithm* algo, const FileNode& fn) const; */
String name() const; virtual void write(FileStorage& fs) const { (void)fs; }
void addParam(Algorithm& algo, const char* name, /** @brief Reads algorithm parameters from a file storage
int& value, bool readOnly=false, */
int (Algorithm::*getter)()=0, virtual void read(const FileNode& fn) { (void)fn; }
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<Mat>& value, bool readOnly=false,
std::vector<Mat> (Algorithm::*getter)()=0,
void (Algorithm::*setter)(const std::vector<Mat>&)=0,
const String& help=String());
void addParam(Algorithm& algo, const char* name,
Ptr<Algorithm>& value, bool readOnly=false,
Ptr<Algorithm> (Algorithm::*getter)()=0,
void (Algorithm::*setter)(const Ptr<Algorithm>&)=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<typename _Tp, typename _Base> 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<typename _Tp> 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;
}; };
/** @todo document */ // define properties
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 };
Param(); #define CV_PURE_PROPERTY(type, name) \
Param(int _type, bool _readonly, int _offset, CV_WRAP virtual type get##name() const = 0; \
Algorithm::Getter _getter=0, CV_WRAP virtual void set##name(type _##name) = 0;
Algorithm::Setter _setter=0,
const String& _help=String()); #define CV_PURE_PROPERTY_S(type, name) \
int type; CV_WRAP virtual type get##name() const = 0; \
int offset; CV_WRAP virtual void set##name(const type & _##name) = 0;
bool readonly;
Algorithm::Getter getter; #define CV_PURE_PROPERTY_RO(type, name) \
Algorithm::Setter setter; CV_WRAP virtual type get##name() const = 0;
String help;
// 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<bool> template<> struct ParamType<bool>
{ {
typedef bool const_param_type; typedef bool const_param_type;

View File

@ -412,84 +412,6 @@ int print(const Matx<_Tp, m, n>& matx, FILE* stream = stdout)
return print(Formatter::get()->format(cv::Mat(matx)), stream); return print(Formatter::get()->format(cv::Mat(matx)), stream);
} }
////////////////////////////////////////// Algorithm //////////////////////////////////////////
template<typename _Tp> inline
Ptr<_Tp> Algorithm::create(const String& name)
{
return _create(name).dynamicCast<_Tp>();
}
template<typename _Tp> inline
void Algorithm::set(const char* _name, const Ptr<_Tp>& value)
{
Ptr<Algorithm> algo_ptr = value. template dynamicCast<cv::Algorithm>();
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<Algorithm>::type, &algo_ptr);
}
template<typename _Tp> inline
void Algorithm::set(const String& _name, const Ptr<_Tp>& value)
{
this->set<_Tp>(_name.c_str(), value);
}
template<typename _Tp> inline
void Algorithm::setAlgorithm(const char* _name, const Ptr<_Tp>& value)
{
Ptr<Algorithm> algo_ptr = value. template ptr<cv::Algorithm>();
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<Algorithm>::type, &algo_ptr);
}
template<typename _Tp> inline
void Algorithm::setAlgorithm(const String& _name, const Ptr<_Tp>& value)
{
this->set<_Tp>(_name.c_str(), value);
}
template<typename _Tp> 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<typename _Tp> 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<typename _Tp, typename _Base> 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<typename _Tp> 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<Algorithm>::type, &value, readOnly,
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
}
//! @endcond //! @endcond
/****************************************************************************************\ /****************************************************************************************\

View File

@ -129,40 +129,6 @@ namespace cv
CV_EXPORTS const char* currentParallelFramework(); CV_EXPORTS const char* currentParallelFramework();
} //namespace cv } //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<classname>(); \
} \
\
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 * * Common declarations *
\****************************************************************************************/ \****************************************************************************************/

File diff suppressed because it is too large Load Diff

View File

@ -140,8 +140,6 @@ namespace
public: public:
CLAHE_Impl(double clipLimit = 40.0, int tilesX = 8, int tilesY = 8); 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(cv::InputArray src, cv::OutputArray dst);
void apply(InputArray src, OutputArray dst, Stream& stream); 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) void CLAHE_Impl::apply(cv::InputArray _src, cv::OutputArray _dst)
{ {
apply(_src, _dst, Stream::Null()); apply(_src, _dst, Stream::Null());

View File

@ -310,10 +310,10 @@ PERF_TEST_P(ImagePair, OpticalFlowDual_TVL1,
{ {
cv::Mat flow; cv::Mat flow;
cv::Ptr<cv::DenseOpticalFlow> alg = cv::createOptFlow_DualTVL1(); cv::Ptr<cv::DualTVL1OpticalFlow> alg = cv::createOptFlow_DualTVL1();
alg->set("medianFiltering", 1); alg->setMedianFiltering(1);
alg->set("innerIterations", 1); alg->setInnerIterations(1);
alg->set("outerIterations", 300); alg->setOuterIterations(300);
TEST_CYCLE() alg->calc(frame0, frame1, flow); TEST_CYCLE() alg->calc(frame0, frame1, flow);
CPU_SANITY_CHECK(flow); CPU_SANITY_CHECK(flow);

View File

@ -369,11 +369,11 @@ CUDA_TEST_P(OpticalFlowDual_TVL1, Accuracy)
cv::cuda::GpuMat d_flow; cv::cuda::GpuMat d_flow;
d_alg->calc(loadMat(frame0), loadMat(frame1), d_flow); d_alg->calc(loadMat(frame0), loadMat(frame1), d_flow);
cv::Ptr<cv::DenseOpticalFlow> alg = cv::createOptFlow_DualTVL1(); cv::Ptr<cv::DualTVL1OpticalFlow> alg = cv::createOptFlow_DualTVL1();
alg->set("medianFiltering", 1); alg->setMedianFiltering(1);
alg->set("innerIterations", 1); alg->setInnerIterations(1);
alg->set("outerIterations", d_alg->getNumIterations()); alg->setOuterIterations(d_alg->getNumIterations());
alg->set("gamma", gamma); alg->setGamma(gamma);
cv::Mat flow; cv::Mat flow;
alg->calc(frame0, frame1, flow); alg->calc(frame0, frame1, flow);

View File

@ -320,8 +320,6 @@ namespace
public: public:
CLAHE_Impl(double clipLimit = 40.0, int tilesX = 8, int tilesY = 8); 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(cv::InputArray src, cv::OutputArray dst);
void setClipLimit(double clipLimit); 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) void CLAHE_Impl::apply(cv::InputArray _src, cv::OutputArray _dst)
{ {
CV_Assert( _src.type() == CV_8UC1 || _src.type() == CV_16UC1 ); CV_Assert( _src.type() == CV_8UC1 || _src.type() == CV_16UC1 );

View File

@ -52,11 +52,6 @@
@defgroup shape Shape Distance and Matching @defgroup shape Shape Distance and Matching
*/ */
namespace cv
{
CV_EXPORTS bool initModule_shape();
}
#endif #endif
/* End of file. */ /* End of file. */

View File

@ -66,8 +66,6 @@ public:
{ {
} }
virtual AlgorithmInfo* info() const { return 0; }
//! the main operator //! the main operator
virtual void estimateTransformation(InputArray transformingShape, InputArray targetShape, std::vector<DMatch> &matches); virtual void estimateTransformation(InputArray transformingShape, InputArray targetShape, std::vector<DMatch> &matches);
virtual float applyTransformation(InputArray input, OutputArray output=noArray()); virtual float applyTransformation(InputArray input, OutputArray output=noArray());

View File

@ -60,8 +60,6 @@ public:
{ {
} }
virtual AlgorithmInfo* info() const { return 0; }
//! the main operator //! the main operator
virtual float computeDistance(InputArray contour1, InputArray contour2); virtual float computeDistance(InputArray contour1, InputArray contour2);

View File

@ -62,8 +62,6 @@ public:
{ {
} }
virtual AlgorithmInfo* info() const { return 0; }
//! the main operator //! the main operator
virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix); virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix);
@ -189,8 +187,6 @@ public:
{ {
} }
virtual AlgorithmInfo* info() const { return 0; }
//! the main operator //! the main operator
virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix); virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix);
@ -327,8 +323,6 @@ public:
{ {
} }
virtual AlgorithmInfo* info() const { return 0; }
//! the main operator //! the main operator
virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix); virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix);
@ -445,8 +439,6 @@ public:
{ {
} }
virtual AlgorithmInfo* info() const { return 0; }
//! the main operator //! the main operator
virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix); virtual void buildCostMatrix(InputArray descriptors1, InputArray descriptors2, OutputArray costMatrix);

View File

@ -79,8 +79,6 @@ public:
{ {
} }
virtual AlgorithmInfo* info() const { return 0; }
//! the main operator //! the main operator
virtual float computeDistance(InputArray contour1, InputArray contour2); virtual float computeDistance(InputArray contour1, InputArray contour2);

View File

@ -68,8 +68,6 @@ public:
{ {
} }
virtual AlgorithmInfo* info() const { return 0; }
//! the main operators //! the main operators
virtual void estimateTransformation(InputArray transformingShape, InputArray targetShape, std::vector<DMatch> &matches); virtual void estimateTransformation(InputArray transformingShape, InputArray targetShape, std::vector<DMatch> &matches);
virtual float applyTransformation(InputArray inPts, OutputArray output=noArray()); virtual float applyTransformation(InputArray inPts, OutputArray output=noArray());

View File

@ -44,6 +44,7 @@
#define __OPENCV_SUPERRES_HPP__ #define __OPENCV_SUPERRES_HPP__
#include "opencv2/core.hpp" #include "opencv2/core.hpp"
#include "opencv2/superres/optical_flow.hpp"
/** /**
@defgroup superres Super Resolution @defgroup superres Super Resolution
@ -62,8 +63,6 @@ namespace cv
//! @addtogroup superres //! @addtogroup superres
//! @{ //! @{
CV_EXPORTS bool initModule_superres();
class CV_EXPORTS FrameSource class CV_EXPORTS FrameSource
{ {
public: public:
@ -105,6 +104,36 @@ namespace cv
*/ */
virtual void collectGarbage(); 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<cv::superres::DenseOpticalFlowExt>, OpticalFlow)
protected: protected:
SuperResolution(); SuperResolution();
@ -139,7 +168,6 @@ namespace cv
*/ */
CV_EXPORTS Ptr<SuperResolution> createSuperResolution_BTVL1(); CV_EXPORTS Ptr<SuperResolution> createSuperResolution_BTVL1();
CV_EXPORTS Ptr<SuperResolution> createSuperResolution_BTVL1_CUDA(); CV_EXPORTS Ptr<SuperResolution> createSuperResolution_BTVL1_CUDA();
CV_EXPORTS Ptr<SuperResolution> createSuperResolution_BTVL1_OCL();
//! @} superres //! @} superres

View File

@ -60,20 +60,68 @@ namespace cv
virtual void collectGarbage() = 0; virtual void collectGarbage() = 0;
}; };
CV_EXPORTS Ptr<DenseOpticalFlowExt> createOptFlow_Farneback();
CV_EXPORTS Ptr<DenseOpticalFlowExt> createOptFlow_Farneback_CUDA();
CV_EXPORTS Ptr<DenseOpticalFlowExt> createOptFlow_Farneback_OCL();
CV_EXPORTS Ptr<DenseOpticalFlowExt> 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<FarnebackOpticalFlow> createOptFlow_Farneback();
CV_EXPORTS Ptr<FarnebackOpticalFlow> createOptFlow_Farneback_CUDA();
CV_EXPORTS Ptr<DenseOpticalFlowExt> createOptFlow_DualTVL1();
CV_EXPORTS Ptr<DenseOpticalFlowExt> createOptFlow_DualTVL1_CUDA();
CV_EXPORTS Ptr<DenseOpticalFlowExt> createOptFlow_DualTVL1_OCL();
CV_EXPORTS Ptr<DenseOpticalFlowExt> createOptFlow_Brox_CUDA(); // CV_EXPORTS Ptr<DenseOpticalFlowExt> createOptFlow_Simple();
CV_EXPORTS Ptr<DenseOpticalFlowExt> createOptFlow_PyrLK_CUDA();
CV_EXPORTS Ptr<DenseOpticalFlowExt> 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<DualTVL1OpticalFlow> createOptFlow_DualTVL1();
CV_EXPORTS Ptr<DualTVL1OpticalFlow> 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<BroxOpticalFlow> 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<PyrLKOpticalFlow> createOptFlow_PyrLK_CUDA();
//! @} //! @}

View File

@ -138,10 +138,10 @@ PERF_TEST_P(Size_MatType, SuperResolution_BTVL1,
{ {
Ptr<SuperResolution> superRes = createSuperResolution_BTVL1_CUDA(); Ptr<SuperResolution> superRes = createSuperResolution_BTVL1_CUDA();
superRes->set("scale", scale); superRes->setScale(scale);
superRes->set("iterations", iterations); superRes->setIterations(iterations);
superRes->set("temporalAreaRadius", temporalAreaRadius); superRes->setTemporalAreaRadius(temporalAreaRadius);
superRes->set("opticalFlow", opticalFlow); superRes->setOpticalFlow(opticalFlow);
superRes->setInput(makePtr<OneFrameSource_CUDA>(GpuMat(frame))); superRes->setInput(makePtr<OneFrameSource_CUDA>(GpuMat(frame)));
@ -156,10 +156,10 @@ PERF_TEST_P(Size_MatType, SuperResolution_BTVL1,
{ {
Ptr<SuperResolution> superRes = createSuperResolution_BTVL1(); Ptr<SuperResolution> superRes = createSuperResolution_BTVL1();
superRes->set("scale", scale); superRes->setScale(scale);
superRes->set("iterations", iterations); superRes->setIterations(iterations);
superRes->set("temporalAreaRadius", temporalAreaRadius); superRes->setTemporalAreaRadius(temporalAreaRadius);
superRes->set("opticalFlow", opticalFlow); superRes->setOpticalFlow(opticalFlow);
superRes->setInput(makePtr<OneFrameSource_CPU>(frame)); superRes->setInput(makePtr<OneFrameSource_CPU>(frame));
@ -198,10 +198,10 @@ OCL_PERF_TEST_P(SuperResolution_BTVL1 ,BTVL1,
Ptr<DenseOpticalFlowExt> opticalFlow(new ZeroOpticalFlow); Ptr<DenseOpticalFlowExt> opticalFlow(new ZeroOpticalFlow);
Ptr<SuperResolution> superRes = createSuperResolution_BTVL1(); Ptr<SuperResolution> superRes = createSuperResolution_BTVL1();
superRes->set("scale", scale); superRes->setScale(scale);
superRes->set("iterations", iterations); superRes->setIterations(iterations);
superRes->set("temporalAreaRadius", temporalAreaRadius); superRes->setTemporalAreaRadius(temporalAreaRadius);
superRes->set("opticalFlow", opticalFlow); superRes->setOpticalFlow(opticalFlow);
superRes->setInput(makePtr<OneFrameSource_CPU>(frame)); superRes->setInput(makePtr<OneFrameSource_CPU>(frame));

View File

@ -460,7 +460,7 @@ namespace
func(_src, _dst, btvKernelSize, btvWeights); func(_src, _dst, btvKernelSize, btvWeights);
} }
class BTVL1_Base class BTVL1_Base : public cv::superres::SuperResolution
{ {
public: public:
BTVL1_Base(); BTVL1_Base();
@ -470,6 +470,17 @@ namespace
void collectGarbage(); 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<cv::superres::DenseOpticalFlowExt>, OpticalFlow, opticalFlow_)
protected: protected:
int scale_; int scale_;
int iterations_; int iterations_;
@ -479,7 +490,8 @@ namespace
int btvKernelSize_; int btvKernelSize_;
int blurKernelSize_; int blurKernelSize_;
double blurSigma_; double blurSigma_;
Ptr<DenseOpticalFlowExt> opticalFlow_; int temporalAreaRadius_; // not used in some implementations
Ptr<cv::superres::DenseOpticalFlowExt> opticalFlow_;
private: private:
bool ocl_process(InputArrayOfArrays src, OutputArray dst, InputArrayOfArrays forwardMotions, bool ocl_process(InputArrayOfArrays src, OutputArray dst, InputArrayOfArrays forwardMotions,
@ -539,6 +551,7 @@ namespace
btvKernelSize_ = 7; btvKernelSize_ = 7;
blurKernelSize_ = 5; blurKernelSize_ = 5;
blurSigma_ = 0.0; blurSigma_ = 0.0;
temporalAreaRadius_ = 0;
opticalFlow_ = createOptFlow_Farneback(); opticalFlow_ = createOptFlow_Farneback();
curBlurKernelSize_ = -1; curBlurKernelSize_ = -1;
@ -781,12 +794,9 @@ namespace
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class BTVL1 : class BTVL1 : public BTVL1_Base
public SuperResolution, private BTVL1_Base
{ {
public: public:
AlgorithmInfo* info() const;
BTVL1(); BTVL1();
void collectGarbage(); void collectGarbage();
@ -799,8 +809,6 @@ namespace
bool ocl_processImpl(Ptr<FrameSource>& frameSource, OutputArray output); bool ocl_processImpl(Ptr<FrameSource>& frameSource, OutputArray output);
private: private:
int temporalAreaRadius_;
void readNextFrame(Ptr<FrameSource>& frameSource); void readNextFrame(Ptr<FrameSource>& frameSource);
bool ocl_readNextFrame(Ptr<FrameSource>& frameSource); bool ocl_readNextFrame(Ptr<FrameSource>& frameSource);
@ -841,18 +849,6 @@ namespace
#endif #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<DenseOpticalFlowExt>(obj, "opticalFlow", obj.opticalFlow_, false, 0, 0, "Dense optical flow algorithm."))
BTVL1::BTVL1() BTVL1::BTVL1()
{ {
temporalAreaRadius_ = 4; temporalAreaRadius_ = 4;
@ -1101,7 +1097,7 @@ namespace
} }
} }
Ptr<SuperResolution> cv::superres::createSuperResolution_BTVL1() Ptr<cv::superres::SuperResolution> cv::superres::createSuperResolution_BTVL1()
{ {
return makePtr<BTVL1>(); return makePtr<BTVL1>();
} }

View File

@ -207,7 +207,7 @@ namespace
funcs[src.channels()](src, dst, ksize); funcs[src.channels()](src, dst, ksize);
} }
class BTVL1_CUDA_Base class BTVL1_CUDA_Base : public cv::superres::SuperResolution
{ {
public: public:
BTVL1_CUDA_Base(); BTVL1_CUDA_Base();
@ -218,6 +218,17 @@ namespace
void collectGarbage(); 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<cv::superres::DenseOpticalFlowExt>, OpticalFlow, opticalFlow_)
protected: protected:
int scale_; int scale_;
int iterations_; int iterations_;
@ -227,7 +238,8 @@ namespace
int btvKernelSize_; int btvKernelSize_;
int blurKernelSize_; int blurKernelSize_;
double blurSigma_; double blurSigma_;
Ptr<DenseOpticalFlowExt> opticalFlow_; int temporalAreaRadius_;
Ptr<cv::superres::DenseOpticalFlowExt> opticalFlow_;
private: private:
std::vector<Ptr<cuda::Filter> > filters_; std::vector<Ptr<cuda::Filter> > filters_;
@ -272,6 +284,7 @@ namespace
#else #else
opticalFlow_ = createOptFlow_Farneback(); opticalFlow_ = createOptFlow_Farneback();
#endif #endif
temporalAreaRadius_ = 0;
curBlurKernelSize_ = -1; curBlurKernelSize_ = -1;
curBlurSigma_ = -1.0; 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: public:
AlgorithmInfo* info() const;
BTVL1_CUDA(); BTVL1_CUDA();
void collectGarbage(); void collectGarbage();
@ -415,8 +426,6 @@ namespace
void processImpl(Ptr<FrameSource>& frameSource, OutputArray output); void processImpl(Ptr<FrameSource>& frameSource, OutputArray output);
private: private:
int temporalAreaRadius_;
void readNextFrame(Ptr<FrameSource>& frameSource); void readNextFrame(Ptr<FrameSource>& frameSource);
void processFrame(int idx); void processFrame(int idx);
@ -438,18 +447,6 @@ namespace
GpuMat finalOutput_; 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<DenseOpticalFlowExt>(obj, "opticalFlow", obj.opticalFlow_, false, 0, 0, "Dense optical flow algorithm."));
BTVL1_CUDA::BTVL1_CUDA() BTVL1_CUDA::BTVL1_CUDA()
{ {
temporalAreaRadius_ = 4; temporalAreaRadius_ = 4;

View File

@ -53,7 +53,7 @@ using namespace cv::superres::detail;
namespace namespace
{ {
class CpuOpticalFlow : public DenseOpticalFlowExt class CpuOpticalFlow : public virtual cv::superres::DenseOpticalFlowExt
{ {
public: public:
explicit CpuOpticalFlow(int work_type); explicit CpuOpticalFlow(int work_type);
@ -173,12 +173,20 @@ namespace
namespace namespace
{ {
class Farneback : public CpuOpticalFlow class Farneback : public CpuOpticalFlow, public cv::superres::FarnebackOpticalFlow
{ {
public: public:
AlgorithmInfo* info() const;
Farneback(); 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: protected:
void impl(InputArray input0, InputArray input1, OutputArray dst); void impl(InputArray input0, InputArray input1, OutputArray dst);
@ -193,15 +201,6 @@ namespace
int flags_; 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) Farneback::Farneback() : CpuOpticalFlow(CV_8UC1)
{ {
pyrScale_ = 0.5; pyrScale_ = 0.5;
@ -213,6 +212,16 @@ namespace
flags_ = 0; 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) void Farneback::impl(InputArray input0, InputArray input1, OutputArray dst)
{ {
calcOpticalFlowFarneback(input0, input1, (InputOutputArray)dst, pyrScale_, calcOpticalFlowFarneback(input0, input1, (InputOutputArray)dst, pyrScale_,
@ -221,7 +230,7 @@ namespace
} }
} }
Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_Farneback() Ptr<cv::superres::FarnebackOpticalFlow> cv::superres::createOptFlow_Farneback()
{ {
return makePtr<Farneback>(); return makePtr<Farneback>();
} }
@ -319,65 +328,53 @@ Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_Simple()
namespace 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: public:
AlgorithmInfo* info() const;
DualTVL1(); DualTVL1();
void calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2);
void collectGarbage(); 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: protected:
void impl(InputArray input0, InputArray input1, OutputArray dst); void impl(InputArray input0, InputArray input1, OutputArray dst);
private: private:
double tau_; Ptr<cv::DualTVL1OpticalFlow> alg_;
double lambda_;
double theta_;
int nscales_;
int warps_;
double epsilon_;
int iterations_;
bool useInitialFlow_;
Ptr<cv::DenseOpticalFlow> 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) DualTVL1::DualTVL1() : CpuOpticalFlow(CV_8UC1)
{ {
alg_ = cv::createOptFlow_DualTVL1(); alg_ = cv::createOptFlow_DualTVL1();
tau_ = alg_->getDouble("tau"); }
lambda_ = alg_->getDouble("lambda");
theta_ = alg_->getDouble("theta"); void DualTVL1::calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2)
nscales_ = alg_->getInt("nscales"); {
warps_ = alg_->getInt("warps"); CpuOpticalFlow::calc(frame0, frame1, flow1, flow2);
epsilon_ = alg_->getDouble("epsilon");
iterations_ = alg_->getInt("iterations");
useInitialFlow_ = alg_->getBool("useInitialFlow");
} }
void DualTVL1::impl(InputArray input0, InputArray input1, OutputArray dst) 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); alg_->calc(input0, input1, (InputOutputArray)dst);
} }
@ -388,7 +385,7 @@ namespace
} }
} }
Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_DualTVL1() Ptr<cv::superres::DualTVL1OpticalFlow> cv::superres::createOptFlow_DualTVL1()
{ {
return makePtr<DualTVL1>(); return makePtr<DualTVL1>();
} }
@ -398,35 +395,35 @@ Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_DualTVL1()
#ifndef HAVE_OPENCV_CUDAOPTFLOW #ifndef HAVE_OPENCV_CUDAOPTFLOW
Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_Farneback_CUDA() Ptr<cv::superres::FarnebackOpticalFlow> cv::superres::createOptFlow_Farneback_CUDA()
{ {
CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform");
return Ptr<DenseOpticalFlowExt>(); return Ptr<cv::superres::FarnebackOpticalFlow>();
} }
Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_DualTVL1_CUDA() Ptr<cv::superres::DualTVL1OpticalFlow> cv::superres::createOptFlow_DualTVL1_CUDA()
{ {
CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform");
return Ptr<DenseOpticalFlowExt>(); return Ptr<cv::superres::DualTVL1OpticalFlow>();
} }
Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_Brox_CUDA() Ptr<cv::superres::BroxOpticalFlow> cv::superres::createOptFlow_Brox_CUDA()
{ {
CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform");
return Ptr<DenseOpticalFlowExt>(); return Ptr<cv::superres::BroxOpticalFlow>();
} }
Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_PyrLK_CUDA() Ptr<cv::superres::PyrLKOpticalFlow> cv::superres::createOptFlow_PyrLK_CUDA()
{ {
CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform");
return Ptr<DenseOpticalFlowExt>(); return Ptr<cv::superres::PyrLKOpticalFlow>();
} }
#else // HAVE_OPENCV_CUDAOPTFLOW #else // HAVE_OPENCV_CUDAOPTFLOW
namespace namespace
{ {
class GpuOpticalFlow : public DenseOpticalFlowExt class GpuOpticalFlow : public virtual cv::superres::DenseOpticalFlowExt
{ {
public: public:
explicit GpuOpticalFlow(int work_type); explicit GpuOpticalFlow(int work_type);
@ -494,15 +491,20 @@ namespace
namespace namespace
{ {
class Brox_CUDA : public GpuOpticalFlow class Brox_CUDA : public GpuOpticalFlow, public virtual cv::superres::BroxOpticalFlow
{ {
public: public:
AlgorithmInfo* info() const;
Brox_CUDA(); Brox_CUDA();
void calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2);
void collectGarbage(); 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: protected:
void impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2); void impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2);
@ -517,14 +519,6 @@ namespace
Ptr<cuda::BroxOpticalFlow> alg_; Ptr<cuda::BroxOpticalFlow> 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) Brox_CUDA::Brox_CUDA() : GpuOpticalFlow(CV_32FC1)
{ {
alg_ = cuda::BroxOpticalFlow::create(0.197f, 50.0f, 0.8f, 10, 77, 10); alg_ = cuda::BroxOpticalFlow::create(0.197f, 50.0f, 0.8f, 10, 77, 10);
@ -537,6 +531,11 @@ namespace
solverIterations_ = alg_->getSolverIterations(); 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) void Brox_CUDA::impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2)
{ {
alg_->setFlowSmoothness(alpha_); alg_->setFlowSmoothness(alpha_);
@ -563,7 +562,7 @@ namespace
} }
} }
Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_Brox_CUDA() Ptr<cv::superres::BroxOpticalFlow> cv::superres::createOptFlow_Brox_CUDA()
{ {
return makePtr<Brox_CUDA>(); return makePtr<Brox_CUDA>();
} }
@ -573,15 +572,17 @@ Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_Brox_CUDA()
namespace namespace
{ {
class PyrLK_CUDA : public GpuOpticalFlow class PyrLK_CUDA : public GpuOpticalFlow, public cv::superres::PyrLKOpticalFlow
{ {
public: public:
AlgorithmInfo* info() const;
PyrLK_CUDA(); PyrLK_CUDA();
void calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2);
void collectGarbage(); void collectGarbage();
CV_IMPL_PROPERTY(int, WindowSize, winSize_)
CV_IMPL_PROPERTY(int, MaxLevel, maxLevel_)
CV_IMPL_PROPERTY(int, Iterations, iterations_)
protected: protected:
void impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2); void impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2);
@ -593,11 +594,6 @@ namespace
Ptr<cuda::DensePyrLKOpticalFlow> alg_; Ptr<cuda::DensePyrLKOpticalFlow> 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) PyrLK_CUDA::PyrLK_CUDA() : GpuOpticalFlow(CV_8UC1)
{ {
alg_ = cuda::DensePyrLKOpticalFlow::create(); alg_ = cuda::DensePyrLKOpticalFlow::create();
@ -607,6 +603,11 @@ namespace
iterations_ = alg_->getNumIters(); 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) void PyrLK_CUDA::impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2)
{ {
alg_->setWinSize(Size(winSize_, winSize_)); alg_->setWinSize(Size(winSize_, winSize_));
@ -630,7 +631,7 @@ namespace
} }
} }
Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_PyrLK_CUDA() Ptr<cv::superres::PyrLKOpticalFlow> cv::superres::createOptFlow_PyrLK_CUDA()
{ {
return makePtr<PyrLK_CUDA>(); return makePtr<PyrLK_CUDA>();
} }
@ -640,15 +641,21 @@ Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_PyrLK_CUDA()
namespace namespace
{ {
class Farneback_CUDA : public GpuOpticalFlow class Farneback_CUDA : public GpuOpticalFlow, public cv::superres::FarnebackOpticalFlow
{ {
public: public:
AlgorithmInfo* info() const;
Farneback_CUDA(); Farneback_CUDA();
void calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2);
void collectGarbage(); 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: protected:
void impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2); void impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2);
@ -664,15 +671,6 @@ namespace
Ptr<cuda::FarnebackOpticalFlow> alg_; Ptr<cuda::FarnebackOpticalFlow> 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) Farneback_CUDA::Farneback_CUDA() : GpuOpticalFlow(CV_8UC1)
{ {
alg_ = cuda::FarnebackOpticalFlow::create(); alg_ = cuda::FarnebackOpticalFlow::create();
@ -686,6 +684,11 @@ namespace
flags_ = alg_->getFlags(); 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) void Farneback_CUDA::impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2)
{ {
alg_->setPyrScale(pyrScale_); alg_->setPyrScale(pyrScale_);
@ -713,7 +716,7 @@ namespace
} }
} }
Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_Farneback_CUDA() Ptr<cv::superres::FarnebackOpticalFlow> cv::superres::createOptFlow_Farneback_CUDA()
{ {
return makePtr<Farneback_CUDA>(); return makePtr<Farneback_CUDA>();
} }
@ -723,15 +726,22 @@ Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_Farneback_CUDA()
namespace namespace
{ {
class DualTVL1_CUDA : public GpuOpticalFlow class DualTVL1_CUDA : public GpuOpticalFlow, public cv::superres::DualTVL1OpticalFlow
{ {
public: public:
AlgorithmInfo* info() const;
DualTVL1_CUDA(); DualTVL1_CUDA();
void calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2);
void collectGarbage(); 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: protected:
void impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2); void impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2);
@ -748,16 +758,6 @@ namespace
Ptr<cuda::OpticalFlowDual_TVL1> alg_; Ptr<cuda::OpticalFlowDual_TVL1> 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) DualTVL1_CUDA::DualTVL1_CUDA() : GpuOpticalFlow(CV_8UC1)
{ {
alg_ = cuda::OpticalFlowDual_TVL1::create(); alg_ = cuda::OpticalFlowDual_TVL1::create();
@ -772,6 +772,11 @@ namespace
useInitialFlow_ = alg_->getUseInitialFlow(); 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) void DualTVL1_CUDA::impl(const GpuMat& input0, const GpuMat& input1, GpuMat& dst1, GpuMat& dst2)
{ {
alg_->setTau(tau_); alg_->setTau(tau_);
@ -800,7 +805,7 @@ namespace
} }
} }
Ptr<DenseOpticalFlowExt> cv::superres::createOptFlow_DualTVL1_CUDA() Ptr<cv::superres::DualTVL1OpticalFlow> cv::superres::createOptFlow_DualTVL1_CUDA()
{ {
return makePtr<DualTVL1_CUDA>(); return makePtr<DualTVL1_CUDA>();
} }

View File

@ -45,11 +45,6 @@
using namespace cv; using namespace cv;
using namespace cv::superres; using namespace cv::superres;
bool cv::superres::initModule_superres()
{
return !createSuperResolution_BTVL1().empty();
}
cv::superres::SuperResolution::SuperResolution() cv::superres::SuperResolution::SuperResolution()
{ {
frameSource_ = createFrameSource_Empty(); frameSource_ = createFrameSource_Empty();

View File

@ -222,11 +222,11 @@ void SuperResolution::RunTest(cv::Ptr<cv::superres::SuperResolution> superRes)
ASSERT_FALSE( superRes.empty() ); ASSERT_FALSE( superRes.empty() );
const int btvKernelSize = superRes->getInt("btvKernelSize"); const int btvKernelSize = superRes->getKernelSize();
superRes->set("scale", scale); superRes->setScale(scale);
superRes->set("iterations", iterations); superRes->setIterations(iterations);
superRes->set("temporalAreaRadius", temporalAreaRadius); superRes->setTemporalAreaRadius(temporalAreaRadius);
cv::Ptr<cv::superres::FrameSource> goldSource(new AllignedFrameSource(cv::superres::createFrameSource_Video(inputVideoName), scale)); cv::Ptr<cv::superres::FrameSource> goldSource(new AllignedFrameSource(cv::superres::createFrameSource_Video(inputVideoName), scale));
cv::Ptr<cv::superres::FrameSource> lowResSource(new DegradeFrameSource( cv::Ptr<cv::superres::FrameSource> lowResSource(new DegradeFrameSource(

View File

@ -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. /** @brief "Dual TV L1" Optical Flow Algorithm.
The class implements the "Dual TV L1" optical flow algorithm described in @cite Zach2007 and 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". 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". 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: public:
/** @brief Calculates an optical flow. //! @name Time step of the numerical scheme
CV_PURE_PROPERTY(double, Tau)
@param I0 first 8-bit single-channel input image. //! @name Weight parameter for the data term, attachment parameter
@param I1 second input image of the same size and the same type as prev. CV_PURE_PROPERTY(double, Lambda)
@param flow computed flow image that has the same size as prev and type CV_32FC2. //! @name Weight parameter for (u - v)^2, tightness parameter
*/ CV_PURE_PROPERTY(double, Theta)
CV_WRAP virtual void calc( InputArray I0, InputArray I1, InputOutputArray flow ) = 0; //! @name coefficient for additional illumination variation term
/** @brief Releases all inner buffers. CV_PURE_PROPERTY(double, Gamma)
*/ //! @name Number of scales used to create the pyramid of images
CV_WRAP virtual void collectGarbage() = 0; 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 /** @brief Creates instance of cv::DenseOpticalFlow
*/ */
CV_EXPORTS_W Ptr<DenseOpticalFlow> createOptFlow_DualTVL1(); CV_EXPORTS_W Ptr<DualTVL1OpticalFlow> createOptFlow_DualTVL1();
//! @} video_track //! @} video_track

View File

@ -87,11 +87,11 @@ OCL_PERF_TEST_P(OpticalFlowDualTVL1Fixture, OpticalFlowDualTVL1,
declare.in(uFrame0, uFrame1, WARMUP_READ).out(uFlow, WARMUP_READ); declare.in(uFrame0, uFrame1, WARMUP_READ).out(uFlow, WARMUP_READ);
//create algorithm //create algorithm
cv::Ptr<cv::DenseOpticalFlow> alg = cv::createOptFlow_DualTVL1(); cv::Ptr<cv::DualTVL1OpticalFlow> alg = cv::createOptFlow_DualTVL1();
//set parameters //set parameters
alg->set("scaleStep", scaleStep); alg->setScaleStep(scaleStep);
alg->setInt("medianFiltering", medianFiltering); alg->setMedianFiltering(medianFiltering);
if (useInitFlow) if (useInitFlow)
{ {
@ -100,7 +100,7 @@ OCL_PERF_TEST_P(OpticalFlowDualTVL1Fixture, OpticalFlowDualTVL1,
} }
//set flag to use initial flow //set flag to use initial flow
alg->setBool("useInitialFlow", useInitFlow); alg->setUseInitialFlow(useInitFlow);
OCL_TEST_CYCLE() OCL_TEST_CYCLE()
alg->calc(uFrame0, uFrame1, uFlow); alg->calc(uFrame0, uFrame1, uFlow);
@ -109,4 +109,4 @@ OCL_PERF_TEST_P(OpticalFlowDualTVL1Fixture, OpticalFlowDualTVL1,
} }
} // namespace cvtest::ocl } // namespace cvtest::ocl
#endif // HAVE_OPENCL #endif // HAVE_OPENCL

View File

@ -160,8 +160,6 @@ public:
nNextLongUpdate = Scalar::all(0); nNextLongUpdate = Scalar::all(0);
} }
virtual AlgorithmInfo* info() const { return 0; }
virtual int getHistory() const { return history; } virtual int getHistory() const { return history; }
virtual void setHistory(int _nframes) { history = _nframes; } virtual void setHistory(int _nframes) { history = _nframes; }

View File

@ -230,8 +230,6 @@ public:
} }
} }
virtual AlgorithmInfo* info() const { return 0; }
virtual int getHistory() const { return history; } virtual int getHistory() const { return history; }
virtual void setHistory(int _nframes) { history = _nframes; } virtual void setHistory(int _nframes) { history = _nframes; }

View File

@ -86,7 +86,7 @@ using namespace cv;
namespace { namespace {
class OpticalFlowDual_TVL1 : public DenseOpticalFlow class OpticalFlowDual_TVL1 : public DualTVL1OpticalFlow
{ {
public: public:
OpticalFlowDual_TVL1(); OpticalFlowDual_TVL1();
@ -94,7 +94,18 @@ public:
void calc(InputArray I0, InputArray I1, InputOutputArray flow); void calc(InputArray I0, InputArray I1, InputOutputArray flow);
void collectGarbage(); 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: protected:
double tau; double tau;
@ -1416,35 +1427,9 @@ void OpticalFlowDual_TVL1::collectGarbage()
dum.norm_buf.release(); 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 } // namespace
Ptr<DenseOpticalFlow> cv::createOptFlow_DualTVL1() Ptr<DualTVL1OpticalFlow> cv::createOptFlow_DualTVL1()
{ {
return makePtr<OpticalFlowDual_TVL1>(); return makePtr<OpticalFlowDual_TVL1>();
} }

View File

@ -82,11 +82,11 @@ OCL_TEST_P(OpticalFlowTVL1, Mat)
cv::Mat flow; cv::UMat uflow; cv::Mat flow; cv::UMat uflow;
//create algorithm //create algorithm
cv::Ptr<cv::DenseOpticalFlow> alg = cv::createOptFlow_DualTVL1(); cv::Ptr<cv::DualTVL1OpticalFlow> alg = cv::createOptFlow_DualTVL1();
//set parameters //set parameters
alg->set("scaleStep", scaleStep); alg->setScaleStep(scaleStep);
alg->setInt("medianFiltering", medianFiltering); alg->setMedianFiltering(medianFiltering);
//create initial flow as result of algorithm calculation //create initial flow as result of algorithm calculation
if (useInitFlow) if (useInitFlow)
@ -96,7 +96,7 @@ OCL_TEST_P(OpticalFlowTVL1, Mat)
} }
//set flag to use initial flow as it is ready to use //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_OFF(alg->calc(frame0, frame1, flow));
OCL_ON(alg->calc(frame0, frame1, uflow)); OCL_ON(alg->calc(frame0, frame1, uflow));
@ -114,4 +114,4 @@ OCL_INSTANTIATE_TEST_CASE_P(Video, OpticalFlowTVL1,
} } // namespace cvtest::ocl } } // namespace cvtest::ocl
#endif // HAVE_OPENCL #endif // HAVE_OPENCL

View File

@ -138,7 +138,7 @@ int main(int argc, char **argv)
Stats stats, akaze_stats, orb_stats; Stats stats, akaze_stats, orb_stats;
Ptr<AKAZE> akaze = AKAZE::create(); Ptr<AKAZE> akaze = AKAZE::create();
akaze->set("threshold", akaze_thresh); akaze->setThreshold(akaze_thresh);
Ptr<ORB> orb = ORB::create(); Ptr<ORB> orb = ORB::create();
orb->setMaxFeatures(stats.keypoints); orb->setMaxFeatures(stats.keypoints);
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce-Hamming"); Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce-Hamming");
@ -163,7 +163,7 @@ int main(int argc, char **argv)
akaze_draw_stats = stats; akaze_draw_stats = stats;
} }
orb_tracker.getDetector()->set("nFeatures", stats.keypoints); orb->setMaxFeatures(stats.keypoints);
orb_res = orb_tracker.process(frame, stats); orb_res = orb_tracker.process(frame, stats);
orb_stats += stats; orb_stats += stats;
if(update_stats) { if(update_stats) {

View File

@ -26,32 +26,32 @@ using namespace cv::superres;
cout << tm.getTimeSec() << " sec" << endl; \ cout << tm.getTimeSec() << " sec" << endl; \
} }
static Ptr<DenseOpticalFlowExt> createOptFlow(const string& name, bool useGpu) static Ptr<cv::superres::DenseOpticalFlowExt> createOptFlow(const string& name, bool useGpu)
{ {
if (name == "farneback") if (name == "farneback")
{ {
if (useGpu) if (useGpu)
return createOptFlow_Farneback_CUDA(); return cv::superres::createOptFlow_Farneback_CUDA();
else else
return createOptFlow_Farneback(); return cv::superres::createOptFlow_Farneback();
} }
/*else if (name == "simple") /*else if (name == "simple")
return createOptFlow_Simple();*/ return createOptFlow_Simple();*/
else if (name == "tvl1") else if (name == "tvl1")
{ {
if (useGpu) if (useGpu)
return createOptFlow_DualTVL1_CUDA(); return cv::superres::createOptFlow_DualTVL1_CUDA();
else else
return createOptFlow_DualTVL1(); return cv::superres::createOptFlow_DualTVL1();
} }
else if (name == "brox") else if (name == "brox")
return createOptFlow_Brox_CUDA(); return cv::superres::createOptFlow_Brox_CUDA();
else if (name == "pyrlk") else if (name == "pyrlk")
return createOptFlow_PyrLK_CUDA(); return cv::superres::createOptFlow_PyrLK_CUDA();
else else
cerr << "Incorrect Optical Flow algorithm - " << name << endl; cerr << "Incorrect Optical Flow algorithm - " << name << endl;
return Ptr<DenseOpticalFlowExt>(); return Ptr<cv::superres::DenseOpticalFlowExt>();
} }
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
@ -92,15 +92,15 @@ int main(int argc, const char* argv[])
else else
superRes = createSuperResolution_BTVL1(); superRes = createSuperResolution_BTVL1();
Ptr<DenseOpticalFlowExt> of = createOptFlow(optFlow, useCuda); Ptr<cv::superres::DenseOpticalFlowExt> of = createOptFlow(optFlow, useCuda);
if (of.empty()) if (of.empty())
return EXIT_FAILURE; return EXIT_FAILURE;
superRes->set("opticalFlow", of); superRes->setOpticalFlow(of);
superRes->set("scale", scale); superRes->setScale(scale);
superRes->set("iterations", iterations); superRes->setIterations(iterations);
superRes->set("temporalAreaRadius", temporalAreaRadius); superRes->setTemporalAreaRadius(temporalAreaRadius);
Ptr<FrameSource> frameSource; Ptr<FrameSource> frameSource;
if (useCuda) if (useCuda)

View File

@ -62,19 +62,17 @@ int main(int argc, char* argv[])
cout << "FOUND " << keypoints2GPU.cols << " keypoints on second image" << endl; cout << "FOUND " << keypoints2GPU.cols << " keypoints on second image" << endl;
// matching descriptors // matching descriptors
BFMatcher_CUDA matcher(surf.defaultNorm()); Ptr<cv::cuda::DescriptorMatcher> matcher = cv::cuda::DescriptorMatcher::createBFMatcher(surf.defaultNorm());
GpuMat trainIdx, distance; vector<DMatch> matches;
matcher.matchSingle(descriptors1GPU, descriptors2GPU, trainIdx, distance); matcher->match(descriptors1GPU, descriptors2GPU, matches);
// downloading results // downloading results
vector<KeyPoint> keypoints1, keypoints2; vector<KeyPoint> keypoints1, keypoints2;
vector<float> descriptors1, descriptors2; vector<float> descriptors1, descriptors2;
vector<DMatch> matches;
surf.downloadKeypoints(keypoints1GPU, keypoints1); surf.downloadKeypoints(keypoints1GPU, keypoints1);
surf.downloadKeypoints(keypoints2GPU, keypoints2); surf.downloadKeypoints(keypoints2GPU, keypoints2);
surf.downloadDescriptors(descriptors1GPU, descriptors1); surf.downloadDescriptors(descriptors1GPU, descriptors1);
surf.downloadDescriptors(descriptors2GPU, descriptors2); surf.downloadDescriptors(descriptors2GPU, descriptors2);
BFMatcher_CUDA::matchDownload(trainIdx, distance, matches);
// drawing the results // drawing the results
Mat img_matches; Mat img_matches;