diff --git a/openbr/plugins/gallery.cpp b/openbr/plugins/gallery.cpp index 05a12b4..e574ec0 100644 --- a/openbr/plugins/gallery.cpp +++ b/openbr/plugins/gallery.cpp @@ -701,11 +701,16 @@ class dbGallery : public Gallery query = query.mid(1, query.size()-2); if (!q.exec(query)) qFatal("%s.", qPrintable(q.lastError().text())); + if ((q.record().count() == 0) || (q.record().count() > 3)) qFatal("Query record expected one to three fields, got %d.", q.record().count()); const bool hasMetadata = (q.record().count() >= 2); const bool hasFilter = (q.record().count() >= 3); + QString labelName = "Label"; + if (q.record().count() >= 2) + labelName = q.record().fieldName(1); + // subset = seed:subjectMaxSize:numSubjects:subjectMinSize or // subset = seed:{Metadata,...,Metadata}:numSubjects int seed = 0, subjectMaxSize = std::numeric_limits::max(), numSubjects = std::numeric_limits::max(), subjectMinSize = 0; @@ -731,6 +736,7 @@ class dbGallery : public Gallery QHash > entries; // QHash > while (q.next()) { if (hasFilter && (seed >= 0) && (qHash(q.value(2).toString()) % 2 != (uint)seed % 2)) continue; // Ensures training and testing filters don't overlap + if (metadataFields.isEmpty()) entries[hasMetadata ? q.value(1).toString() : ""].append(QPair(q.value(0).toString(), hasFilter ? q.value(2).toString() : "")); else @@ -765,8 +771,10 @@ class dbGallery : public Gallery if (entryList.size() > subjectMaxSize) std::random_shuffle(entryList.begin(), entryList.end()); - foreach (const Entry &entry, entryList.mid(0, subjectMaxSize)) - templates.append(File(entry.first, label)); + foreach (const Entry &entry, entryList.mid(0, subjectMaxSize)) { + templates.append(File(entry.first)); + templates.last().file.set(labelName, label); + } numSubjects--; } }