Commit fd2c2ed7b1238d2135f141c3a5516210f7362106

Authored by Tunde
1 parent 04e0d32a

Added Top Predictions Gallery. Very basic at the moment

Showing 1 changed file with 79 additions and 0 deletions
openbr/plugins/gallery.cpp
... ... @@ -1019,6 +1019,85 @@ class landmarksGallery : public Gallery
1019 1019  
1020 1020 BR_REGISTER(Gallery, landmarksGallery)
1021 1021  
  1022 +/*!
  1023 + * \ingroup galleries
  1024 + * \brief Prints top attributes.
  1025 + * \author Babatunde Ogunfemi \cite baba1472
  1026 + *
  1027 + * Prints to std out the top predictions. An optional threshold may be specified using a space ' ' separator:
  1028 + *
  1029 + */
  1030 +class topPredictionsGallery : public Gallery
  1031 +{
  1032 + Q_OBJECT
  1033 + Q_PROPERTY(float out_count READ get_out_count WRITE set_out_count RESET reset_out_count STORED false)
  1034 + BR_PROPERTY(float, out_count, 3)
  1035 +
  1036 + QMap<float, QString> attributes;
  1037 +
  1038 + ~topPredictionsGallery()
  1039 + {
  1040 + QString result = QString("# of attributes: %1").arg(QString::number(attributes.count()));
  1041 + QtUtils::writeFile(file.name, result);
  1042 + if (!attributes.isEmpty())
  1043 + {
  1044 + QMapIterator <float, QString> it(attributes);
  1045 + it.toBack();
  1046 + if (out_count > 1)
  1047 + {
  1048 + if (attributes.count() < out_count)
  1049 + out_count = attributes.count();
  1050 +
  1051 + for (int i = 0; i < out_count; i++)
  1052 + {
  1053 + it.previous();
  1054 + result = QString("%1) %2 : %3").arg(QString::number(i + 1), it.value(), QString::number((float)it.key()));
  1055 + QtUtils::writeFile(file.name, result);
  1056 + }
  1057 + }
  1058 + else
  1059 + {
  1060 + int count = 0;
  1061 + it.toBack();
  1062 + while (it.hasPrevious())
  1063 + {
  1064 + it.previous();
  1065 + if (it.key() >= out_count)
  1066 + {
  1067 + result = QString("%1) %2 : %3").arg(QString::number(count + 1), it.value(), QString::number((float)it.key()));
  1068 + QtUtils::writeFile(file.name, result);
  1069 + count++;
  1070 + }
  1071 + }
  1072 + }
  1073 + }
  1074 + }
  1075 +
  1076 + //Pure virtial function so needs an implementation
  1077 + TemplateList readBlock(bool *done)
  1078 + {
  1079 + *done = true;
  1080 + return TemplateList() << file;
  1081 + }
  1082 +
  1083 + void write(const Template &t)
  1084 + {
  1085 + QList<QString> keys = t.file.localKeys();
  1086 + for (int i = 0; i < keys.count(); i++)
  1087 + {
  1088 + QString key = keys.at(i);
  1089 + if (key.startsWith("predicted_"))
  1090 + {
  1091 + float val = t.file.get<float>(key);
  1092 + attributes.insert(val, key); //use float as key to keep in order
  1093 + }
  1094 +
  1095 + }
  1096 + }
  1097 +};
  1098 +
  1099 +BR_REGISTER(Gallery, topPredictionsGallery)
  1100 +
1022 1101 #ifdef CVMATIO
1023 1102  
1024 1103 using namespace cv;
... ...