mr_georg
mr_georg

Reputation: 3713

How can I read from an XML-string in OpenCV?

I know how to load/save a cv::Mat instance into a XML-file (See this question).

But what I really need, is to parse a std::string (or char *) that contains the XML, and get the cv::Mat. Say I get the XML out of a database, and not from a file.

Is that possible?

Upvotes: 13

Views: 7479

Answers (1)

Andrey Kamaev
Andrey Kamaev

Reputation: 30142

You can do it since OpenCV 2.4.1.

Here is a code sample from release notes:

//==== storing data ====
FileStorage fs(".xml", FileStorage::WRITE + FileStorage::MEMORY);
fs << "date" << date_string << "mymatrix" << mymatrix;
string buf = fs.releaseAndGetString();

//==== reading it back ====
FileStorage fs(buf, FileStorage::READ + FileStorage::MEMORY);
fs["date"] >> date_string;
fs["mymatrix"] >> mymatrix;

Upvotes: 19

Related Questions