youtube.cpp
2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <QCoreApplication>
#include <QProcess>
#include <openbr_plugin.h>
#include "core/common.h"
namespace br
{
/*!
* \ingroup transforms
* \brief Implements the YouTubesFaceDB \cite wolf11 experimental protocol.
* \author Josh Klontz \cite jklontz
*/
class YouTubeFacesDBTransform : public UntrainableMetaTransform
{
Q_OBJECT
Q_PROPERTY(QString algorithm READ get_algorithm WRITE set_algorithm RESET reset_algorithm STORED false)
BR_PROPERTY(QString, algorithm, "")
void project(const Template &src, Template &dst) const
{
static QMutex mutex;
// First input is the header in 'splits.txt'
if (src.file.get<int>("Index") == 0) return;
const QStringList words = src.file.name.split(", ");
const QString matrix = "YTF-"+algorithm+"/"+words[0] + "_" + words[1] + "_" + words[4] + ".mtx";
const QStringList arguments = QStringList() << "-algorithm" << algorithm
<< "-parallelism" << QString::number(Globals->parallelism)
<< "-path" << Globals->path
<< "-compare" << File(words[2]).resolved() << File(words[3]).resolved() << matrix;
mutex.lock();
int result = 0;
if (!QFileInfo(matrix).exists())
result = QProcess::execute(QCoreApplication::applicationFilePath(), arguments);
mutex.unlock();
if (result != 0)
qWarning("Process for computing %s returned %d.", qPrintable(matrix), result);
dst = Template();
}
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<int> frames;
foreach (const Template &t, templates) {
QStringList words = t.file.name.split('.');
frames.append(words[words.size()-2].toInt());
}
typedef QPair<int,int> SortedFrame; // <frame number, original index>
QList<SortedFrame> 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)
} // namespace br
#include "youtube.moc"