c++ - Append element in xml file in opencv using cpp -


i trying append new element in opencv xml file has 1 element below

<?xml version="1.0"?> <opencv_storage> <acc type_id="opencv-ml-ann-mlp"> ... </_></weights></acc> </opencv_storage> 

i trying append 1 more element called micr below

<?xml version="1.0"?> <opencv_storage> <acc type_id="opencv-ml-ann-mlp"> ... </_></weights></acc>   <micr type_id="opencv-ml-ann-mlp"> ... </_></weights></micr> </opencv_storage> 

but getting is

<?xml version="1.0"?> <opencv_storage> <acc type_id="opencv-ml-ann-mlp"> ...   <micr type_id="opencv-ml-ann-mlp"> ... </_></weights></micr></_></weights></acc> </opencv_storage> 

i using cv::filestorage opencv.

i want know wrong ::append , if there alternative achieve this.

here's code:

cv::filestorage f("ocr.xml", cv::filestorage::write); ... ann.write(*f, "acc");    //in function ... f.release();  cv::filestorage f("ocr.xml", cv::filestorage::append); ... ann.write(*f, "micr");    //in function ... f.release(); 

thanks in advance!

please try snippet. seems work expected.

#include <opencv2/opencv.hpp> #include <vector> using namespace cv;  int main() {     mat layers = (mat1i(2,1) << 5, 15);     cvann_mlp ann(layers);      {         filestorage f("ocr.xml", filestorage::write);         ann.write(*f, "acc");     }     {         filestorage f("ocr.xml", filestorage::append);         ann.write(*f, "micr");     }      filestorage f("ocr.xml", filestorage::read);      cvann_mlp ann_acc;     ann_acc.read(*f, cvgetfilenodebyname(*f, null, "acc"));      cvann_mlp ann_micr;     ann_acc.read(*f, cvgetfilenodebyname(*f, null, "micr"));      return 0;      return 0; } 

see here shouldn't mix save/load write/read.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -