Commit 91443f791f582403fbd9473ff2ca87a94a6bf0ec

Authored by Josh Klontz
1 parent 46bec4cc

added initial xml format

Showing 1 changed file with 49 additions and 0 deletions
sdk/plugins/format.cpp
... ... @@ -17,6 +17,7 @@
17 17 #ifndef BR_EMBEDDED
18 18 #include <QNetworkAccessManager>
19 19 #include <QNetworkReply>
  20 +#include <QtXml>
20 21 #endif // BR_EMBEDDED
21 22 #include <opencv2/highgui/highgui.hpp>
22 23 #include <openbr_plugin.h>
... ... @@ -134,4 +135,52 @@ class webcamFormat : public Format
134 135  
135 136 BR_REGISTER(Format, webcamFormat)
136 137  
  138 +#ifndef BR_EMBEDDED
  139 +/*!
  140 + * \ingroup formats
  141 + * \brief Decodes images from Base64 xml
  142 + * \author Scott Klum \cite sklum
  143 + * \author Josh Klontz \cite jklontz
  144 + */
  145 +class xmlFormat : public Format
  146 +{
  147 + Q_OBJECT
  148 +
  149 + QList<Mat> read() const
  150 + {
  151 + QDomDocument doc(file);
  152 + QFile f(file);
  153 + bool success;
  154 + success = f.open(QIODevice::ReadOnly); if (!success) qFatal("xmlFormat::read unable to open %s for reading.", qPrintable(file));
  155 + success = doc.setContent(&f); if (!success) qFatal("xmlFormat::read unable to parse %s.", qPrintable(file));
  156 + f.close();
  157 +
  158 + QList<Mat> mats;
  159 + QDomElement docElem = doc.documentElement();
  160 + QDomNode subject = docElem.firstChild();
  161 + while (!subject.isNull()) {
  162 + QDomNode fileNode = subject.firstChild();
  163 +
  164 + while (!fileNode.isNull()) {
  165 + QDomElement e = fileNode.toElement();
  166 +
  167 + if (e.tagName() == "FORMAL_IMG") {
  168 + QByteArray byteArray = QByteArray::fromBase64(qPrintable(e.text()));
  169 + Mat m = imdecode(Mat(1, byteArray.size(), CV_8UC1, byteArray.data()), CV_LOAD_IMAGE_ANYDEPTH);
  170 + if (!m.data) qWarning("xmlFormat::read failed to decode image data.");
  171 + mats.append(m);
  172 + }
  173 +
  174 + fileNode = fileNode.nextSibling();
  175 + }
  176 + subject = subject.nextSibling();
  177 + }
  178 +
  179 + return mats;
  180 + }
  181 +};
  182 +
  183 +BR_REGISTER(Format, xmlFormat)
  184 +#endif // BR_EMBEDDED
  185 +
137 186 #include "format.moc"
... ...