From a1e04c98aa40915b5da23544f7f99824b15ed8ce Mon Sep 17 00:00:00 2001 From: TobyWanKenobi Date: Tue, 2 Dec 2014 15:15:06 +0100 Subject: [PATCH] Add method in StatModel class, to load from String Added a method "loadFromString" which is based on the "load" one. It allow to directly pass the XML string which can be usefull and faster when you have a huge file in a variable. --- modules/ml/include/opencv2/ml.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/ml/include/opencv2/ml.hpp b/modules/ml/include/opencv2/ml.hpp index 5e633c4d0a..63a29c80e5 100644 --- a/modules/ml/include/opencv2/ml.hpp +++ b/modules/ml/include/opencv2/ml.hpp @@ -827,6 +827,22 @@ public: return model->isTrained() ? model : Ptr<_Tp>(); } + /** @brief Loads model from an XML String + + This is static template method of StatModel. It's usage is following (in the case of SVM): : + + Ptr svm = StatModel::loadFromString(myXMLStringModel); + + @param strModel The string variable containing the model (in an XML format) you want to load. + */ + template static Ptr<_Tp> loadFromString(const String& strModel) + { + FileStorage fs(strModel, FileStorage::READ + FileStorage::MEMORY + FileStorage::FORMAT_XML); + Ptr<_Tp> model = _Tp::create(); + model->read(fs.getFirstTopLevelNode()); + return model->isTrained() ? model : Ptr<_Tp>(); + } + template static Ptr<_Tp> train(const Ptr& data, const typename _Tp::Params& p, int flags=0) { Ptr<_Tp> model = _Tp::create(p); @@ -1511,6 +1527,7 @@ public: }; /** @brief The class represents a decision tree node. It has public members: + - member double value Value at the node: a class label in case of classification or estimated function value in case of regression.