diff --git a/modules/ml/include/opencv2/ml.hpp b/modules/ml/include/opencv2/ml.hpp index 862f3f950c..7acce7f33c 100644 --- a/modules/ml/include/opencv2/ml.hpp +++ b/modules/ml/include/opencv2/ml.hpp @@ -719,6 +719,15 @@ public: Use StatModel::train to train the model. Since %SVM has several parameters, you may want to find the best parameters for your problem, it can be done with SVM::trainAuto. */ CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized svm from a file + * + * Use SVM::save to serialize and store an SVM to disk. + * Load the SVM from this file again, by calling this function with the path to the file. + * + * @param filepath path to serialized svm + */ + CV_WRAP static Ptr load(const String& filepath); }; /****************************************************************************************\ @@ -1389,6 +1398,16 @@ public: Note that the train method has optional flags: ANN_MLP::TrainFlags. */ CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized ANN from a file + * + * Use ANN::save to serialize and store an ANN to disk. + * Load the ANN from this file again, by calling this function with the path to the file. + * + * @param filepath path to serialized ANN + */ + CV_WRAP static Ptr load(const String& filepath); + }; /****************************************************************************************\ diff --git a/modules/ml/src/ann_mlp.cpp b/modules/ml/src/ann_mlp.cpp index ff6512dedd..19ee913320 100644 --- a/modules/ml/src/ann_mlp.cpp +++ b/modules/ml/src/ann_mlp.cpp @@ -1317,6 +1317,18 @@ Ptr ANN_MLP::create() return makePtr(); } -}} +Ptr ANN_MLP::load(const String& filepath) +{ + FileStorage fs; + fs.open(filepath, FileStorage::READ); + + Ptr ann = makePtr(); + + ((ANN_MLPImpl*)ann.get())->read(fs.getFirstTopLevelNode()); + return ann; +} + + + }} /* End of file. */ diff --git a/modules/ml/src/svm.cpp b/modules/ml/src/svm.cpp index 757bb7a171..34acebb991 100644 --- a/modules/ml/src/svm.cpp +++ b/modules/ml/src/svm.cpp @@ -2261,6 +2261,17 @@ Ptr SVM::create() return makePtr(); } +Ptr SVM::load(const String& filepath) +{ + FileStorage fs; + fs.open(filepath, FileStorage::READ); + + Ptr svm = makePtr(); + + ((SVMImpl*)svm.get())->read(fs.getFirstTopLevelNode()); + return svm; +} + Mat SVM::getUncompressedSupportVectors() const { const SVMImpl* this_ = dynamic_cast(this);