如何从OpenCV中的XML字符串中读取? [英] How can I read from an XML-string in OpenCV?

查看:174
本文介绍了如何从OpenCV中的XML字符串中读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何将 cv :: Mat 实例加载/保存到XML文件中(请参阅 this question )。



但我真正需要的是解析一个 std :: string (或 char * )包含XML,并获得 cv :: Mat 。说我从数据库中获取XML,而不是从文件中获取。



这是否可能?



这是一个来自发布说明

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

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


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?

解决方案

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;

这篇关于如何从OpenCV中的XML字符串中读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆