Commit 0ffe4ba6a0b0452509fd4ec3502055d80c30a225
1 parent
584e8718
added .ut universal_template gallery support
Showing
2 changed files
with
81 additions
and
21 deletions
openbr/plugins/gallery.cpp
| @@ -28,6 +28,7 @@ | @@ -28,6 +28,7 @@ | ||
| 28 | #include <opencv2/highgui/highgui.hpp> | 28 | #include <opencv2/highgui/highgui.hpp> |
| 29 | #include "openbr_internal.h" | 29 | #include "openbr_internal.h" |
| 30 | 30 | ||
| 31 | +#include "openbr/universal_template.h" | ||
| 31 | #include "openbr/core/bee.h" | 32 | #include "openbr/core/bee.h" |
| 32 | #include "openbr/core/common.h" | 33 | #include "openbr/core/common.h" |
| 33 | #include "openbr/core/opencvutils.h" | 34 | #include "openbr/core/opencvutils.h" |
| @@ -88,19 +89,9 @@ class arffGallery : public Gallery | @@ -88,19 +89,9 @@ class arffGallery : public Gallery | ||
| 88 | 89 | ||
| 89 | BR_REGISTER(Gallery, arffGallery) | 90 | BR_REGISTER(Gallery, arffGallery) |
| 90 | 91 | ||
| 91 | -/*! | ||
| 92 | - * \ingroup galleries | ||
| 93 | - * \brief A binary gallery. | ||
| 94 | - * | ||
| 95 | - * Designed to be a literal translation of templates to disk. | ||
| 96 | - * Compatible with TemplateList::fromBuffer. | ||
| 97 | - * \author Josh Klontz \cite jklontz | ||
| 98 | - */ | ||
| 99 | -class galGallery : public Gallery | 92 | +class BinaryGallery : public Gallery |
| 100 | { | 93 | { |
| 101 | Q_OBJECT | 94 | Q_OBJECT |
| 102 | - QFile gallery; | ||
| 103 | - QDataStream stream; | ||
| 104 | 95 | ||
| 105 | void init() | 96 | void init() |
| 106 | { | 97 | { |
| @@ -125,9 +116,7 @@ class galGallery : public Gallery | @@ -125,9 +116,7 @@ class galGallery : public Gallery | ||
| 125 | 116 | ||
| 126 | TemplateList templates; | 117 | TemplateList templates; |
| 127 | while ((templates.size() < readBlockSize) && !stream.atEnd()) { | 118 | while ((templates.size() < readBlockSize) && !stream.atEnd()) { |
| 128 | - Template m; | ||
| 129 | - stream >> m; | ||
| 130 | - templates.append(m); | 119 | + templates.append(readTemplate()); |
| 131 | templates.last().file.set("progress", totalSize()); | 120 | templates.last().file.set("progress", totalSize()); |
| 132 | } | 121 | } |
| 133 | 122 | ||
| @@ -135,13 +124,9 @@ class galGallery : public Gallery | @@ -135,13 +124,9 @@ class galGallery : public Gallery | ||
| 135 | return templates; | 124 | return templates; |
| 136 | } | 125 | } |
| 137 | 126 | ||
| 138 | - void write(const Template &t) | ||
| 139 | - { | ||
| 140 | - if (t.isEmpty() && t.file.isNull()) | ||
| 141 | - return; | ||
| 142 | - | ||
| 143 | - stream << t; | ||
| 144 | - } | 127 | +protected: |
| 128 | + QFile gallery; | ||
| 129 | + QDataStream stream; | ||
| 145 | 130 | ||
| 146 | qint64 totalSize() | 131 | qint64 totalSize() |
| 147 | { | 132 | { |
| @@ -153,12 +138,70 @@ class galGallery : public Gallery | @@ -153,12 +138,70 @@ class galGallery : public Gallery | ||
| 153 | return gallery.pos(); | 138 | return gallery.pos(); |
| 154 | } | 139 | } |
| 155 | 140 | ||
| 141 | + virtual Template readTemplate() = 0; | ||
| 142 | +}; | ||
| 143 | + | ||
| 144 | +/*! | ||
| 145 | + * \ingroup galleries | ||
| 146 | + * \brief A binary gallery. | ||
| 147 | + * | ||
| 148 | + * Designed to be a literal translation of templates to disk. | ||
| 149 | + * Compatible with TemplateList::fromBuffer. | ||
| 150 | + * \author Josh Klontz \cite jklontz | ||
| 151 | + */ | ||
| 152 | +class galGallery : public BinaryGallery | ||
| 153 | +{ | ||
| 154 | + Q_OBJECT | ||
| 155 | + | ||
| 156 | + Template readTemplate() | ||
| 157 | + { | ||
| 158 | + Template t; | ||
| 159 | + stream >> t; | ||
| 160 | + return t; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + void write(const Template &t) | ||
| 164 | + { | ||
| 165 | + if (t.isEmpty() && t.file.isNull()) | ||
| 166 | + return; | ||
| 167 | + stream << t; | ||
| 168 | + } | ||
| 156 | }; | 169 | }; |
| 157 | 170 | ||
| 158 | BR_REGISTER(Gallery, galGallery) | 171 | BR_REGISTER(Gallery, galGallery) |
| 159 | 172 | ||
| 160 | /*! | 173 | /*! |
| 161 | * \ingroup galleries | 174 | * \ingroup galleries |
| 175 | + * \brief A contiguous array of br_universal_template. | ||
| 176 | + * \author Josh Klontz \cite jklontz | ||
| 177 | + */ | ||
| 178 | +class utGallery : public BinaryGallery | ||
| 179 | +{ | ||
| 180 | + Q_OBJECT | ||
| 181 | + | ||
| 182 | + Template readTemplate() | ||
| 183 | + { | ||
| 184 | + cv::Mat m; | ||
| 185 | + br_utemplate t = (br_utemplate) malloc(sizeof(br_universal_template)); | ||
| 186 | + if (gallery.read((char*)t, sizeof(br_universal_template)) == sizeof(br_universal_template)) { | ||
| 187 | + m = cv::Mat(1, t->size, CV_8UC1); | ||
| 188 | + if (gallery.read((char*)m.data, t->size) != t->size) | ||
| 189 | + qFatal("Unexepected EOF when reading universal template data."); | ||
| 190 | + } | ||
| 191 | + free(t); | ||
| 192 | + return m; | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + void write(const Template &) | ||
| 196 | + { | ||
| 197 | + qFatal("Not implemented."); | ||
| 198 | + } | ||
| 199 | +}; | ||
| 200 | + | ||
| 201 | +BR_REGISTER(Gallery, utGallery) | ||
| 202 | + | ||
| 203 | +/*! | ||
| 204 | + * \ingroup galleries | ||
| 162 | * \brief Reads/writes templates to/from folders. | 205 | * \brief Reads/writes templates to/from folders. |
| 163 | * \author Josh Klontz \cite jklontz | 206 | * \author Josh Klontz \cite jklontz |
| 164 | * \param regexp An optional regular expression to match against the files extension. | 207 | * \param regexp An optional regular expression to match against the files extension. |
openbr/plugins/misc.cpp
| @@ -55,6 +55,23 @@ BR_REGISTER(Transform, OpenTransform) | @@ -55,6 +55,23 @@ BR_REGISTER(Transform, OpenTransform) | ||
| 55 | 55 | ||
| 56 | /*! | 56 | /*! |
| 57 | * \ingroup transforms | 57 | * \ingroup transforms |
| 58 | + * \brief Decodes images | ||
| 59 | + * \author Josh Klontz \cite jklontz | ||
| 60 | + */ | ||
| 61 | +class DecodeTransform : public UntrainableTransform | ||
| 62 | +{ | ||
| 63 | + Q_OBJECT | ||
| 64 | + | ||
| 65 | + void project(const Template &src, Template &dst) const | ||
| 66 | + { | ||
| 67 | + dst.append(cv::imdecode(src.m(), IMREAD_UNCHANGED)); | ||
| 68 | + } | ||
| 69 | +}; | ||
| 70 | + | ||
| 71 | +BR_REGISTER(Transform, DecodeTransform) | ||
| 72 | + | ||
| 73 | +/*! | ||
| 74 | + * \ingroup transforms | ||
| 58 | * \brief Prints the template's file to stdout or stderr. | 75 | * \brief Prints the template's file to stdout or stderr. |
| 59 | * \author Josh Klontz \cite jklontz | 76 | * \author Josh Klontz \cite jklontz |
| 60 | */ | 77 | */ |