mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge pull request #3911 from vpisarev:core_tweaks
This commit is contained in:
@@ -10,8 +10,10 @@
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2000-2015, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2015, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -2921,6 +2923,10 @@ public:
|
||||
Algorithm();
|
||||
virtual ~Algorithm();
|
||||
|
||||
/** @brief Clears the algorithm state
|
||||
*/
|
||||
CV_WRAP virtual void clear() {}
|
||||
|
||||
/** @brief Stores algorithm parameters in a file storage
|
||||
*/
|
||||
virtual void write(FileStorage& fs) const { (void)fs; }
|
||||
@@ -2928,6 +2934,75 @@ public:
|
||||
/** @brief Reads algorithm parameters from a file storage
|
||||
*/
|
||||
virtual void read(const FileNode& fn) { (void)fn; }
|
||||
|
||||
/** @brief Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read
|
||||
*/
|
||||
virtual bool empty() const { return false; }
|
||||
|
||||
/** @brief Reads algorithm from the file node
|
||||
|
||||
This is static template method of Algorithm. It's usage is following (in the case of SVM):
|
||||
@code
|
||||
Ptr<SVM> svm = Algorithm::read<SVM>(fn);
|
||||
@endcode
|
||||
In order to make this method work, the derived class must overwrite Algorithm::read(const
|
||||
FileNode& fn) and also have static create() method without parameters
|
||||
(or with all the optional parameters)
|
||||
*/
|
||||
template<typename _Tp> static Ptr<_Tp> read(const FileNode& fn)
|
||||
{
|
||||
Ptr<_Tp> obj = _Tp::create();
|
||||
obj->read(fn);
|
||||
return !obj->empty() ? obj : Ptr<_Tp>();
|
||||
}
|
||||
|
||||
/** @brief Loads algorithm from the file
|
||||
|
||||
@param filename Name of the file to read.
|
||||
@param objname The optional name of the node to read (if empty, the first top-level node will be used)
|
||||
|
||||
This is static template method of Algorithm. It's usage is following (in the case of SVM):
|
||||
@code
|
||||
Ptr<SVM> svm = Algorithm::load<SVM>("my_svm_model.xml");
|
||||
@endcode
|
||||
In order to make this method work, the derived class must overwrite Algorithm::read(const
|
||||
FileNode& fn).
|
||||
*/
|
||||
template<typename _Tp> static Ptr<_Tp> load(const String& filename, const String& objname=String())
|
||||
{
|
||||
FileStorage fs(filename, FileStorage::READ);
|
||||
FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname];
|
||||
Ptr<_Tp> obj = _Tp::create();
|
||||
obj->read(fn);
|
||||
return !obj->empty() ? obj : Ptr<_Tp>();
|
||||
}
|
||||
|
||||
/** @brief Loads algorithm from a String
|
||||
|
||||
@param strModel The string variable containing the model you want to load.
|
||||
@param objname The optional name of the node to read (if empty, the first top-level node will be used)
|
||||
|
||||
This is static template method of Algorithm. It's usage is following (in the case of SVM):
|
||||
@code
|
||||
Ptr<SVM> svm = Algorithm::loadFromString<SVM>(myStringModel);
|
||||
@endcode
|
||||
*/
|
||||
template<typename _Tp> static Ptr<_Tp> loadFromString(const String& strModel, const String& objname=String())
|
||||
{
|
||||
FileStorage fs(strModel, FileStorage::READ + FileStorage::MEMORY);
|
||||
FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname];
|
||||
Ptr<_Tp> obj = _Tp::create();
|
||||
obj->read(fn);
|
||||
return !obj->empty() ? obj : Ptr<_Tp>();
|
||||
}
|
||||
|
||||
/** Saves the algorithm to a file.
|
||||
In order to make this method work, the derived class must implement Algorithm::write(FileStorage& fs). */
|
||||
CV_WRAP virtual void save(const String& filename) const;
|
||||
|
||||
/** Returns the algorithm string identifier.
|
||||
This string is used as top level xml/yml node tag when the object is saved to a file or string. */
|
||||
CV_WRAP virtual String getDefaultName() const;
|
||||
};
|
||||
|
||||
struct Param {
|
||||
|
||||
@@ -1,3 +1,47 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2015, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_CORE_IPPASYNC_HPP__
|
||||
#define __OPENCV_CORE_IPPASYNC_HPP__
|
||||
|
||||
|
||||
@@ -185,39 +185,43 @@ public:
|
||||
_InputArray(const UMat& um);
|
||||
_InputArray(const std::vector<UMat>& umv);
|
||||
|
||||
virtual Mat getMat(int idx=-1) const;
|
||||
virtual UMat getUMat(int idx=-1) const;
|
||||
virtual void getMatVector(std::vector<Mat>& mv) const;
|
||||
virtual void getUMatVector(std::vector<UMat>& umv) const;
|
||||
virtual cuda::GpuMat getGpuMat() const;
|
||||
virtual ogl::Buffer getOGlBuffer() const;
|
||||
void* getObj() const;
|
||||
Mat getMat(int idx=-1) const;
|
||||
Mat getMat_(int idx=-1) const;
|
||||
UMat getUMat(int idx=-1) const;
|
||||
void getMatVector(std::vector<Mat>& mv) const;
|
||||
void getUMatVector(std::vector<UMat>& umv) const;
|
||||
cuda::GpuMat getGpuMat() const;
|
||||
ogl::Buffer getOGlBuffer() const;
|
||||
|
||||
virtual int kind() const;
|
||||
virtual int dims(int i=-1) const;
|
||||
virtual int cols(int i=-1) const;
|
||||
virtual int rows(int i=-1) const;
|
||||
virtual Size size(int i=-1) const;
|
||||
virtual int sizend(int* sz, int i=-1) const;
|
||||
virtual bool sameSize(const _InputArray& arr) const;
|
||||
virtual size_t total(int i=-1) const;
|
||||
virtual int type(int i=-1) const;
|
||||
virtual int depth(int i=-1) const;
|
||||
virtual int channels(int i=-1) const;
|
||||
virtual bool isContinuous(int i=-1) const;
|
||||
virtual bool isSubmatrix(int i=-1) const;
|
||||
virtual bool empty() const;
|
||||
virtual void copyTo(const _OutputArray& arr) const;
|
||||
virtual void copyTo(const _OutputArray& arr, const _InputArray & mask) const;
|
||||
virtual size_t offset(int i=-1) const;
|
||||
virtual size_t step(int i=-1) const;
|
||||
int getFlags() const;
|
||||
void* getObj() const;
|
||||
Size getSz() const;
|
||||
|
||||
int kind() const;
|
||||
int dims(int i=-1) const;
|
||||
int cols(int i=-1) const;
|
||||
int rows(int i=-1) const;
|
||||
Size size(int i=-1) const;
|
||||
int sizend(int* sz, int i=-1) const;
|
||||
bool sameSize(const _InputArray& arr) const;
|
||||
size_t total(int i=-1) const;
|
||||
int type(int i=-1) const;
|
||||
int depth(int i=-1) const;
|
||||
int channels(int i=-1) const;
|
||||
bool isContinuous(int i=-1) const;
|
||||
bool isSubmatrix(int i=-1) const;
|
||||
bool empty() const;
|
||||
void copyTo(const _OutputArray& arr) const;
|
||||
void copyTo(const _OutputArray& arr, const _InputArray & mask) const;
|
||||
size_t offset(int i=-1) const;
|
||||
size_t step(int i=-1) const;
|
||||
bool isMat() const;
|
||||
bool isUMat() const;
|
||||
bool isMatVector() const;
|
||||
bool isUMatVector() const;
|
||||
bool isMatx() const;
|
||||
|
||||
virtual ~_InputArray();
|
||||
~_InputArray();
|
||||
|
||||
protected:
|
||||
int flags;
|
||||
@@ -303,21 +307,21 @@ public:
|
||||
_OutputArray(const UMat& m);
|
||||
_OutputArray(const std::vector<UMat>& vec);
|
||||
|
||||
virtual bool fixedSize() const;
|
||||
virtual bool fixedType() const;
|
||||
virtual bool needed() const;
|
||||
virtual Mat& getMatRef(int i=-1) const;
|
||||
virtual UMat& getUMatRef(int i=-1) const;
|
||||
virtual cuda::GpuMat& getGpuMatRef() const;
|
||||
virtual ogl::Buffer& getOGlBufferRef() const;
|
||||
virtual cuda::HostMem& getHostMemRef() const;
|
||||
virtual void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
||||
virtual void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
||||
virtual void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
||||
virtual void createSameSize(const _InputArray& arr, int mtype) const;
|
||||
virtual void release() const;
|
||||
virtual void clear() const;
|
||||
virtual void setTo(const _InputArray& value, const _InputArray & mask = _InputArray()) const;
|
||||
bool fixedSize() const;
|
||||
bool fixedType() const;
|
||||
bool needed() const;
|
||||
Mat& getMatRef(int i=-1) const;
|
||||
UMat& getUMatRef(int i=-1) const;
|
||||
cuda::GpuMat& getGpuMatRef() const;
|
||||
ogl::Buffer& getOGlBufferRef() const;
|
||||
cuda::HostMem& getHostMemRef() const;
|
||||
void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
||||
void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
||||
void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
||||
void createSameSize(const _InputArray& arr, int mtype) const;
|
||||
void release() const;
|
||||
void clear() const;
|
||||
void setTo(const _InputArray& value, const _InputArray & mask = _InputArray()) const;
|
||||
|
||||
void assign(const UMat& u) const;
|
||||
void assign(const Mat& m) const;
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -61,6 +63,8 @@ inline void _InputArray::init(int _flags, const void* _obj, Size _sz)
|
||||
{ flags = _flags; obj = (void*)_obj; sz = _sz; }
|
||||
|
||||
inline void* _InputArray::getObj() const { return obj; }
|
||||
inline int _InputArray::getFlags() const { return flags; }
|
||||
inline Size _InputArray::getSz() const { return sz; }
|
||||
|
||||
inline _InputArray::_InputArray() { init(NONE, 0); }
|
||||
inline _InputArray::_InputArray(int _flags, void* _obj) { init(_flags, _obj); }
|
||||
@@ -110,6 +114,13 @@ inline _InputArray::_InputArray(const cuda::HostMem& cuda_mem)
|
||||
|
||||
inline _InputArray::~_InputArray() {}
|
||||
|
||||
inline Mat _InputArray::getMat(int i) const
|
||||
{
|
||||
if( kind() == MAT && i < 0 )
|
||||
return *(const Mat*)obj;
|
||||
return getMat_(i);
|
||||
}
|
||||
|
||||
inline bool _InputArray::isMat() const { return kind() == _InputArray::MAT; }
|
||||
inline bool _InputArray::isUMat() const { return kind() == _InputArray::UMAT; }
|
||||
inline bool _InputArray::isMatVector() const { return kind() == _InputArray::STD_VECTOR_MAT; }
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright( C) 2000, Intel Corporation, all rights reserved.
|
||||
// Copyright( C) 2000-2015, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2011-2013, NVIDIA Corporation, all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
|
||||
@@ -53,6 +53,20 @@ Algorithm::~Algorithm()
|
||||
{
|
||||
}
|
||||
|
||||
void Algorithm::save(const String& filename) const
|
||||
{
|
||||
FileStorage fs(filename, FileStorage::WRITE);
|
||||
fs << getDefaultName() << "{";
|
||||
fs << "format" << (int)3;
|
||||
write(fs);
|
||||
fs << "}";
|
||||
}
|
||||
|
||||
String Algorithm::getDefaultName() const
|
||||
{
|
||||
return String("my_object");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
|
||||
@@ -1113,7 +1113,7 @@ void scalarToRawData(const Scalar& s, void* _buf, int type, int unroll_to)
|
||||
Input/Output Array
|
||||
\*************************************************************************************************/
|
||||
|
||||
Mat _InputArray::getMat(int i) const
|
||||
Mat _InputArray::getMat_(int i) const
|
||||
{
|
||||
int k = kind();
|
||||
int accessFlags = flags & ACCESS_MASK;
|
||||
|
||||
@@ -297,11 +297,12 @@ public:
|
||||
COMPRESSED_INPUT=2,
|
||||
PREPROCESSED_INPUT=4
|
||||
};
|
||||
CV_WRAP virtual void clear();
|
||||
|
||||
/** @brief Returns the number of variables in training samples */
|
||||
CV_WRAP virtual int getVarCount() const = 0;
|
||||
|
||||
CV_WRAP virtual bool empty() const;
|
||||
|
||||
/** @brief Returns true if the model is trained */
|
||||
CV_WRAP virtual bool isTrained() const = 0;
|
||||
/** @brief Returns true if the model is classifier */
|
||||
@@ -347,40 +348,6 @@ public:
|
||||
*/
|
||||
CV_WRAP virtual float predict( InputArray samples, OutputArray results=noArray(), int flags=0 ) const = 0;
|
||||
|
||||
/** @brief Loads model from the file
|
||||
|
||||
This is static template method of StatModel. It's usage is following (in the case of SVM):
|
||||
@code
|
||||
Ptr<SVM> svm = StatModel::load<SVM>("my_svm_model.xml");
|
||||
@endcode
|
||||
In order to make this method work, the derived class must overwrite Algorithm::read(const
|
||||
FileNode& fn).
|
||||
*/
|
||||
template<typename _Tp> static Ptr<_Tp> load(const String& filename)
|
||||
{
|
||||
FileStorage fs(filename, FileStorage::READ);
|
||||
Ptr<_Tp> model = _Tp::create();
|
||||
model->read(fs.getFirstTopLevelNode());
|
||||
return model->isTrained() ? model : Ptr<_Tp>();
|
||||
}
|
||||
|
||||
/** @brief Loads model from a String
|
||||
|
||||
@param strModel The string variable containing the model you want to load.
|
||||
|
||||
This is static template method of StatModel. It's usage is following (in the case of SVM):
|
||||
@code
|
||||
Ptr<SVM> svm = StatModel::loadFromString<SVM>(myStringModel);
|
||||
@endcode
|
||||
*/
|
||||
template<typename _Tp> static Ptr<_Tp> loadFromString(const String& strModel)
|
||||
{
|
||||
FileStorage fs(strModel, FileStorage::READ + FileStorage::MEMORY);
|
||||
Ptr<_Tp> model = _Tp::create();
|
||||
model->read(fs.getFirstTopLevelNode());
|
||||
return model->isTrained() ? model : Ptr<_Tp>();
|
||||
}
|
||||
|
||||
/** @brief Create and train model with default parameters
|
||||
|
||||
The class must implement static `create()` method with no parameters or with all default parameter values
|
||||
@@ -390,14 +357,6 @@ public:
|
||||
Ptr<_Tp> model = _Tp::create();
|
||||
return !model.empty() && model->train(data, flags) ? model : Ptr<_Tp>();
|
||||
}
|
||||
|
||||
/** Saves the model to a file.
|
||||
In order to make this method work, the derived class must implement Algorithm::write(FileStorage& fs). */
|
||||
CV_WRAP virtual void save(const String& filename) const;
|
||||
|
||||
/** Returns model string identifier.
|
||||
This string is used as top level xml/yml node tag when model is saved to a file or string. */
|
||||
CV_WRAP virtual String getDefaultModelName() const = 0;
|
||||
};
|
||||
|
||||
/****************************************************************************************\
|
||||
@@ -939,7 +898,7 @@ public:
|
||||
|
||||
/** Creates empty %EM model.
|
||||
The model should be trained then using StatModel::train(traindata, flags) method. Alternatively, you
|
||||
can use one of the EM::train\* methods or load it from file using StatModel::load\<EM\>(filename).
|
||||
can use one of the EM::train\* methods or load it from file using Algorithm::load\<EM\>(filename).
|
||||
*/
|
||||
CV_WRAP static Ptr<EM> create();
|
||||
};
|
||||
@@ -1127,7 +1086,7 @@ public:
|
||||
|
||||
The static method creates empty decision tree with the specified parameters. It should be then
|
||||
trained using train method (see StatModel::train). Alternatively, you can load the model from
|
||||
file using StatModel::load\<DTrees\>(filename).
|
||||
file using Algorithm::load\<DTrees\>(filename).
|
||||
*/
|
||||
CV_WRAP static Ptr<DTrees> create();
|
||||
};
|
||||
@@ -1181,7 +1140,7 @@ public:
|
||||
|
||||
/** Creates the empty model.
|
||||
Use StatModel::train to train the model, StatModel::train to create and train the model,
|
||||
StatModel::load to load the pre-trained model.
|
||||
Algorithm::load to load the pre-trained model.
|
||||
*/
|
||||
CV_WRAP static Ptr<RTrees> create();
|
||||
};
|
||||
@@ -1231,7 +1190,7 @@ public:
|
||||
};
|
||||
|
||||
/** Creates the empty model.
|
||||
Use StatModel::train to train the model, StatModel::load\<Boost\>(filename) to load the pre-trained model. */
|
||||
Use StatModel::train to train the model, Algorithm::load\<Boost\>(filename) to load the pre-trained model. */
|
||||
CV_WRAP static Ptr<Boost> create();
|
||||
};
|
||||
|
||||
@@ -1416,7 +1375,7 @@ public:
|
||||
|
||||
/** @brief Creates empty model
|
||||
|
||||
Use StatModel::train to train the model, StatModel::load\<ANN_MLP\>(filename) to load the pre-trained model.
|
||||
Use StatModel::train to train the model, Algorithm::load\<ANN_MLP\>(filename) to load the pre-trained model.
|
||||
Note that the train method has optional flags: ANN_MLP::TrainFlags.
|
||||
*/
|
||||
static Ptr<ANN_MLP> create();
|
||||
|
||||
@@ -1294,7 +1294,7 @@ public:
|
||||
return layer_sizes.empty() ? 0 : layer_sizes[0];
|
||||
}
|
||||
|
||||
String getDefaultModelName() const
|
||||
String getDefaultName() const
|
||||
{
|
||||
return "opencv_ml_ann_mlp";
|
||||
}
|
||||
|
||||
@@ -465,7 +465,7 @@ public:
|
||||
CV_WRAP_SAME_PROPERTY(float, RegressionAccuracy, impl.params)
|
||||
CV_WRAP_SAME_PROPERTY_S(cv::Mat, Priors, impl.params)
|
||||
|
||||
String getDefaultModelName() const { return "opencv_ml_boost"; }
|
||||
String getDefaultName() const { return "opencv_ml_boost"; }
|
||||
|
||||
bool train( const Ptr<TrainData>& trainData, int flags )
|
||||
{
|
||||
|
||||
@@ -227,7 +227,7 @@ public:
|
||||
return means.cols;
|
||||
}
|
||||
|
||||
String getDefaultModelName() const
|
||||
String getDefaultName() const
|
||||
{
|
||||
return "opencv_ml_em";
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ ParamGrid::ParamGrid(double _minVal, double _maxVal, double _logStep)
|
||||
logStep = std::max(_logStep, 1.);
|
||||
}
|
||||
|
||||
void StatModel::clear() {}
|
||||
bool StatModel::empty() const { return !isTrained(); }
|
||||
|
||||
int StatModel::getVarCount() const { return 0; }
|
||||
|
||||
@@ -111,15 +111,6 @@ float StatModel::calcError( const Ptr<TrainData>& data, bool testerr, OutputArra
|
||||
return (float)(err / n * (isclassifier ? 100 : 1));
|
||||
}
|
||||
|
||||
void StatModel::save(const String& filename) const
|
||||
{
|
||||
FileStorage fs(filename, FileStorage::WRITE);
|
||||
fs << getDefaultModelName() << "{";
|
||||
fs << "format" << (int)3;
|
||||
write(fs);
|
||||
fs << "}";
|
||||
}
|
||||
|
||||
/* Calculates upper triangular matrix S, where A is a symmetrical matrix A=S'*S */
|
||||
static void Cholesky( const Mat& A, Mat& S )
|
||||
{
|
||||
|
||||
@@ -496,7 +496,7 @@ public:
|
||||
return impl->train(data, flags);
|
||||
}
|
||||
|
||||
String getDefaultModelName() const { return impl->getModelName(); }
|
||||
String getDefaultName() const { return impl->getModelName(); }
|
||||
|
||||
protected:
|
||||
void initImpl(int algorithmType)
|
||||
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
virtual int getVarCount() const { return learnt_thetas.cols; }
|
||||
virtual bool isTrained() const { return !learnt_thetas.empty(); }
|
||||
virtual bool isClassifier() const { return true; }
|
||||
virtual String getDefaultModelName() const { return "opencv_ml_lr"; }
|
||||
virtual String getDefaultName() const { return "opencv_ml_lr"; }
|
||||
protected:
|
||||
Mat calc_sigmoid(const Mat& data) const;
|
||||
double compute_cost(const Mat& _data, const Mat& _labels, const Mat& _init_theta);
|
||||
|
||||
@@ -443,7 +443,7 @@ public:
|
||||
bool isTrained() const { return !avg.empty(); }
|
||||
bool isClassifier() const { return true; }
|
||||
int getVarCount() const { return nallvars; }
|
||||
String getDefaultModelName() const { return "opencv_ml_nbayes"; }
|
||||
String getDefaultName() const { return "opencv_ml_nbayes"; }
|
||||
|
||||
int nallvars;
|
||||
Mat var_idx, cls_labels, c;
|
||||
|
||||
@@ -290,7 +290,7 @@ namespace ml
|
||||
virtual ~DTreesImpl();
|
||||
virtual void clear();
|
||||
|
||||
String getDefaultModelName() const { return "opencv_ml_dtree"; }
|
||||
String getDefaultName() const { return "opencv_ml_dtree"; }
|
||||
bool isTrained() const { return !roots.empty(); }
|
||||
bool isClassifier() const { return _isClassifier; }
|
||||
int getVarCount() const { return varType.empty() ? 0 : (int)(varType.size() - 1); }
|
||||
|
||||
@@ -375,7 +375,7 @@ public:
|
||||
RTreesImpl() {}
|
||||
virtual ~RTreesImpl() {}
|
||||
|
||||
String getDefaultModelName() const { return "opencv_ml_rtrees"; }
|
||||
String getDefaultName() const { return "opencv_ml_rtrees"; }
|
||||
|
||||
bool train( const Ptr<TrainData>& trainData, int flags )
|
||||
{
|
||||
|
||||
@@ -2008,7 +2008,7 @@ public:
|
||||
return var_count;
|
||||
}
|
||||
|
||||
String getDefaultModelName() const
|
||||
String getDefaultName() const
|
||||
{
|
||||
return "opencv_ml_svm";
|
||||
}
|
||||
|
||||
@@ -576,7 +576,7 @@ protected:
|
||||
// Read in
|
||||
try
|
||||
{
|
||||
em = StatModel::load<EM>(filename);
|
||||
em = Algorithm::load<EM>(filename);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
|
||||
@@ -179,7 +179,7 @@ void CV_LRTest_SaveLoad::run( int /*start_from*/ )
|
||||
// and load to another
|
||||
try
|
||||
{
|
||||
Ptr<LogisticRegression> lr2 = StatModel::load<LogisticRegression>(filename);
|
||||
Ptr<LogisticRegression> lr2 = Algorithm::load<LogisticRegression>(filename);
|
||||
lr2->predict(tdata->getSamples(), responses2);
|
||||
learnt_mat2 = lr2->get_learnt_thetas();
|
||||
}
|
||||
|
||||
@@ -472,19 +472,19 @@ void CV_MLBaseTest::save( const char* filename )
|
||||
void CV_MLBaseTest::load( const char* filename )
|
||||
{
|
||||
if( modelName == CV_NBAYES )
|
||||
model = StatModel::load<NormalBayesClassifier>( filename );
|
||||
model = Algorithm::load<NormalBayesClassifier>( filename );
|
||||
else if( modelName == CV_KNEAREST )
|
||||
model = StatModel::load<KNearest>( filename );
|
||||
model = Algorithm::load<KNearest>( filename );
|
||||
else if( modelName == CV_SVM )
|
||||
model = StatModel::load<SVM>( filename );
|
||||
model = Algorithm::load<SVM>( filename );
|
||||
else if( modelName == CV_ANN )
|
||||
model = StatModel::load<ANN_MLP>( filename );
|
||||
model = Algorithm::load<ANN_MLP>( filename );
|
||||
else if( modelName == CV_DTREE )
|
||||
model = StatModel::load<DTrees>( filename );
|
||||
model = Algorithm::load<DTrees>( filename );
|
||||
else if( modelName == CV_BOOST )
|
||||
model = StatModel::load<Boost>( filename );
|
||||
model = Algorithm::load<Boost>( filename );
|
||||
else if( modelName == CV_RTREES )
|
||||
model = StatModel::load<RTrees>( filename );
|
||||
model = Algorithm::load<RTrees>( filename );
|
||||
else
|
||||
CV_Error( CV_StsNotImplemented, "invalid stat model name");
|
||||
}
|
||||
|
||||
@@ -190,17 +190,17 @@ protected:
|
||||
bool isTree = modelName == CV_BOOST || modelName == CV_DTREE || modelName == CV_RTREES;
|
||||
Ptr<StatModel> model;
|
||||
if (modelName == CV_BOOST)
|
||||
model = StatModel::load<Boost>(filename);
|
||||
model = Algorithm::load<Boost>(filename);
|
||||
else if (modelName == CV_ANN)
|
||||
model = StatModel::load<ANN_MLP>(filename);
|
||||
model = Algorithm::load<ANN_MLP>(filename);
|
||||
else if (modelName == CV_DTREE)
|
||||
model = StatModel::load<DTrees>(filename);
|
||||
model = Algorithm::load<DTrees>(filename);
|
||||
else if (modelName == CV_NBAYES)
|
||||
model = StatModel::load<NormalBayesClassifier>(filename);
|
||||
model = Algorithm::load<NormalBayesClassifier>(filename);
|
||||
else if (modelName == CV_SVM)
|
||||
model = StatModel::load<SVM>(filename);
|
||||
model = Algorithm::load<SVM>(filename);
|
||||
else if (modelName == CV_RTREES)
|
||||
model = StatModel::load<RTrees>(filename);
|
||||
model = Algorithm::load<RTrees>(filename);
|
||||
if (!model)
|
||||
{
|
||||
code = cvtest::TS::FAIL_INVALID_TEST_DATA;
|
||||
@@ -273,11 +273,11 @@ TEST(DISABLED_ML_SVM, linear_save_load)
|
||||
{
|
||||
Ptr<cv::ml::SVM> svm1, svm2, svm3;
|
||||
|
||||
svm1 = StatModel::load<SVM>("SVM45_X_38-1.xml");
|
||||
svm2 = StatModel::load<SVM>("SVM45_X_38-2.xml");
|
||||
svm1 = Algorithm::load<SVM>("SVM45_X_38-1.xml");
|
||||
svm2 = Algorithm::load<SVM>("SVM45_X_38-2.xml");
|
||||
string tname = tempfile("a.xml");
|
||||
svm2->save(tname);
|
||||
svm3 = StatModel::load<SVM>(tname);
|
||||
svm3 = Algorithm::load<SVM>(tname);
|
||||
|
||||
ASSERT_EQ(svm1->getVarCount(), svm2->getVarCount());
|
||||
ASSERT_EQ(svm1->getVarCount(), svm3->getVarCount());
|
||||
|
||||
@@ -106,6 +106,8 @@ protected:
|
||||
class CV_EXPORTS VoronoiSeamFinder : public PairwiseSeamFinder
|
||||
{
|
||||
public:
|
||||
virtual void find(const std::vector<UMat> &src, const std::vector<Point> &corners,
|
||||
std::vector<UMat> &masks);
|
||||
virtual void find(const std::vector<Size> &size, const std::vector<Point> &corners,
|
||||
std::vector<UMat> &masks);
|
||||
private:
|
||||
|
||||
@@ -186,14 +186,18 @@ public:
|
||||
*/
|
||||
PlaneWarper(float scale = 1.f) { projector_.scale = scale; }
|
||||
|
||||
Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R);
|
||||
Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R, InputArray T);
|
||||
|
||||
virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap);
|
||||
Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap);
|
||||
|
||||
Point warp(InputArray src, InputArray K, InputArray R,
|
||||
int interp_mode, int border_mode, OutputArray dst);
|
||||
virtual Point warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode,
|
||||
OutputArray dst);
|
||||
|
||||
Rect warpRoi(Size src_size, InputArray K, InputArray R);
|
||||
Rect warpRoi(Size src_size, InputArray K, InputArray R, InputArray T);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -82,6 +82,11 @@ void PairwiseSeamFinder::run()
|
||||
}
|
||||
}
|
||||
|
||||
void VoronoiSeamFinder::find(const std::vector<UMat> &src, const std::vector<Point> &corners,
|
||||
std::vector<UMat> &masks)
|
||||
{
|
||||
PairwiseSeamFinder::find(src, corners, masks);
|
||||
}
|
||||
|
||||
void VoronoiSeamFinder::find(const std::vector<Size> &sizes, const std::vector<Point> &corners,
|
||||
std::vector<UMat> &masks)
|
||||
|
||||
@@ -87,6 +87,13 @@ Point2f PlaneWarper::warpPoint(const Point2f &pt, InputArray K, InputArray R, In
|
||||
return uv;
|
||||
}
|
||||
|
||||
Point2f PlaneWarper::warpPoint(const Point2f &pt, InputArray K, InputArray R)
|
||||
{
|
||||
float tz[] = {0.f, 0.f, 0.f};
|
||||
Mat_<float> T(3, 1, tz);
|
||||
return warpPoint(pt, K, R, T);
|
||||
}
|
||||
|
||||
Rect PlaneWarper::buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap)
|
||||
{
|
||||
return buildMaps(src_size, K, R, Mat::zeros(3, 1, CV_32FC1), xmap, ymap);
|
||||
@@ -155,6 +162,13 @@ Point PlaneWarper::warp(InputArray src, InputArray K, InputArray R, InputArray T
|
||||
return dst_roi.tl();
|
||||
}
|
||||
|
||||
Point PlaneWarper::warp(InputArray src, InputArray K, InputArray R,
|
||||
int interp_mode, int border_mode, OutputArray dst)
|
||||
{
|
||||
float tz[] = {0.f, 0.f, 0.f};
|
||||
Mat_<float> T(3, 1, tz);
|
||||
return warp(src, K, R, T, interp_mode, border_mode, dst);
|
||||
}
|
||||
|
||||
Rect PlaneWarper::warpRoi(Size src_size, InputArray K, InputArray R, InputArray T)
|
||||
{
|
||||
@@ -166,6 +180,13 @@ Rect PlaneWarper::warpRoi(Size src_size, InputArray K, InputArray R, InputArray
|
||||
return Rect(dst_tl, Point(dst_br.x + 1, dst_br.y + 1));
|
||||
}
|
||||
|
||||
Rect PlaneWarper::warpRoi(Size src_size, InputArray K, InputArray R)
|
||||
{
|
||||
float tz[] = {0.f, 0.f, 0.f};
|
||||
Mat_<float> T(3, 1, tz);
|
||||
return warpRoi(src_size, K, R, T);
|
||||
}
|
||||
|
||||
|
||||
void PlaneWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br)
|
||||
{
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace
|
||||
|
||||
void Farneback::impl(InputArray input0, InputArray input1, OutputArray dst)
|
||||
{
|
||||
calcOpticalFlowFarneback(input0, input1, (InputOutputArray)dst, pyrScale_,
|
||||
calcOpticalFlowFarneback(input0, input1, InputOutputArray(dst), pyrScale_,
|
||||
numLevels_, winSize_, numIters_,
|
||||
polyN_, polySigma_, flags_);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user