added wrapped load function for python as suggested by gat3way
authorChristoph Spörk <spoerk@cogvis.at>
Mon, 11 Jan 2016 09:59:15 +0000 (10:59 +0100)
committerChristoph Spörk <spoerk@cogvis.at>
Mon, 11 Jan 2016 09:59:15 +0000 (10:59 +0100)
modules/ml/include/opencv2/ml.hpp
modules/ml/src/ann_mlp.cpp

index 4f99bf4..7acce7f 100644 (file)
@@ -1398,6 +1398,16 @@ public:
     Note that the train method has optional flags: ANN_MLP::TrainFlags.
      */
     CV_WRAP static Ptr<ANN_MLP> 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<ANN_MLP> load(const String& filepath);
+
 };
 
 /****************************************************************************************\
index ff6512d..19ee913 100644 (file)
@@ -1317,6 +1317,18 @@ Ptr<ANN_MLP> ANN_MLP::create()
     return makePtr<ANN_MLPImpl>();
 }
 
-}}
+Ptr<ANN_MLP> ANN_MLP::load(const String& filepath)
+{
+    FileStorage fs;
+    fs.open(filepath, FileStorage::READ);
+
+    Ptr<ANN_MLP> ann = makePtr<ANN_MLPImpl>();
+
+    ((ANN_MLPImpl*)ann.get())->read(fs.getFirstTopLevelNode());
+    return ann;
+}
+
+
+    }}
 
 /* End of file. */