Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8488253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:28:51+00:00 2026-06-10T21:28:51+00:00

I am trying to read the parameters of a trained Expectation Maximation model from

  • 0

I am trying to read the parameters of a trained Expectation Maximation model from an XML file for later use. In order to store the model I call

cv::FileStorage fs("model.xml",cv::FileStorage::WRITE);
classifier.write(fs);  //classifier is of type cv::EM

this creates the file containing what looks like the data of the model. Here is what the files looks like (first few lines from the start):

StatModel.EM 1
<_ type_id="opencv-matrix"> 3 3 d
1.2159868951764311e+01 0. 0. 0. 1.9776824566023249e-01 0. 0. 0.  .2204460492503131e-16     
<_ type_id="opencv-matrix"> 3 3 d
3.2869203526862529e+00 0. 0. 0. 1.1631692248472096e+00 0. 0. 0. 2.2204460492503131e-16     
<_ type_id="opencv-matrix"> 3 3 d
2.9815870012055705e+00 0. 0. 0. 6.5049770685681069e+03 0. 0. 0. 6.8510191786605528e+03 
<_ type_id="opencv-matrix"> 3 3 d 
4.6608996548002040e+00 0. 0. 0. 3.7558131457318683e+02 0. 0. 0. 2.2204460492503131e-16 

Note, that the XML header is missing. Now in order to read the data I am using

cv::FileStorage fs("model.xml",cv::FileStorage::READ);

the cv::Algorithm::read() function has to be called with a filenode as parameter. I am not sure what node to use. Since I would expect there to be only one node in the file I tried

classifier.read(fs[0]);

But the algorithm is not trained afterwards. What do I need to do in order to restore the original parameters?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:28:52+00:00Added an answer on June 10, 2026 at 9:28 pm

    Instead, of using ‘write’ you can do:

    fs<<"my_model"<<classifier;
    

    and then after you open a FileStorage for reading, read it like that:

    cv::EM EModel;
    fs["my_model"] >> EModel;
    

    EDIT: The above will not work with cv::EM since it is not included in the overloads.

    This link provides a very good example about how you write and read a custom class to/from an XML/YAML file. According to that, you create the “write” and “read” methods for your class, so you are the one who defines and names the nodes.

    If you haven’t written those methods yourself and they are part of cv::Algorithm (probably this is new, I couldn’t find it in 2.2 that I am using) , then I would suggest to check the xml file to see the names of the nodes that were created and then get them either using the >> operator or doing:

    FileNode myFilenode = fs["node_name"];
    classifier.read(myFilenode);
    

    From the StatModel.EM 1 <_ type_id="opencv-matrix"> that you provide and the xml example in the link, I would guess that this node’s name is actually “_” (maybe this is the default if you don’t provide any name when you write it)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read variables from a batch file for later use in the
I'm trying to read an object from a XML file using XMLDecoder. The construction
I'm trying to read the version of an xml file: <Order xsi:schemaLocation=urn:schemas-basda-org:2000:purchaseOrder:xdr:3.01 order-v3.xsd urn:schemas-bossfed-co-uk:OP-Order-v1
I am trying to read the post request parameters from my HTML. I can
I am trying to read in an XML file that I have saved to
I am trying to read some XML code from a website, and am having
I'm trying to read UTF-8 from a text file and do some tokenization, but
i am trying to read the xml file but somehow i am getting this
I'm trying to use an after_commit method to pass parameters from the post to
I am trying to use ADO to access and read some things from an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.