Commit f613d429b875d05dcac4f94f03b99f0009dc9ebe

Authored by Josh Klontz
1 parent e52c15ae

updated utGallery to reflect new universal template format

Showing 1 changed file with 38 additions and 76 deletions
openbr/plugins/gallery.cpp
... ... @@ -242,26 +242,18 @@ class utGallery : public BinaryGallery
242 242 dst += bytesRead;
243 243 }
244 244  
245   - if (QCryptographicHash::hash(data, QCryptographicHash::Md5) != QByteArray((const char*)ut.templateID, 16))
  245 + if (QCryptographicHash::hash(data.mid(ut.urlSize), QCryptographicHash::Md5) != QByteArray((const char*)ut.templateID, 16))
246 246 qFatal("MD5 hash check failure!");
247 247  
248   - if (ut.algorithmID == 5) {
249   - QDataStream stream(&data, QIODevice::ReadOnly);
250   - stream >> t;
251   - } else if (ut.algorithmID == 7) {
252   - uint32_t *roi = (uint32_t*) data.data();
253   - t.file.set("X", roi[0]);
254   - t.file.set("Y", roi[1]);
255   - t.file.set("Width", roi[2]);
256   - t.file.set("Height", roi[3]);
257   - t.append(cv::Mat(1, data.size()-4*sizeof(uint32_t), CV_8UC1, data.data()+4*sizeof(uint32_t)).clone() /* We don't want a shallow copy! */);
258   - } else {
259   - t.append(cv::Mat(1, data.size(), CV_8UC1, data.data()).clone() /* We don't want a shallow copy! */);
260   - }
261   -
262 248 t.file.set("ImageID", QVariant(QByteArray((const char*)ut.imageID, 16).toHex()));
263 249 t.file.set("TemplateID", QVariant(QByteArray((const char*)ut.templateID, 16).toHex()));
264 250 t.file.set("AlgorithmID", ut.algorithmID);
  251 + t.file.set("X", ut.x);
  252 + t.file.set("Y", ut.y);
  253 + t.file.set("Width", ut.width);
  254 + t.file.set("Height", ut.height);
  255 + t.file.set("URL", QString(data.data()));
  256 + t.append(cv::Mat(1, ut.size - ut.urlSize, CV_8UC1, data.data() + ut.urlSize).clone() /* We don't want a shallow copy! */);
265 257 } else {
266 258 qFatal("Failed to read universal template header!");
267 259 }
... ... @@ -275,75 +267,45 @@ class utGallery : public BinaryGallery
275 267 qFatal("Expected 16-byte ImageID, got: %d bytes.", imageID.size());
276 268  
277 269 const int32_t algorithmID = t.isEmpty() ? 0 : t.file.get<int32_t>("AlgorithmID");
  270 + const QByteArray url = t.file.get<QString>("URL", t.file.name).toLatin1();
  271 +
  272 + uint32_t x = 0, y = 0, width = 0, height = 0;
278 273 QByteArray data;
279   - if (algorithmID == 5) {
280   - QDataStream stream(&data, QIODevice::WriteOnly);
281   - stream << t;
  274 + if (algorithmID == -1) {
  275 + const QRectF frontalFace = t.file.get<QRectF>("FrontalFace");
  276 + x = frontalFace.x();
  277 + y = frontalFace.y();
  278 + width = frontalFace.width();
  279 + height = frontalFace.height();
  280 +
  281 + const QPointF firstEye = t.file.get<QPointF>("First_Eye");
  282 + const QPointF secondEye = t.file.get<QPointF>("Second_Eye");
  283 + const uint32_t rightEyeX = firstEye.x();
  284 + const uint32_t rightEyeY = firstEye.y();
  285 + const uint32_t leftEyeX = secondEye.x();
  286 + const uint32_t leftEyeY = secondEye.y();
  287 +
  288 + data.append((const char*)&rightEyeX, sizeof(uint32_t));
  289 + data.append((const char*)&rightEyeY, sizeof(uint32_t));
  290 + data.append((const char*)&leftEyeX , sizeof(uint32_t));
  291 + data.append((const char*)&leftEyeY , sizeof(uint32_t));
282 292 } else {
283   - if (!t.empty())
284   - data = QByteArray((const char*) t.m().data, t.m().rows * t.m().cols * t.m().elemSize());
285   -
286   - if (algorithmID == -1) {
287   - const QRectF frontalFace = t.file.get<QRectF>("FrontalFace");
288   - const QPointF firstEye = t.file.get<QPointF>("First_Eye");
289   - const QPointF secondEye = t.file.get<QPointF>("Second_Eye");
290   - const float x = frontalFace.x();
291   - const float y = frontalFace.y();
292   - const float width = frontalFace.width();
293   - const float height = frontalFace.height();
294   - const float rightEyeX = firstEye.x();
295   - const float rightEyeY = firstEye.y();
296   - const float leftEyeX = secondEye.x();
297   - const float leftEyeY = secondEye.y();
298   -
299   - data.append((const char*)&x , sizeof(float));
300   - data.append((const char*)&y , sizeof(float));
301   - data.append((const char*)&width , sizeof(float));
302   - data.append((const char*)&height , sizeof(float));
303   - data.append((const char*)&rightEyeX, sizeof(float));
304   - data.append((const char*)&rightEyeY, sizeof(float));
305   - data.append((const char*)&leftEyeX , sizeof(float));
306   - data.append((const char*)&leftEyeY , sizeof(float));
307   - }
  293 + x = t.file.get<uint32_t>("X", 0);
  294 + y = t.file.get<uint32_t>("Y", 0);
  295 + width = t.file.get<uint32_t>("Width", 0);
  296 + height = t.file.get<uint32_t>("Height", 0);
308 297 }
309   - const QByteArray templateID = data.isEmpty() ? QByteArray(16, 0) : QCryptographicHash::hash(data, QCryptographicHash::Md5);
310   - const uint32_t size = data.size();
311 298  
312   - gallery.write(imageID);
313   - gallery.write(templateID);
314   - gallery.write((const char*) &algorithmID, 4);
315   - gallery.write((const char*) &size, 4);
316   - gallery.write(data);
317   - }
318   -};
  299 + if (!t.empty())
  300 + data.append((const char*) t.m().data, t.m().rows * t.m().cols * t.m().elemSize());
319 301  
320   -BR_REGISTER(Gallery, utGallery)
321   -
322   -/*!
323   - * \ingroup galleries
324   - * \brief Newline-separated br_universal_template data.
325   - * \author Josh Klontz \cite jklontz
326   - */
327   -class utdGallery : public BinaryGallery
328   -{
329   - Q_OBJECT
330   -
331   - Template readTemplate()
332   - {
333   - qFatal("Not supported");
334   - return Template();
335   - }
336   -
337   - void writeTemplate(const Template &t)
338   - {
339   - if (t.empty())
340   - return;
341   - gallery.write(QByteArray((const char*) t.m().data, t.m().rows * t.m().cols * t.m().elemSize()));
342   - gallery.write("\n");
  302 + br_const_utemplate ut = br_new_utemplate((const int8_t*) imageID.data(), algorithmID, x, y, width, height, url.data(), data.data(), data.size());
  303 + gallery.write((const char*) ut, sizeof(br_universal_template) + ut->size);
  304 + br_free_utemplate(ut);
343 305 }
344 306 };
345 307  
346   -BR_REGISTER(Gallery, utdGallery)
  308 +BR_REGISTER(Gallery, utGallery)
347 309  
348 310 /*!
349 311 * \ingroup galleries
... ...