From a1e04c98aa40915b5da23544f7f99824b15ed8ce Mon Sep 17 00:00:00 2001 From: TobyWanKenobi Date: Tue, 2 Dec 2014 15:15:06 +0100 Subject: [PATCH 1/5] 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. From 270af2ca7943e029104da5fce2e57f6c2cda789d Mon Sep 17 00:00:00 2001 From: TobyWanKenobi Date: Wed, 3 Dec 2014 15:40:12 +0100 Subject: [PATCH 2/5] Changing tabs to spaces. Edited previous code to change tabs into spaces. --- modules/ml/include/opencv2/ml.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/ml/include/opencv2/ml.hpp b/modules/ml/include/opencv2/ml.hpp index 63a29c80e5..598c5b1b1d 100644 --- a/modules/ml/include/opencv2/ml.hpp +++ b/modules/ml/include/opencv2/ml.hpp @@ -836,12 +836,12 @@ public: @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>(); - } + { + 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) { From b3bba3476da599ec2ec69bb1846eb268e8d20971 Mon Sep 17 00:00:00 2001 From: TobyWanKenobi Date: Wed, 3 Dec 2014 15:54:25 +0100 Subject: [PATCH 3/5] Re-editing Documentation Attempting to re-editing the documentation, to satisfy buildbot error status. --- modules/ml/include/opencv2/ml.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/ml/include/opencv2/ml.hpp b/modules/ml/include/opencv2/ml.hpp index 598c5b1b1d..060776224f 100644 --- a/modules/ml/include/opencv2/ml.hpp +++ b/modules/ml/include/opencv2/ml.hpp @@ -828,12 +828,11 @@ public: } /** @brief Loads model from an XML String + + @param strModel The string variable containing the model (in an XML format) you want to load. - This is static template method of StatModel. It's usage is following (in the case of SVM): : - + 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) { From f54b80d2c84bc825384d6e29bf38daba511d6a60 Mon Sep 17 00:00:00 2001 From: TobyWanKenobi Date: Wed, 3 Dec 2014 17:13:11 +0100 Subject: [PATCH 4/5] Re-edition of documentation Re-edited the documentation again. --- modules/ml/include/opencv2/ml.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/ml/include/opencv2/ml.hpp b/modules/ml/include/opencv2/ml.hpp index 060776224f..8e61c63a11 100644 --- a/modules/ml/include/opencv2/ml.hpp +++ b/modules/ml/include/opencv2/ml.hpp @@ -828,7 +828,6 @@ public: } /** @brief Loads model from an XML String - @param strModel The string variable containing the model (in an XML format) you want to load. This is static template method of StatModel. It's usage is following (in the case of SVM): @@ -841,7 +840,7 @@ public: 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); From b35f5d115fb8e06d012ca0313d4a133f2a48e587 Mon Sep 17 00:00:00 2001 From: TobyWanKenobi Date: Mon, 8 Dec 2014 09:21:55 +0100 Subject: [PATCH 5/5] Removed "FORMAT_XML" to generalize format Removed the "FileStorage::FORMAT_XML" to generalize format of the String model. --- modules/ml/include/opencv2/ml.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/ml/include/opencv2/ml.hpp b/modules/ml/include/opencv2/ml.hpp index 8e61c63a11..619664ba30 100644 --- a/modules/ml/include/opencv2/ml.hpp +++ b/modules/ml/include/opencv2/ml.hpp @@ -827,15 +827,15 @@ public: return model->isTrained() ? model : Ptr<_Tp>(); } - /** @brief Loads model from an XML String - @param strModel The string variable containing the model (in an XML format) you want to load. + /** @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): - Ptr svm = StatModel::loadFromString(myXMLStringModel); + Ptr svm = StatModel::loadFromString(myStringModel); */ template static Ptr<_Tp> loadFromString(const String& strModel) { - FileStorage fs(strModel, FileStorage::READ + FileStorage::MEMORY + FileStorage::FORMAT_XML); + FileStorage fs(strModel, FileStorage::READ + FileStorage::MEMORY); Ptr<_Tp> model = _Tp::create(); model->read(fs.getFirstTopLevelNode()); return model->isTrained() ? model : Ptr<_Tp>();