Commit 091df77e8a2b2d0c3fa47f53ee5f3d35d4fec02f

Authored by Scott Klum
1 parent 1fd84565

Added TurkGallery

Showing 1 changed file with 66 additions and 0 deletions
openbr/plugins/gallery.cpp
... ... @@ -974,6 +974,72 @@ class landmarksGallery : public Gallery
974 974  
975 975 BR_REGISTER(Gallery, landmarksGallery)
976 976  
  977 +/*!
  978 + * \ingroup galleries
  979 + * \brief Treats each line as a file.
  980 + * \author Josh Klontz \cite jklontz
  981 + *
  982 + * Columns should be comma separated with first row containing headers.
  983 + * The first column in the file should be the path to the file to enroll.
  984 + * Other columns will be treated as file metadata.
  985 + *
  986 + * \see txtGallery
  987 + */
  988 +class turkGallery : public Gallery
  989 +{
  990 + Q_OBJECT
  991 +;
  992 + TemplateList readBlock(bool *done)
  993 + {
  994 + *done = true;
  995 + TemplateList templates;
  996 + if (!file.exists()) return templates;
  997 +
  998 + QStringList lines = QtUtils::readLines(file);
  999 + QRegExp regexp(",(?!(?:\\w+,?)+\\])");
  1000 +
  1001 + QStringList headers;
  1002 +
  1003 + if (!lines.isEmpty()) headers = lines.takeFirst().split(regexp);
  1004 +
  1005 + foreach (const QString &line, lines) {
  1006 + QStringList words = line.split(regexp);
  1007 + if (words.size() != headers.size()) continue;
  1008 + File f;
  1009 + f.name = words[0];
  1010 + f.set("Label", words[0].mid(0,5));
  1011 +
  1012 + for (int i=1; i<words.size(); i++) {
  1013 + QStringList categories = headers[i].split('[');
  1014 + categories.last().chop(1); // Remove trailing bracket
  1015 + QStringList types = categories.last().split(',');
  1016 +
  1017 + QStringList ratings = words[i].split(',');
  1018 + ratings.first() = ratings.first().mid(1); // Remove first bracket
  1019 + ratings.last().chop(1); // Remove trailing bracket
  1020 +
  1021 + if (types.size() != ratings.size()) continue;
  1022 +
  1023 + QMap<QString,QVariant> categoryMap;
  1024 + for (int j=0; j<types.size(); j++) categoryMap.insert(types[j],ratings[j]);
  1025 +
  1026 + f.set(categories[0], categoryMap);
  1027 + }
  1028 + templates.append(f);
  1029 + }
  1030 +
  1031 + return templates;
  1032 + }
  1033 +
  1034 + void write(const Template &t)
  1035 + {
  1036 + (void)t;
  1037 + qFatal("turkGallery write not implemented.");
  1038 + }
  1039 +};
  1040 +
  1041 +BR_REGISTER(Gallery, turkGallery)
  1042 +
977 1043 #ifdef CVMATIO
978 1044  
979 1045 using namespace cv;
... ...