Commit 3e2bb59573adce9615bdcc9b783aabb98e3c8ed3

Authored by Josh Klontz
1 parent d7b36b93

fixed you tube face sorting issue

sdk/core/core.cpp
@@ -259,7 +259,7 @@ private: @@ -259,7 +259,7 @@ private:
259 if (Globals->abbreviations.contains(description)) 259 if (Globals->abbreviations.contains(description))
260 return init(Globals->abbreviations[description]); 260 return init(Globals->abbreviations[description]);
261 261
262 - QStringList words = description.split(':'); 262 + QStringList words = QtUtils::parse(description, ':');
263 if (words.size() > 2) qFatal("Invalid algorithm format."); 263 if (words.size() > 2) qFatal("Invalid algorithm format.");
264 264
265 transform = QSharedPointer<Transform>(Transform::make(words[0], NULL)); 265 transform = QSharedPointer<Transform>(Transform::make(words[0], NULL));
sdk/plugins/youtube.cpp
1 #include <openbr_plugin.h> 1 #include <openbr_plugin.h>
2 2
  3 +#include "core/common.h"
  4 +
3 namespace br 5 namespace br
4 { 6 {
5 7
@@ -24,20 +26,22 @@ class YouTubeFacesDBTransform : public UntrainableMetaTransform @@ -24,20 +26,22 @@ class YouTubeFacesDBTransform : public UntrainableMetaTransform
24 distance = Distance::fromAlgorithm(algorithm); 26 distance = Distance::fromAlgorithm(algorithm);
25 } 27 }
26 28
27 - void project(const Template &src, Template &dst) const 29 + void project(const TemplateList &src, TemplateList &dst) const
28 { 30 {
29 - dst = src;  
30 -  
31 - // First input is the header in 'splits.txt'  
32 - if (src.file.getInt("Index") == 0) return; 31 + Transform::project(src.mid(1) /* First template is the header in 'splits.txt' */, dst);
  32 + }
33 33
  34 + void project(const Template &src, Template &dst) const
  35 + {
34 const QStringList words = src.file.name.split(", "); 36 const QStringList words = src.file.name.split(", ");
35 dst.file.name = words[0] + "_" + words[1] + "_" + words[4] + ".mtx"; 37 dst.file.name = words[0] + "_" + words[1] + "_" + words[4] + ".mtx";
36 38
37 TemplateList queryTemplates = TemplateList::fromGallery(File(words[2]).resolved()); 39 TemplateList queryTemplates = TemplateList::fromGallery(File(words[2]).resolved());
  40 + sort(queryTemplates);
38 queryTemplates >> *transform; 41 queryTemplates >> *transform;
39 42
40 TemplateList targetTemplates = TemplateList::fromGallery(File(words[3]).resolved()); 43 TemplateList targetTemplates = TemplateList::fromGallery(File(words[3]).resolved());
  44 + sort(targetTemplates);
41 targetTemplates >> *transform; 45 targetTemplates >> *transform;
42 46
43 QScopedPointer<MatrixOutput> memoryOutput(MatrixOutput::make(targetTemplates.files(), queryTemplates.files())); 47 QScopedPointer<MatrixOutput> memoryOutput(MatrixOutput::make(targetTemplates.files(), queryTemplates.files()));
@@ -46,6 +50,26 @@ class YouTubeFacesDBTransform : public UntrainableMetaTransform @@ -46,6 +50,26 @@ class YouTubeFacesDBTransform : public UntrainableMetaTransform
46 dst.clear(); 50 dst.clear();
47 dst.m() = memoryOutput.data()->data; 51 dst.m() = memoryOutput.data()->data;
48 } 52 }
  53 +
  54 + static void sort(TemplateList &templates)
  55 + {
  56 + // The file names in the YouTube Faces Database make it very difficult
  57 + // for them to be ordered by frame number automatically,
  58 + // hence we do it manually here.
  59 + QList<int> frames;
  60 + foreach (const Template &t, templates) {
  61 + QStringList words = t.file.name.split('.');
  62 + frames.append(words[words.size()-2].toInt());
  63 + }
  64 +
  65 + typedef QPair<int,int> SortedFrame; // <frame number, original index>
  66 + QList<SortedFrame> sortedFrames = Common::Sort(frames);
  67 + TemplateList sortedTemplates; sortedTemplates.reserve(templates.size());
  68 + foreach (const SortedFrame &sortedFrame, sortedFrames)
  69 + sortedTemplates.append(templates[sortedFrame.second]);
  70 +
  71 + templates = sortedTemplates;
  72 + }
49 }; 73 };
50 74
51 BR_REGISTER(Transform, YouTubeFacesDBTransform) 75 BR_REGISTER(Transform, YouTubeFacesDBTransform)