Commit 9b42f0bfda5643a0a46cd9ced0213843591f096e

Authored by Josh Klontz
1 parent 2e3ebad6

rewrote YouTubeFacesDBTransform

sdk/core/bee.cpp
@@ -199,6 +199,7 @@ void writeMatrix(const Mat &m, const QString &matrix, const QString &targetSigse @@ -199,6 +199,7 @@ void writeMatrix(const Mat &m, const QString &matrix, const QString &targetSigse
199 199
200 char buff[4]; 200 char buff[4];
201 QFile file(matrix); 201 QFile file(matrix);
  202 + QtUtils::touchDir(file);
202 bool success = file.open(QFile::WriteOnly); if (!success) qFatal("Unable to open %s for writing.", qPrintable(matrix)); 203 bool success = file.open(QFile::WriteOnly); if (!success) qFatal("Unable to open %s for writing.", qPrintable(matrix));
203 file.write("S2\n"); 204 file.write("S2\n");
204 file.write(qPrintable(QFileInfo(targetSigset).fileName())); 205 file.write(qPrintable(QFileInfo(targetSigset).fileName()));
sdk/plugins/youtube.cpp
  1 +#include <QProcess>
1 #include <openbr_plugin.h> 2 #include <openbr_plugin.h>
2 3
3 #include "core/common.h" 4 #include "core/common.h"
@@ -16,16 +17,6 @@ class YouTubeFacesDBTransform : public UntrainableMetaTransform @@ -16,16 +17,6 @@ class YouTubeFacesDBTransform : public UntrainableMetaTransform
16 Q_PROPERTY(QString algorithm READ get_algorithm WRITE set_algorithm RESET reset_algorithm STORED false) 17 Q_PROPERTY(QString algorithm READ get_algorithm WRITE set_algorithm RESET reset_algorithm STORED false)
17 BR_PROPERTY(QString, algorithm, "") 18 BR_PROPERTY(QString, algorithm, "")
18 19
19 - QSharedPointer<Transform> transform;  
20 - QSharedPointer<Distance> distance;  
21 -  
22 - void init()  
23 - {  
24 - if (algorithm.isEmpty()) return;  
25 - transform = Transform::fromAlgorithm(algorithm);  
26 - distance = Distance::fromAlgorithm(algorithm);  
27 - }  
28 -  
29 void project(const TemplateList &src, TemplateList &dst) const 20 void project(const TemplateList &src, TemplateList &dst) const
30 { 21 {
31 Transform::project(src.mid(1) /* First template is the header in 'splits.txt' */, dst); 22 Transform::project(src.mid(1) /* First template is the header in 'splits.txt' */, dst);
@@ -33,22 +24,19 @@ class YouTubeFacesDBTransform : public UntrainableMetaTransform @@ -33,22 +24,19 @@ class YouTubeFacesDBTransform : public UntrainableMetaTransform
33 24
34 void project(const Template &src, Template &dst) const 25 void project(const Template &src, Template &dst) const
35 { 26 {
  27 + static QMutex mutex;
36 const QStringList words = src.file.name.split(", "); 28 const QStringList words = src.file.name.split(", ");
37 - dst.file.name = words[0] + "_" + words[1] + "_" + words[4] + ".mtx";  
38 -  
39 - TemplateList queryTemplates = TemplateList::fromGallery(File(words[2]).resolved());  
40 - sort(queryTemplates);  
41 - queryTemplates >> *transform;  
42 -  
43 - TemplateList targetTemplates = TemplateList::fromGallery(File(words[3]).resolved());  
44 - sort(targetTemplates);  
45 - targetTemplates >> *transform;  
46 -  
47 - QScopedPointer<MatrixOutput> memoryOutput(MatrixOutput::make(targetTemplates.files(), queryTemplates.files()));  
48 - distance->compare(targetTemplates, queryTemplates, memoryOutput.data());  
49 -  
50 - dst.clear();  
51 - dst.m() = memoryOutput.data()->data; 29 + const QString matrix = "YTF-"+algorithm+"/"+words[0] + "_" + words[1] + "_" + words[4] + ".mtx";
  30 + const QStringList arguments = QStringList() << "-algorithm" << algorithm
  31 + << "-parallelism" << QString::number(Globals->parallelism)
  32 + << "-path" << Globals->path
  33 + << "-compare" << File(words[2]).resolved() << File(words[3]).resolved() << matrix;
  34 + mutex.lock();
  35 + int result = QProcess::execute(QCoreApplication::applicationFilePath(), arguments);
  36 + mutex.unlock();
  37 + if (result != 0)
  38 + qWarning("Process for computing %s returned %d.", qPrintable(matrix), result);
  39 + dst = Template();
52 } 40 }
53 41
54 static void sort(TemplateList &templates) 42 static void sort(TemplateList &templates)