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,9 +821,9 @@ private:
821 821
822 /*! 822 /*!
823 * \ingroup formats 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 * br::File::suffix() is used to determine which plugin should handle the format. 827 * br::File::suffix() is used to determine which plugin should handle the format.
828 */ 828 */
829 class BR_EXPORT Format : public Object 829 class BR_EXPORT Format : public Object
@@ -832,7 +832,7 @@ class BR_EXPORT Format : public Object @@ -832,7 +832,7 @@ class BR_EXPORT Format : public Object
832 832
833 public: 833 public:
834 virtual ~Format() {} 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,7 +34,7 @@ class csvFormat : public Format
34 { 34 {
35 Q_OBJECT 35 Q_OBJECT
36 36
37 - QList<Mat> read() const 37 + Template read() const
38 { 38 {
39 QFile f(file.name); 39 QFile f(file.name);
40 f.open(QFile::ReadOnly); 40 f.open(QFile::ReadOnly);
@@ -60,9 +60,7 @@ class csvFormat : public Format @@ -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,9 +75,9 @@ class DefaultFormat : public Format
77 { 75 {
78 Q_OBJECT 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 if (file.name.startsWith("http://") || file.name.startsWith("www.")) { 82 if (file.name.startsWith("http://") || file.name.startsWith("www.")) {
85 #ifndef BR_EMBEDDED 83 #ifndef BR_EMBEDDED
@@ -95,16 +93,16 @@ class DefaultFormat : public Format @@ -95,16 +93,16 @@ class DefaultFormat : public Format
95 delete reply; 93 delete reply;
96 94
97 Mat m = imdecode(Mat(1, data.size(), CV_8UC1, data.data()), 1); 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 #endif // BR_EMBEDDED 97 #endif // BR_EMBEDDED
100 } else { 98 } else {
101 QString prefix = ""; 99 QString prefix = "";
102 if (!QFileInfo(file.name).exists()) prefix = file.getString("path") + "/"; 100 if (!QFileInfo(file.name).exists()) prefix = file.getString("path") + "/";
103 Mat m = imread((prefix+file.name).toStdString()); 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,7 +117,7 @@ class webcamFormat : public Format
119 { 117 {
120 Q_OBJECT 118 Q_OBJECT
121 119
122 - QList<Mat> read() const 120 + Template read() const
123 { 121 {
124 static QScopedPointer<VideoCapture> videoCapture; 122 static QScopedPointer<VideoCapture> videoCapture;
125 123
@@ -128,8 +126,7 @@ class webcamFormat : public Format @@ -128,8 +126,7 @@ class webcamFormat : public Format
128 126
129 Mat m; 127 Mat m;
130 videoCapture->read(m); 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,16 +143,15 @@ class xmlFormat : public Format
146 { 143 {
147 Q_OBJECT 144 Q_OBJECT
148 145
149 - QList<Mat> read() const 146 + Template read() const
150 { 147 {
151 QDomDocument doc(file); 148 QDomDocument doc(file);
152 QFile f(file); 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 f.close(); 152 f.close();
157 153
158 - QList<Mat> mats; 154 + Template t;
159 QDomElement docElem = doc.documentElement(); 155 QDomElement docElem = doc.documentElement();
160 QDomNode subject = docElem.firstChild(); 156 QDomNode subject = docElem.firstChild();
161 while (!subject.isNull()) { 157 while (!subject.isNull()) {
@@ -168,7 +164,7 @@ class xmlFormat : public Format @@ -168,7 +164,7 @@ class xmlFormat : public Format
168 QByteArray byteArray = QByteArray::fromBase64(qPrintable(e.text())); 164 QByteArray byteArray = QByteArray::fromBase64(qPrintable(e.text()));
169 Mat m = imdecode(Mat(1, byteArray.size(), CV_8UC1, byteArray.data()), CV_LOAD_IMAGE_ANYDEPTH); 165 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."); 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 fileNode = fileNode.nextSibling(); 170 fileNode = fileNode.nextSibling();
@@ -176,7 +172,7 @@ class xmlFormat : public Format @@ -176,7 +172,7 @@ class xmlFormat : public Format
176 subject = subject.nextSibling(); 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,18 +34,15 @@ class OpenTransform : public UntrainableMetaTransform
34 void project(const Template &src, Template &dst) const 34 void project(const Template &src, Template &dst) const
35 { 35 {
36 if (Globals->verbose) qDebug("Opening %s", qPrintable(src.file.flat())); 36 if (Globals->verbose) qDebug("Opening %s", qPrintable(src.file.flat()));
37 - bool fto = false; 37 + dst.file = src.file;
38 foreach (const File &file, src.file.split()) { 38 foreach (const File &file, src.file.split()) {
39 QScopedPointer<Format> format(Factory<Format>::make(file)); 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