Commit b8f04b8bfc410dc3604c6df19d32a98613a2bb30

Authored by Josh Klontz
1 parent dc0e2086

Generalized br::Format to read a template

sdk/openbr_plugin.h
... ... @@ -821,9 +821,9 @@ private:
821 821  
822 822 /*!
823 823 * \ingroup formats
824   - * \brief Plugin base class for reading matrices from disk.
  824 + * \brief Plugin base class for reading a template from disk.
825 825 *
826   - * A \em format is a br::File representing a matrix (ex. jpg image) on disk.
  826 + * A \em format is a br::File representing a template (ex. jpg image) on disk.
827 827 * br::File::suffix() is used to determine which plugin should handle the format.
828 828 */
829 829 class BR_EXPORT Format : public Object
... ... @@ -832,7 +832,7 @@ class BR_EXPORT Format : public Object
832 832  
833 833 public:
834 834 virtual ~Format() {}
835   - virtual QList<cv::Mat> read() const = 0; /*!< \brief Returns a list of matrices created by reading #br::Object::file. */
  835 + virtual Template read() const = 0; /*!< \brief Returns a br::Template created by reading #br::Object::file. */
836 836 };
837 837  
838 838 /*!
... ...
sdk/plugins/format.cpp
... ... @@ -34,7 +34,7 @@ class csvFormat : public Format
34 34 {
35 35 Q_OBJECT
36 36  
37   - QList<Mat> read() const
  37 + Template read() const
38 38 {
39 39 QFile f(file.name);
40 40 f.open(QFile::ReadOnly);
... ... @@ -60,9 +60,7 @@ class csvFormat : public Format
60 60 }
61 61 }
62 62  
63   - QList<Mat> mats;
64   - mats.append(m);
65   - return mats;
  63 + return Template(m);
66 64 }
67 65 };
68 66  
... ... @@ -77,9 +75,9 @@ class DefaultFormat : public Format
77 75 {
78 76 Q_OBJECT
79 77  
80   - QList<Mat> read() const
  78 + Template read() const
81 79 {
82   - QList<Mat> mats;
  80 + Template t;
83 81  
84 82 if (file.name.startsWith("http://") || file.name.startsWith("www.")) {
85 83 #ifndef BR_EMBEDDED
... ... @@ -95,16 +93,16 @@ class DefaultFormat : public Format
95 93 delete reply;
96 94  
97 95 Mat m = imdecode(Mat(1, data.size(), CV_8UC1, data.data()), 1);
98   - if (m.data) mats.append(m);
  96 + if (m.data) t.append(m);
99 97 #endif // BR_EMBEDDED
100 98 } else {
101 99 QString prefix = "";
102 100 if (!QFileInfo(file.name).exists()) prefix = file.getString("path") + "/";
103 101 Mat m = imread((prefix+file.name).toStdString());
104   - if (m.data) mats.append(m);
  102 + if (m.data) t.append(m);
105 103 }
106 104  
107   - return mats;
  105 + return t;
108 106 }
109 107 };
110 108  
... ... @@ -119,7 +117,7 @@ class webcamFormat : public Format
119 117 {
120 118 Q_OBJECT
121 119  
122   - QList<Mat> read() const
  120 + Template read() const
123 121 {
124 122 static QScopedPointer<VideoCapture> videoCapture;
125 123  
... ... @@ -128,8 +126,7 @@ class webcamFormat : public Format
128 126  
129 127 Mat m;
130 128 videoCapture->read(m);
131   -
132   - return QList<Mat>() << m;
  129 + return Template(m);
133 130 }
134 131 };
135 132  
... ... @@ -146,16 +143,15 @@ class xmlFormat : public Format
146 143 {
147 144 Q_OBJECT
148 145  
149   - QList<Mat> read() const
  146 + Template read() const
150 147 {
151 148 QDomDocument doc(file);
152 149 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));
  150 + if (!f.open(QIODevice::ReadOnly)) qFatal("xmlFormat::read unable to open %s for reading.", qPrintable(file.flat()));
  151 + if (!doc.setContent(&f)) qFatal("xmlFormat::read unable to parse %s.", qPrintable(file.flat()));
156 152 f.close();
157 153  
158   - QList<Mat> mats;
  154 + Template t;
159 155 QDomElement docElem = doc.documentElement();
160 156 QDomNode subject = docElem.firstChild();
161 157 while (!subject.isNull()) {
... ... @@ -168,7 +164,7 @@ class xmlFormat : public Format
168 164 QByteArray byteArray = QByteArray::fromBase64(qPrintable(e.text()));
169 165 Mat m = imdecode(Mat(1, byteArray.size(), CV_8UC1, byteArray.data()), CV_LOAD_IMAGE_ANYDEPTH);
170 166 if (!m.data) qWarning("xmlFormat::read failed to decode image data.");
171   - mats.append(m);
  167 + t.append(m);
172 168 }
173 169  
174 170 fileNode = fileNode.nextSibling();
... ... @@ -176,7 +172,7 @@ class xmlFormat : public Format
176 172 subject = subject.nextSibling();
177 173 }
178 174  
179   - return mats;
  175 + return t;
180 176 }
181 177 };
182 178  
... ...
sdk/plugins/misc.cpp
... ... @@ -34,18 +34,15 @@ class OpenTransform : public UntrainableMetaTransform
34 34 void project(const Template &src, Template &dst) const
35 35 {
36 36 if (Globals->verbose) qDebug("Opening %s", qPrintable(src.file.flat()));
37   - bool fto = false;
  37 + dst.file = src.file;
38 38 foreach (const File &file, src.file.split()) {
39 39 QScopedPointer<Format> format(Factory<Format>::make(file));
40   - QList<Mat> mats = format->read();
41   - if (mats.isEmpty()) {
42   - qWarning("Can't open %s", qPrintable(file.flat()));
43   - fto = true;
44   - }
45   - dst += mats;
  40 + Template t = format->read();
  41 + if (t.isEmpty()) qWarning("Can't open %s", qPrintable(file.flat()));
  42 + dst.append(t);
  43 + dst.file.append(t.file.localMetadata());
46 44 }
47   - dst.file = src.file;
48   - dst.file.insert("FTO", fto);
  45 + dst.file.insert("FTO", dst.isEmpty());
49 46 }
50 47 };
51 48  
... ...