Commit 33adb525d201992e0445bd0fb722332c81630eb5
1 parent
0a61040d
improvements to utGallery
Showing
2 changed files
with
25 additions
and
9 deletions
openbr/plugins/gallery.cpp
| ... | ... | @@ -193,8 +193,8 @@ class utGallery : public BinaryGallery |
| 193 | 193 | Template t; |
| 194 | 194 | br_utemplate ut = (br_utemplate) malloc(sizeof(br_universal_template)); |
| 195 | 195 | if (gallery.read((char*)ut, sizeof(br_universal_template)) == sizeof(br_universal_template)) { |
| 196 | - cv::Mat m = cv::Mat(1, ut->size, CV_8UC1); | |
| 197 | - char *dst = (char*) m.data; | |
| 196 | + QByteArray data(ut->size, Qt::Uninitialized); | |
| 197 | + char *dst = data.data(); | |
| 198 | 198 | qint64 bytesNeeded = ut->size; |
| 199 | 199 | while (bytesNeeded > 0) { |
| 200 | 200 | qint64 bytesRead = gallery.read(dst, bytesNeeded); |
| ... | ... | @@ -203,10 +203,17 @@ class utGallery : public BinaryGallery |
| 203 | 203 | bytesNeeded -= bytesRead; |
| 204 | 204 | dst += bytesRead; |
| 205 | 205 | } |
| 206 | - t.append(m); | |
| 207 | - t.file.set("ImageID", QVariant(QByteArray((const char*)ut->imageID, 16))); | |
| 208 | - t.file.set("TemplateID", QVariant(QByteArray((const char*)ut->templateID, 16))); | |
| 209 | - t.file.set("AlgorithmID", QVariant(ut->algorithmID)); | |
| 206 | + | |
| 207 | + if (ut->algorithmID == 5) { | |
| 208 | + QDataStream stream(&data, QIODevice::ReadOnly); | |
| 209 | + stream >> t; | |
| 210 | + } else { | |
| 211 | + t.append(cv::Mat(1, data.size(), CV_8UC1, data.data())); | |
| 212 | + } | |
| 213 | + | |
| 214 | + t.file.set("ImageID", QVariant(QByteArray((const char*)ut->imageID, 16).toHex())); | |
| 215 | + t.file.set("TemplateID", QVariant(QByteArray((const char*)ut->templateID, 16).toHex())); | |
| 216 | + t.file.set("AlgorithmID", ut->algorithmID); | |
| 210 | 217 | } |
| 211 | 218 | free(ut); |
| 212 | 219 | return t; |
| ... | ... | @@ -222,12 +229,18 @@ class utGallery : public BinaryGallery |
| 222 | 229 | qFatal("Expected 16-byte ImageID, got: %d bytes.", imageID.size()); |
| 223 | 230 | |
| 224 | 231 | const int32_t algorithmID = t.file.get<int32_t>("AlgorithmID"); |
| 225 | - const QByteArray data((const char*) t.m().data, t.m().rows * t.m().cols * t.m().elemSize()); | |
| 232 | + QByteArray data; | |
| 233 | + if (algorithmID == 5) { | |
| 234 | + QDataStream stream(&data, QIODevice::WriteOnly); | |
| 235 | + stream << t; | |
| 236 | + } else { | |
| 237 | + data = QByteArray((const char*) t.m().data, t.m().rows * t.m().cols * t.m().elemSize()); | |
| 238 | + } | |
| 226 | 239 | const QByteArray templateID = QCryptographicHash::hash(data, QCryptographicHash::Md5); |
| 227 | 240 | const uint32_t size = data.size(); |
| 228 | 241 | |
| 229 | - gallery.write(imageID); | |
| 230 | - gallery.write(templateID); | |
| 242 | + gallery.write(QByteArray::fromHex(imageID)); | |
| 243 | + gallery.write(QByteArray::fromHex(templateID)); | |
| 231 | 244 | gallery.write((const char*) &algorithmID, 4); |
| 232 | 245 | gallery.write((const char*) &size, 4); |
| 233 | 246 | gallery.write(data); | ... | ... |
openbr/plugins/misc.cpp
| ... | ... | @@ -149,6 +149,9 @@ private: |
| 149 | 149 | if (!decoded.empty()) |
| 150 | 150 | dst += (mode == Encoded) ? encoded : decoded; |
| 151 | 151 | } |
| 152 | + | |
| 153 | + dst.file.set("ImageID", QVariant(QCryptographicHash::hash(data, QCryptographicHash::Md5))); | |
| 154 | + dst.file.set("AlgorithmID", mode == Decoded ? 5 : 3); | |
| 152 | 155 | } |
| 153 | 156 | }; |
| 154 | 157 | ... | ... |