From b8f04b8bfc410dc3604c6df19d32a98613a2bb30 Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Sun, 13 Jan 2013 11:09:15 -0500 Subject: [PATCH] Generalized br::Format to read a template --- sdk/openbr_plugin.h | 6 +++--- sdk/plugins/format.cpp | 34 +++++++++++++++------------------- sdk/plugins/misc.cpp | 15 ++++++--------- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/sdk/openbr_plugin.h b/sdk/openbr_plugin.h index 603320c..f3e28e1 100644 --- a/sdk/openbr_plugin.h +++ b/sdk/openbr_plugin.h @@ -821,9 +821,9 @@ private: /*! * \ingroup formats - * \brief Plugin base class for reading matrices from disk. + * \brief Plugin base class for reading a template from disk. * - * A \em format is a br::File representing a matrix (ex. jpg image) on disk. + * A \em format is a br::File representing a template (ex. jpg image) on disk. * br::File::suffix() is used to determine which plugin should handle the format. */ class BR_EXPORT Format : public Object @@ -832,7 +832,7 @@ class BR_EXPORT Format : public Object public: virtual ~Format() {} - virtual QList read() const = 0; /*!< \brief Returns a list of matrices created by reading #br::Object::file. */ + virtual Template read() const = 0; /*!< \brief Returns a br::Template created by reading #br::Object::file. */ }; /*! diff --git a/sdk/plugins/format.cpp b/sdk/plugins/format.cpp index 5899f7c..72e2416 100644 --- a/sdk/plugins/format.cpp +++ b/sdk/plugins/format.cpp @@ -34,7 +34,7 @@ class csvFormat : public Format { Q_OBJECT - QList read() const + Template read() const { QFile f(file.name); f.open(QFile::ReadOnly); @@ -60,9 +60,7 @@ class csvFormat : public Format } } - QList mats; - mats.append(m); - return mats; + return Template(m); } }; @@ -77,9 +75,9 @@ class DefaultFormat : public Format { Q_OBJECT - QList read() const + Template read() const { - QList mats; + Template t; if (file.name.startsWith("http://") || file.name.startsWith("www.")) { #ifndef BR_EMBEDDED @@ -95,16 +93,16 @@ class DefaultFormat : public Format delete reply; Mat m = imdecode(Mat(1, data.size(), CV_8UC1, data.data()), 1); - if (m.data) mats.append(m); + if (m.data) t.append(m); #endif // BR_EMBEDDED } else { QString prefix = ""; if (!QFileInfo(file.name).exists()) prefix = file.getString("path") + "/"; Mat m = imread((prefix+file.name).toStdString()); - if (m.data) mats.append(m); + if (m.data) t.append(m); } - return mats; + return t; } }; @@ -119,7 +117,7 @@ class webcamFormat : public Format { Q_OBJECT - QList read() const + Template read() const { static QScopedPointer videoCapture; @@ -128,8 +126,7 @@ class webcamFormat : public Format Mat m; videoCapture->read(m); - - return QList() << m; + return Template(m); } }; @@ -146,16 +143,15 @@ class xmlFormat : public Format { Q_OBJECT - QList read() const + Template 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)); + if (!f.open(QIODevice::ReadOnly)) qFatal("xmlFormat::read unable to open %s for reading.", qPrintable(file.flat())); + if (!doc.setContent(&f)) qFatal("xmlFormat::read unable to parse %s.", qPrintable(file.flat())); f.close(); - QList mats; + Template t; QDomElement docElem = doc.documentElement(); QDomNode subject = docElem.firstChild(); while (!subject.isNull()) { @@ -168,7 +164,7 @@ class xmlFormat : public Format 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); + t.append(m); } fileNode = fileNode.nextSibling(); @@ -176,7 +172,7 @@ class xmlFormat : public Format subject = subject.nextSibling(); } - return mats; + return t; } }; diff --git a/sdk/plugins/misc.cpp b/sdk/plugins/misc.cpp index c480680..392c006 100644 --- a/sdk/plugins/misc.cpp +++ b/sdk/plugins/misc.cpp @@ -34,18 +34,15 @@ class OpenTransform : public UntrainableMetaTransform void project(const Template &src, Template &dst) const { if (Globals->verbose) qDebug("Opening %s", qPrintable(src.file.flat())); - bool fto = false; + dst.file = src.file; foreach (const File &file, src.file.split()) { QScopedPointer format(Factory::make(file)); - QList mats = format->read(); - if (mats.isEmpty()) { - qWarning("Can't open %s", qPrintable(file.flat())); - fto = true; - } - dst += mats; + Template t = format->read(); + if (t.isEmpty()) qWarning("Can't open %s", qPrintable(file.flat())); + dst.append(t); + dst.file.append(t.file.localMetadata()); } - dst.file = src.file; - dst.file.insert("FTO", fto); + dst.file.insert("FTO", dst.isEmpty()); } }; -- libgit2 0.21.4