Commit 3289608e4f5a9dc91633d695787f0c728f5cd4a8
1 parent
8c5153cb
moved turkGallery to turk.cpp
Showing
2 changed files
with
60 additions
and
66 deletions
openbr/plugins/gallery.cpp
| @@ -1019,72 +1019,6 @@ class landmarksGallery : public Gallery | @@ -1019,72 +1019,6 @@ class landmarksGallery : public Gallery | ||
| 1019 | 1019 | ||
| 1020 | BR_REGISTER(Gallery, landmarksGallery) | 1020 | BR_REGISTER(Gallery, landmarksGallery) |
| 1021 | 1021 | ||
| 1022 | -/*! | ||
| 1023 | - * \ingroup galleries | ||
| 1024 | - * \brief Treats each line as a file. | ||
| 1025 | - * \author Josh Klontz \cite jklontz | ||
| 1026 | - * | ||
| 1027 | - * Columns should be comma separated with first row containing headers. | ||
| 1028 | - * The first column in the file should be the path to the file to enroll. | ||
| 1029 | - * Other columns will be treated as file metadata. | ||
| 1030 | - * | ||
| 1031 | - * \see txtGallery | ||
| 1032 | - */ | ||
| 1033 | -class turkGallery : public Gallery | ||
| 1034 | -{ | ||
| 1035 | - Q_OBJECT | ||
| 1036 | -; | ||
| 1037 | - TemplateList readBlock(bool *done) | ||
| 1038 | - { | ||
| 1039 | - *done = true; | ||
| 1040 | - TemplateList templates; | ||
| 1041 | - if (!file.exists()) return templates; | ||
| 1042 | - | ||
| 1043 | - QStringList lines = QtUtils::readLines(file); | ||
| 1044 | - QRegExp regexp(",(?!(?:\\w+,?)+\\])"); | ||
| 1045 | - | ||
| 1046 | - QStringList headers; | ||
| 1047 | - | ||
| 1048 | - if (!lines.isEmpty()) headers = lines.takeFirst().split(regexp); | ||
| 1049 | - | ||
| 1050 | - foreach (const QString &line, lines) { | ||
| 1051 | - QStringList words = line.split(regexp); | ||
| 1052 | - if (words.size() != headers.size()) continue; | ||
| 1053 | - File f; | ||
| 1054 | - f.name = words[0]; | ||
| 1055 | - f.set("Label", words[0].mid(0,5)); | ||
| 1056 | - | ||
| 1057 | - for (int i=1; i<words.size(); i++) { | ||
| 1058 | - QStringList categories = headers[i].split('['); | ||
| 1059 | - categories.last().chop(1); // Remove trailing bracket | ||
| 1060 | - QStringList types = categories.last().split(','); | ||
| 1061 | - | ||
| 1062 | - QStringList ratings = words[i].split(','); | ||
| 1063 | - ratings.first() = ratings.first().mid(1); // Remove first bracket | ||
| 1064 | - ratings.last().chop(1); // Remove trailing bracket | ||
| 1065 | - | ||
| 1066 | - if (types.size() != ratings.size()) continue; | ||
| 1067 | - | ||
| 1068 | - QMap<QString,QVariant> categoryMap; | ||
| 1069 | - for (int j=0; j<types.size(); j++) categoryMap.insert(types[j],ratings[j]); | ||
| 1070 | - | ||
| 1071 | - f.set(categories[0], categoryMap); | ||
| 1072 | - } | ||
| 1073 | - templates.append(f); | ||
| 1074 | - } | ||
| 1075 | - | ||
| 1076 | - return templates; | ||
| 1077 | - } | ||
| 1078 | - | ||
| 1079 | - void write(const Template &t) | ||
| 1080 | - { | ||
| 1081 | - (void)t; | ||
| 1082 | - qFatal("turkGallery write not implemented."); | ||
| 1083 | - } | ||
| 1084 | -}; | ||
| 1085 | - | ||
| 1086 | -BR_REGISTER(Gallery, turkGallery) | ||
| 1087 | - | ||
| 1088 | #ifdef CVMATIO | 1022 | #ifdef CVMATIO |
| 1089 | 1023 | ||
| 1090 | using namespace cv; | 1024 | using namespace cv; |
openbr/plugins/turk.cpp
| 1 | #include "openbr_internal.h" | 1 | #include "openbr_internal.h" |
| 2 | +#include "openbr/core/qtutils.h" | ||
| 2 | 3 | ||
| 3 | namespace br | 4 | namespace br |
| 4 | { | 5 | { |
| 5 | 6 | ||
| 7 | +/*! | ||
| 8 | + * \ingroup galleries | ||
| 9 | + * \brief For Amazon Mechanical Turk datasets | ||
| 10 | + * \author Scott Klum \cite sklum | ||
| 11 | + */ | ||
| 12 | +class turkGallery : public Gallery | ||
| 13 | +{ | ||
| 14 | + Q_OBJECT | ||
| 15 | + | ||
| 16 | + TemplateList readBlock(bool *done) | ||
| 17 | + { | ||
| 18 | + *done = true; | ||
| 19 | + TemplateList templates; | ||
| 20 | + if (!file.exists()) return templates; | ||
| 21 | + | ||
| 22 | + QStringList lines = QtUtils::readLines(file); | ||
| 23 | + QRegExp regexp(",(?!(?:\\w+,?)+\\])"); | ||
| 24 | + | ||
| 25 | + QStringList headers; | ||
| 26 | + | ||
| 27 | + if (!lines.isEmpty()) headers = lines.takeFirst().split(regexp); | ||
| 28 | + | ||
| 29 | + foreach (const QString &line, lines) { | ||
| 30 | + QStringList words = line.split(regexp); | ||
| 31 | + if (words.size() != headers.size()) continue; | ||
| 32 | + File f; | ||
| 33 | + f.name = words[0]; | ||
| 34 | + f.set("Label", words[0].mid(0,5)); | ||
| 35 | + | ||
| 36 | + for (int i=1; i<words.size(); i++) { | ||
| 37 | + QStringList categories = headers[i].split('['); | ||
| 38 | + categories.last().chop(1); // Remove trailing bracket | ||
| 39 | + QStringList types = categories.last().split(','); | ||
| 40 | + | ||
| 41 | + QStringList ratings = words[i].split(','); | ||
| 42 | + ratings.first() = ratings.first().mid(1); // Remove first bracket | ||
| 43 | + ratings.last().chop(1); // Remove trailing bracket | ||
| 44 | + | ||
| 45 | + if (types.size() != ratings.size()) continue; | ||
| 46 | + | ||
| 47 | + QMap<QString,QVariant> categoryMap; | ||
| 48 | + for (int j=0; j<types.size(); j++) categoryMap.insert(types[j],ratings[j]); | ||
| 49 | + | ||
| 50 | + f.set(categories[0], categoryMap); | ||
| 51 | + } | ||
| 52 | + templates.append(f); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + return templates; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + void write(const Template &) | ||
| 59 | + { | ||
| 60 | + qFatal("turkGallery write not implemented."); | ||
| 61 | + } | ||
| 62 | +}; | ||
| 63 | + | ||
| 64 | +BR_REGISTER(Gallery, turkGallery) | ||
| 65 | + | ||
| 6 | static Template unmap(const Template &t, const QString& variable, const float maxVotes, const float maxRange, const float minRange, const bool classify, const bool consensusOnly) { | 66 | static Template unmap(const Template &t, const QString& variable, const float maxVotes, const float maxRange, const float minRange, const bool classify, const bool consensusOnly) { |
| 7 | // Create a new template matching the one containing the votes in the map structure | 67 | // Create a new template matching the one containing the votes in the map structure |
| 8 | // but remove the map structure | 68 | // but remove the map structure |