From 3e2bb59573adce9615bdcc9b783aabb98e3c8ed3 Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Wed, 6 Mar 2013 23:24:05 -0500 Subject: [PATCH] fixed you tube face sorting issue --- sdk/core/core.cpp | 2 +- sdk/plugins/youtube.cpp | 34 +++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/sdk/core/core.cpp b/sdk/core/core.cpp index d85f49d..a386dd2 100644 --- a/sdk/core/core.cpp +++ b/sdk/core/core.cpp @@ -259,7 +259,7 @@ private: if (Globals->abbreviations.contains(description)) return init(Globals->abbreviations[description]); - QStringList words = description.split(':'); + QStringList words = QtUtils::parse(description, ':'); if (words.size() > 2) qFatal("Invalid algorithm format."); transform = QSharedPointer(Transform::make(words[0], NULL)); diff --git a/sdk/plugins/youtube.cpp b/sdk/plugins/youtube.cpp index 3d33ba9..1a96ddc 100644 --- a/sdk/plugins/youtube.cpp +++ b/sdk/plugins/youtube.cpp @@ -1,5 +1,7 @@ #include +#include "core/common.h" + namespace br { @@ -24,20 +26,22 @@ class YouTubeFacesDBTransform : public UntrainableMetaTransform distance = Distance::fromAlgorithm(algorithm); } - void project(const Template &src, Template &dst) const + void project(const TemplateList &src, TemplateList &dst) const { - dst = src; - - // First input is the header in 'splits.txt' - if (src.file.getInt("Index") == 0) return; + Transform::project(src.mid(1) /* First template is the header in 'splits.txt' */, dst); + } + void project(const Template &src, Template &dst) const + { const QStringList words = src.file.name.split(", "); dst.file.name = words[0] + "_" + words[1] + "_" + words[4] + ".mtx"; TemplateList queryTemplates = TemplateList::fromGallery(File(words[2]).resolved()); + sort(queryTemplates); queryTemplates >> *transform; TemplateList targetTemplates = TemplateList::fromGallery(File(words[3]).resolved()); + sort(targetTemplates); targetTemplates >> *transform; QScopedPointer memoryOutput(MatrixOutput::make(targetTemplates.files(), queryTemplates.files())); @@ -46,6 +50,26 @@ class YouTubeFacesDBTransform : public UntrainableMetaTransform dst.clear(); dst.m() = memoryOutput.data()->data; } + + static void sort(TemplateList &templates) + { + // The file names in the YouTube Faces Database make it very difficult + // for them to be ordered by frame number automatically, + // hence we do it manually here. + QList frames; + foreach (const Template &t, templates) { + QStringList words = t.file.name.split('.'); + frames.append(words[words.size()-2].toInt()); + } + + typedef QPair SortedFrame; // + QList sortedFrames = Common::Sort(frames); + TemplateList sortedTemplates; sortedTemplates.reserve(templates.size()); + foreach (const SortedFrame &sortedFrame, sortedFrames) + sortedTemplates.append(templates[sortedFrame.second]); + + templates = sortedTemplates; + } }; BR_REGISTER(Transform, YouTubeFacesDBTransform) -- libgit2 0.21.4