classifier.cpp
1.74 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
#include <QtConcurrentRun>
#include <openbr/openbr_plugin.h>
#include "classifier.h"
using namespace br;
/**** CLASSIFIER ****/
/*** PUBLIC ***/
GUIClassifier::GUIClassifier(QWidget *parent)
: QLabel(parent)
{
setAlignment(Qt::AlignCenter);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
connect(this, SIGNAL(newClassification(QString,QString)), this, SLOT(setClassification(QString,QString)));
}
void GUIClassifier::setAlgorithm(const QString &algorithm)
{
this->algorithm = algorithm;
}
/*** PUBLIC SLOTS ***/
void GUIClassifier::classify(const File &file)
{
QtConcurrent::run(this, &GUIClassifier::_classify, file);
}
/*** PRIVATE SLOTS ***/
void GUIClassifier::setClassification(const QString &key, const QString &value)
{
if (key.isEmpty()) clear();
else setText(QString("%1: <b>%2</b>").arg(key, value));
}
/*** PRIVATE ***/
void GUIClassifier::_classify(File file)
{
QString key, value;
QSharedPointer<Transform> transform = Transform::fromAlgorithm(algorithm);
TemplateList input, output;
input.append(file);
transform->projectUpdate(input, output);
foreach (const File &f, output.files() ) {
if (algorithm == "GenderClassification") key = "Gender";
else if (algorithm == "AgeRegression") key = "Age";
else key = algorithm;
if (!f.contains(key)) continue;
if (algorithm == "AgeRegression") value = QString::number(int(f.get<float>(key)+0.5)) + " Years";
else value = f.get<QString>(key);
break;
}
emit newClassification(key, value);
}
#include "moc_classifier.cpp"