From 91443f791f582403fbd9473ff2ca87a94a6bf0ec Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Sun, 13 Jan 2013 10:35:19 -0500 Subject: [PATCH] added initial xml format --- sdk/plugins/format.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+), 0 deletions(-) diff --git a/sdk/plugins/format.cpp b/sdk/plugins/format.cpp index ab8960d..5899f7c 100644 --- a/sdk/plugins/format.cpp +++ b/sdk/plugins/format.cpp @@ -17,6 +17,7 @@ #ifndef BR_EMBEDDED #include #include +#include #endif // BR_EMBEDDED #include #include @@ -134,4 +135,52 @@ class webcamFormat : public Format BR_REGISTER(Format, webcamFormat) +#ifndef BR_EMBEDDED +/*! + * \ingroup formats + * \brief Decodes images from Base64 xml + * \author Scott Klum \cite sklum + * \author Josh Klontz \cite jklontz + */ +class xmlFormat : public Format +{ + Q_OBJECT + + QList read() const + { + QDomDocument doc(file); + QFile f(file); + bool success; + success = f.open(QIODevice::ReadOnly); if (!success) qFatal("xmlFormat::read unable to open %s for reading.", qPrintable(file)); + success = doc.setContent(&f); if (!success) qFatal("xmlFormat::read unable to parse %s.", qPrintable(file)); + f.close(); + + QList mats; + QDomElement docElem = doc.documentElement(); + QDomNode subject = docElem.firstChild(); + while (!subject.isNull()) { + QDomNode fileNode = subject.firstChild(); + + while (!fileNode.isNull()) { + QDomElement e = fileNode.toElement(); + + if (e.tagName() == "FORMAL_IMG") { + QByteArray byteArray = QByteArray::fromBase64(qPrintable(e.text())); + Mat m = imdecode(Mat(1, byteArray.size(), CV_8UC1, byteArray.data()), CV_LOAD_IMAGE_ANYDEPTH); + if (!m.data) qWarning("xmlFormat::read failed to decode image data."); + mats.append(m); + } + + fileNode = fileNode.nextSibling(); + } + subject = subject.nextSibling(); + } + + return mats; + } +}; + +BR_REGISTER(Format, xmlFormat) +#endif // BR_EMBEDDED + #include "format.moc" -- libgit2 0.21.4