Commit 0dbc7e4243d91b816b1f867dde6eb2b76eff4ccf

Authored by Josh Klontz
1 parent d3815649

rewrote xmlGallery to support writing

sdk/core/bee.cpp
... ... @@ -34,7 +34,7 @@ using namespace cv;
34 34 using namespace br;
35 35  
36 36 /**** BEE ****/
37   -FileList BEE::readSigset(QString sigset, bool ignoreMetadata)
  37 +FileList BEE::readSigset(const QString &sigset, bool ignoreMetadata)
38 38 {
39 39 FileList fileList;
40 40  
... ... @@ -90,24 +90,22 @@ FileList BEE::readSigset(QString sigset, bool ignoreMetadata)
90 90 return fileList;
91 91 }
92 92  
93   -void BEE::writeSigset(const QString &sigset, const br::FileList &fileList)
  93 +void BEE::writeSigset(const QString &sigset, const br::FileList &files, bool ignoreMetadata)
94 94 {
95   - typedef QPair<QString,QString> Signature; // QPair<Subject, File>
96   - QList<Signature> signatures;
97   -
98   - foreach (const File &file, fileList)
99   - signatures.append(Signature(file.subject(), file.name));
100   -
101   - QFile file(sigset);
102   - file.open(QFile::WriteOnly);
103   - file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
104   - "<biometric-signature-set>\n");
105   - foreach (const Signature &signature, signatures)
106   - file.write(qPrintable(QString("\t<biometric-signature name=\"%1\">\n"
107   - "\t\t<presentation file-name=\"%2\"/>\n"
108   - "\t</biometric-signature>\n").arg(signature.first, signature.second)));
109   - file.write("</biometric-signature-set>\n");
110   - file.close();
  95 + QStringList lines; lines.reserve(3*files.size()+3);
  96 + lines.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  97 + lines.append("<biometric-signature-set>");
  98 + foreach (const File &file, files) {
  99 + QStringList metadata;
  100 + if (!ignoreMetadata)
  101 + foreach (const QString &key, file.localKeys())
  102 + metadata.append(key+"=\""+file.getString(key, "?")+"\"");
  103 + lines.append("\t<biometric-signature name=\"" + file.subject() +"\">");
  104 + lines.append("\t\t<presentation file-name=\"" + file.name + "\" " + metadata.join(" ") + "/>");
  105 + lines.append("\t</biometric-signature>");
  106 + }
  107 + lines.append("</biometric-signature-set>");
  108 + QtUtils::writeFile(sigset, lines);
111 109 }
112 110  
113 111 template <typename T>
... ...
sdk/core/bee.h
... ... @@ -35,8 +35,8 @@ namespace BEE
35 35 typedef uchar Mask_t;
36 36  
37 37 // Sigset IO
38   - br::FileList readSigset(QString sigset, bool ignoreMetadata = false);
39   - void writeSigset(const QString &sigset, const br::FileList &metadataList);
  38 + br::FileList readSigset(const QString &sigset, bool ignoreMetadata = false);
  39 + void writeSigset(const QString &sigset, const br::FileList &files, bool ignoreMetadata = false);
40 40  
41 41 // Matrix IO
42 42 cv::Mat readSimmat(const br::File &simmat);
... ...
sdk/openbr_plugin.h
... ... @@ -330,6 +330,7 @@ struct TemplateList : public QList&lt;Template&gt;
330 330  
331 331 TemplateList() : uniform(false) {}
332 332 TemplateList(const QList<Template> &templates) : uniform(false) { append(templates); } /*!< \brief Initialize the template list from another template list. */
  333 + TemplateList(const QList<File> &files) : uniform(false) { foreach (const File &file, files) append(file); }
333 334 BR_EXPORT static TemplateList fromInput(const File &input); /*!< \brief Create a template list from a br::Input. */
334 335 BR_EXPORT static TemplateList relabel(const TemplateList &tl); /*!< \brief Ensure labels are in the range [0,numClasses-1]. */
335 336 /*!
... ...
sdk/plugins/gallery.cpp
... ... @@ -433,22 +433,24 @@ BR_REGISTER(Gallery, txtGallery)
433 433 class xmlGallery : public Gallery
434 434 {
435 435 Q_OBJECT
436   - Q_PROPERTY(bool ignoreMetadata READ get_ignoreMetadata WRITE set_ignoreMetadata RESET reset_ignoreMetadata)
  436 + Q_PROPERTY(bool ignoreMetadata READ get_ignoreMetadata WRITE set_ignoreMetadata RESET reset_ignoreMetadata STORED false)
437 437 BR_PROPERTY(bool, ignoreMetadata, false)
  438 + FileList files;
  439 +
  440 + ~xmlGallery()
  441 + {
  442 + BEE::writeSigset(file, files, ignoreMetadata);
  443 + }
438 444  
439 445 TemplateList readBlock(bool *done)
440 446 {
441   - TemplateList templates;
442   - foreach (const File &signature, BEE::readSigset(file.name, ignoreMetadata))
443   - templates.append(signature);
444 447 *done = true;
445   - return templates;
  448 + return TemplateList(BEE::readSigset(file, ignoreMetadata));
446 449 }
447 450  
448 451 void write(const Template &t)
449 452 {
450   - (void) t;
451   - qFatal("Writing to an xmlGallery not supported.");
  453 + files.append(t.file);
452 454 }
453 455 };
454 456  
... ... @@ -471,8 +473,7 @@ class dbGallery : public Gallery
471 473 QString subset = file.getString("subset", "");
472 474  
473 475 #ifndef BR_EMBEDDED
474   - static QSqlDatabase db;
475   - if (!db.isValid()) db = QSqlDatabase::addDatabase("QSQLITE");
  476 + QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
476 477 db.setDatabaseName(file);
477 478 if (!db.open()) qFatal("Failed to open SQLite database %s.", qPrintable(file.name));
478 479  
... ...