Commit 35ab70c92afd319af7f22fc5e742267c2c33d021
1 parent
e2fb91d8
function cleanup
Showing
25 changed files
with
134 additions
and
198 deletions
app/examples/age_estimation.cpp
app/examples/face_recognition.cpp
| ... | ... | @@ -32,8 +32,8 @@ static void printTemplate(const br::Template &t) |
| 32 | 32 | { |
| 33 | 33 | printf("%s eyes: (%d, %d) (%d, %d)\n", |
| 34 | 34 | qPrintable(t.file.fileName()), |
| 35 | - t.file.getInt("Affine_0_X"), t.file.getInt("Affine_0_Y"), | |
| 36 | - t.file.getInt("Affine_1_X"), t.file.getInt("Affine_1_Y")); | |
| 35 | + t.file.get<int>("Affine_0_X"), t.file.get<int>("Affine_0_Y"), | |
| 36 | + t.file.get<int>("Affine_1_X"), t.file.get<int>("Affine_1_Y")); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | int main(int argc, char *argv[]) | ... | ... |
app/examples/gender_estimation.cpp
| ... | ... | @@ -31,7 +31,7 @@ static void printTemplate(const br::Template &t) |
| 31 | 31 | { |
| 32 | 32 | printf("%s gender: %s\n", |
| 33 | 33 | qPrintable(t.file.fileName()), |
| 34 | - t.file.getInt("Label") == 1 ? "Female" : "Male"); | |
| 34 | + t.file.get<int>("Label") == 1 ? "Female" : "Male"); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | int main(int argc, char *argv[]) | ... | ... |
app/openbr-gui/classifier.cpp
| ... | ... | @@ -39,19 +39,18 @@ void Classifier::_classify(File file) |
| 39 | 39 | { |
| 40 | 40 | QString key, value; |
| 41 | 41 | foreach (const File &f, Enroll(file.flat(), File("[algorithm=" + algorithm + "]"))) { |
| 42 | - qDebug() << f.flat(); | |
| 43 | 42 | if (!f.contains("Label")) |
| 44 | 43 | continue; |
| 45 | 44 | |
| 46 | 45 | if (algorithm == "GenderClassification") { |
| 47 | 46 | key = "Gender"; |
| 48 | - value = (f.getInt("Label", 0) == 0 ? "Male" : "Female"); | |
| 47 | + value = (f.get<int>("Label", 0) == 0 ? "Male" : "Female"); | |
| 49 | 48 | } else if (algorithm == "AgeRegression") { |
| 50 | 49 | key = "Age"; |
| 51 | - value = QString::number(int(f.getFloat("Label", 0)+0.5)) + " Years"; | |
| 50 | + value = QString::number(int(f.get<float>("Label", 0)+0.5)) + " Years"; | |
| 52 | 51 | } else { |
| 53 | 52 | key = algorithm; |
| 54 | - value = f.getString("Label"); | |
| 53 | + value = f.get<QString>("Label"); | |
| 55 | 54 | } |
| 56 | 55 | break; |
| 57 | 56 | } | ... | ... |
app/openbr-gui/gallerytoolbar.cpp
| ... | ... | @@ -117,7 +117,7 @@ void br::GalleryToolBar::checkWebcam() |
| 117 | 117 | void br::GalleryToolBar::enrollmentFinished() |
| 118 | 118 | { |
| 119 | 119 | if (files.isEmpty()) { |
| 120 | - if (input.getBool("enrollAll") && !tbWebcam.isChecked()) { | |
| 120 | + if (input.get<bool>("enrollAll", false) && !tbWebcam.isChecked()) { | |
| 121 | 121 | QMessageBox msgBox; |
| 122 | 122 | msgBox.setText("Quality test failed."); |
| 123 | 123 | msgBox.setInformativeText("Enroll anyway?"); |
| ... | ... | @@ -127,7 +127,7 @@ void br::GalleryToolBar::enrollmentFinished() |
| 127 | 127 | |
| 128 | 128 | if (ret == QMessageBox::Ok) { |
| 129 | 129 | br::File file = input; |
| 130 | - file.setBool("enrollAll", false); | |
| 130 | + file.set("enrollAll", false); | |
| 131 | 131 | enroll(file); |
| 132 | 132 | } |
| 133 | 133 | } | ... | ... |
app/openbr-gui/templatemetadata.cpp
| ... | ... | @@ -28,7 +28,7 @@ void br::TemplateMetadata::setFile(const br::File &file) |
| 28 | 28 | { |
| 29 | 29 | if (file.isNull()) lFile.clear(); |
| 30 | 30 | else lFile.setText("<b>File:</b> " + file.fileName()); |
| 31 | - lQuality.setText(QString("<b>Quality:</b> %1").arg(file.getBool("FTE") ? "Low" : "High")); | |
| 31 | + lQuality.setText(QString("<b>Quality:</b> %1").arg(file.get<bool>("FTE", false) ? "Low" : "High")); | |
| 32 | 32 | foreach (const ConditionalClassifier &classifier, conditionalClassifiers) |
| 33 | 33 | if (classifier.action->isVisible()) classifier.classifier->classify(file); |
| 34 | 34 | } | ... | ... |
app/openbr-gui/templateviewer.cpp
| ... | ... | @@ -40,9 +40,9 @@ void TemplateViewer::setFile(const File &file_) |
| 40 | 40 | // Update landmarks |
| 41 | 41 | landmarks.clear(); |
| 42 | 42 | if (file.contains("Affine_0_X") && file.contains("Affine_0_Y")) |
| 43 | - landmarks.append(QPointF(file.getFloat("Affine_0_X"), file.getFloat("Affine_0_Y"))); | |
| 43 | + landmarks.append(QPointF(file.get<float>("Affine_0_X"), file.get<float>("Affine_0_Y"))); | |
| 44 | 44 | if (file.contains("Affine_1_X") && file.contains("Affine_1_Y")) |
| 45 | - landmarks.append(QPointF(file.getFloat("Affine_1_X"), file.getFloat("Affine_1_Y"))); | |
| 45 | + landmarks.append(QPointF(file.get<float>("Affine_1_X"), file.get<float>("Affine_1_Y"))); | |
| 46 | 46 | while (landmarks.size() < NumLandmarks) |
| 47 | 47 | landmarks.append(QPointF()); |
| 48 | 48 | nearestLandmark = -1; | ... | ... |
sdk/core/bee.cpp
| ... | ... | @@ -71,7 +71,7 @@ FileList BEE::readSigset(const QString &sigset, bool ignoreMetadata) |
| 71 | 71 | newFile.append(file); |
| 72 | 72 | file = newFile; |
| 73 | 73 | } else if (!ignoreMetadata) { |
| 74 | - file.insert(key, value); | |
| 74 | + file.set(key, value); | |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| ... | ... | @@ -99,7 +99,7 @@ void BEE::writeSigset(const QString &sigset, const br::FileList &files, bool ign |
| 99 | 99 | QStringList metadata; |
| 100 | 100 | if (!ignoreMetadata) |
| 101 | 101 | foreach (const QString &key, file.localKeys()) |
| 102 | - metadata.append(key+"=\""+file.getString(key, "?")+"\""); | |
| 102 | + metadata.append(key+"=\""+file.get<QString>(key, "?")+"\""); | |
| 103 | 103 | lines.append("\t<biometric-signature name=\"" + file.subject() +"\">"); |
| 104 | 104 | lines.append("\t\t<presentation file-name=\"" + file.name + "\" " + metadata.join(" ") + "/>"); |
| 105 | 105 | lines.append("\t</biometric-signature>"); |
| ... | ... | @@ -113,19 +113,19 @@ Mat readMatrix(const br::File &matrix) |
| 113 | 113 | { |
| 114 | 114 | // Special case matrix construction |
| 115 | 115 | if (matrix == "Identity") { |
| 116 | - int rows = matrix.getInt("rows", -1); | |
| 117 | - int columns = matrix.getInt("columns", -1); | |
| 118 | - const int size = matrix.getInt("size", -1); | |
| 116 | + int rows = matrix.get<int>("rows", -1); | |
| 117 | + int columns = matrix.get<int>("columns", -1); | |
| 118 | + const int size = matrix.get<int>("size", -1); | |
| 119 | 119 | if (size != -1) { |
| 120 | 120 | if (rows == -1) rows = size; |
| 121 | 121 | if (columns == -1) columns = size; |
| 122 | 122 | } |
| 123 | - const int step = matrix.getInt("step", 1); | |
| 123 | + const int step = matrix.get<int>("step", 1); | |
| 124 | 124 | if (rows % step != 0) qFatal("Step does not divide rows evenly."); |
| 125 | 125 | if (columns % step != 0) qFatal("Step does not divide columns evenly."); |
| 126 | 126 | |
| 127 | 127 | if (sizeof(T) == sizeof(BEE::Mask_t)) { |
| 128 | - const bool selfSimilar = matrix.getBool("selfSimilar"); | |
| 128 | + const bool selfSimilar = matrix.get<bool>("selfSimilar", false); | |
| 129 | 129 | |
| 130 | 130 | Mat m(rows, columns, CV_8UC1); |
| 131 | 131 | m.setTo(BEE::NonMatch); |
| ... | ... | @@ -171,8 +171,8 @@ Mat readMatrix(const br::File &matrix) |
| 171 | 171 | file.close(); |
| 172 | 172 | |
| 173 | 173 | Mat result; |
| 174 | - if (isDistance ^ matrix.getBool("negate")) m.convertTo(result, -1, -1); | |
| 175 | - else result = m.clone(); | |
| 174 | + if (isDistance ^ matrix.get<bool>("negate", false)) m.convertTo(result, -1, -1); | |
| 175 | + else result = m.clone(); | |
| 176 | 176 | return result; |
| 177 | 177 | } |
| 178 | 178 | ... | ... |
sdk/core/core.cpp
| ... | ... | @@ -194,7 +194,7 @@ struct AlgorithmCore |
| 194 | 194 | |
| 195 | 195 | void compare(File targetGallery, File queryGallery, File output) |
| 196 | 196 | { |
| 197 | - if (output.exists() && output.getBool("cache")) return; | |
| 197 | + if (output.exists() && output.get<bool>("cache", false)) return; | |
| 198 | 198 | if (queryGallery == ".") queryGallery = targetGallery; |
| 199 | 199 | |
| 200 | 200 | QScopedPointer<Gallery> t, q; |
| ... | ... | @@ -316,14 +316,14 @@ void br::Train(const File &input, const File &model) |
| 316 | 316 | { |
| 317 | 317 | qDebug("Training on %s%s", qPrintable(input.flat()), |
| 318 | 318 | model.isNull() ? "" : qPrintable(" to " + model.flat())); |
| 319 | - AlgorithmManager::getAlgorithm(model.getString("algorithm"))->train(input, model); | |
| 319 | + AlgorithmManager::getAlgorithm(model.get<QString>("algorithm"))->train(input, model); | |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | FileList br::Enroll(const File &input, const File &gallery) |
| 323 | 323 | { |
| 324 | 324 | qDebug("Enrolling %s%s", qPrintable(input.flat()), |
| 325 | 325 | gallery.isNull() ? "" : qPrintable(" to " + gallery.flat())); |
| 326 | - return AlgorithmManager::getAlgorithm(gallery.getString("algorithm"))->enroll(input, gallery); | |
| 326 | + return AlgorithmManager::getAlgorithm(gallery.get<QString>("algorithm"))->enroll(input, gallery); | |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | void br::Compare(const File &targetGallery, const File &queryGallery, const File &output) |
| ... | ... | @@ -331,7 +331,7 @@ void br::Compare(const File &targetGallery, const File &queryGallery, const File |
| 331 | 331 | qDebug("Comparing %s and %s%s", qPrintable(targetGallery.flat()), |
| 332 | 332 | qPrintable(queryGallery.flat()), |
| 333 | 333 | output.isNull() ? "" : qPrintable(" to " + output.flat())); |
| 334 | - AlgorithmManager::getAlgorithm(output.getString("algorithm"))->compare(targetGallery, queryGallery, output); | |
| 334 | + AlgorithmManager::getAlgorithm(output.get<QString>("algorithm"))->compare(targetGallery, queryGallery, output); | |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | void br::Convert(const File &src, const File &dst) | ... | ... |
sdk/core/plot.cpp
| ... | ... | @@ -119,8 +119,8 @@ float Evaluate(const QString &simmat, const QString &mask, const QString &csv) |
| 119 | 119 | // Read files |
| 120 | 120 | const Mat scores = BEE::readSimmat(simmat); |
| 121 | 121 | File maskFile(mask); |
| 122 | - maskFile.insert("rows", scores.rows); | |
| 123 | - maskFile.insert("columns", scores.cols); | |
| 122 | + maskFile.set("rows", scores.rows); | |
| 123 | + maskFile.set("columns", scores.cols); | |
| 124 | 124 | const Mat masks = BEE::readMask(maskFile); |
| 125 | 125 | if (scores.size() != masks.size()) qFatal("Simmat/Mask size mismatch."); |
| 126 | 126 | |
| ... | ... | @@ -416,7 +416,7 @@ struct RPlot |
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - const QString &smooth = destination.getString("smooth", ""); | |
| 419 | + const QString &smooth = destination.get<QString>("smooth", ""); | |
| 420 | 420 | major.smooth = !smooth.isEmpty() && (major.header == smooth) && (major.size > 1); |
| 421 | 421 | minor.smooth = !smooth.isEmpty() && (minor.header == smooth) && (minor.size > 1); |
| 422 | 422 | if (major.smooth) major.size = 1; | ... | ... |
sdk/openbr_plugin.cpp
| ... | ... | @@ -61,7 +61,7 @@ QString File::hash() const |
| 61 | 61 | void File::append(const QHash<QString, QVariant> &metadata) |
| 62 | 62 | { |
| 63 | 63 | foreach (const QString &key, metadata.keys()) |
| 64 | - insert(key, metadata[key]); | |
| 64 | + set(key, metadata[key]); | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | void File::append(const File &other) |
| ... | ... | @@ -70,7 +70,7 @@ void File::append(const File &other) |
| 70 | 70 | if (name.isEmpty()) { |
| 71 | 71 | name = other.name; |
| 72 | 72 | } else { |
| 73 | - if (!contains("separator")) insert("separator", ";"); | |
| 73 | + if (!contains("separator")) set("separator", ";"); | |
| 74 | 74 | name += value("separator").toString() + other.name; |
| 75 | 75 | } |
| 76 | 76 | } |
| ... | ... | @@ -153,77 +153,6 @@ void File::set(const QString &key, const QVariant &value) |
| 153 | 153 | m_metadata.insert(key, value); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | -QVariant File::get(const QString &key) const | |
| 157 | -{ | |
| 158 | - if (!contains(key)) qFatal("Missing key: %s", qPrintable(key)); | |
| 159 | - return value(key); | |
| 160 | -} | |
| 161 | - | |
| 162 | -QVariant File::get(const QString &key, const QVariant &defaultValue) const | |
| 163 | -{ | |
| 164 | - if (!contains(key)) return defaultValue; | |
| 165 | - return value(key); | |
| 166 | -} | |
| 167 | - | |
| 168 | -bool File::getBool(const QString &key) const | |
| 169 | -{ | |
| 170 | - if (!contains(key)) return false; | |
| 171 | - QString v = value(key).toString(); | |
| 172 | - if (v.isEmpty() || (v == "true")) return true; | |
| 173 | - if (v == "false") return false; | |
| 174 | - return v.toInt(); | |
| 175 | -} | |
| 176 | - | |
| 177 | -void File::setBool(const QString &key, bool value) | |
| 178 | -{ | |
| 179 | - if (value) m_metadata.insert(key, QVariant()); | |
| 180 | - else m_metadata.remove(key); | |
| 181 | -} | |
| 182 | - | |
| 183 | -int File::getInt(const QString &key) const | |
| 184 | -{ | |
| 185 | - if (!contains(key)) qFatal("Missing key: %s", qPrintable(key)); | |
| 186 | - bool ok; int result = value(key).toInt(&ok); | |
| 187 | - if (!ok) qFatal("Invalid conversion from: %s", qPrintable(getString(key))); | |
| 188 | - return result; | |
| 189 | -} | |
| 190 | - | |
| 191 | -int File::getInt(const QString &key, int defaultValue) const | |
| 192 | -{ | |
| 193 | - if (!contains(key)) return defaultValue; | |
| 194 | - bool ok; int result = value(key).toInt(&ok); | |
| 195 | - if (!ok) return defaultValue; | |
| 196 | - return result; | |
| 197 | -} | |
| 198 | - | |
| 199 | -float File::getFloat(const QString &key) const | |
| 200 | -{ | |
| 201 | - if (!contains(key)) qFatal("Missing key: %s", qPrintable(key)); | |
| 202 | - bool ok; float result = value(key).toFloat(&ok); | |
| 203 | - if (!ok) qFatal("Invalid conversion from: %s", qPrintable(getString(key))); | |
| 204 | - return result; | |
| 205 | -} | |
| 206 | - | |
| 207 | -float File::getFloat(const QString &key, float defaultValue) const | |
| 208 | -{ | |
| 209 | - if (!contains(key)) return defaultValue; | |
| 210 | - bool ok; float result = value(key).toFloat(&ok); | |
| 211 | - if (!ok) return defaultValue; | |
| 212 | - return result; | |
| 213 | -} | |
| 214 | - | |
| 215 | -QString File::getString(const QString &key) const | |
| 216 | -{ | |
| 217 | - if (!contains(key)) qFatal("Missing key: %s", qPrintable(key)); | |
| 218 | - return value(key).toString(); | |
| 219 | -} | |
| 220 | - | |
| 221 | -QString File::getString(const QString &key, const QString &defaultValue) const | |
| 222 | -{ | |
| 223 | - if (!contains(key)) return defaultValue; | |
| 224 | - return value(key).toString(); | |
| 225 | -} | |
| 226 | - | |
| 227 | 156 | QList<QPointF> File::landmarks() const |
| 228 | 157 | { |
| 229 | 158 | QList<QPointF> landmarks; |
| ... | ... | @@ -245,7 +174,7 @@ QList<QPointF> File::namedLandmarks() const |
| 245 | 174 | keys.contains(keyBaseName+"_Height") || |
| 246 | 175 | keys.contains(keyBaseName+"_Radius")) |
| 247 | 176 | continue; |
| 248 | - landmarks.append(QPointF(getFloat(keyBaseName+"_X"), getFloat(keyBaseName+"_Y"))); | |
| 177 | + landmarks.append(QPointF(get<float>(keyBaseName+"_X"), get<float>(keyBaseName+"_Y"))); | |
| 249 | 178 | } |
| 250 | 179 | return landmarks; |
| 251 | 180 | } |
| ... | ... | @@ -325,10 +254,10 @@ void File::init(const QString &file) |
| 325 | 254 | QStringList words = QtUtils::parse(parameters[i], '='); |
| 326 | 255 | QtUtils::checkArgsSize("File", words, 1, 2); |
| 327 | 256 | if (words.size() < 2) { |
| 328 | - if (unnamed) insertParameter(i, words[0]); | |
| 329 | - else insert(words[0], QVariant()); | |
| 257 | + if (unnamed) setParameter(i, words[0]); | |
| 258 | + else set(words[0], QVariant()); | |
| 330 | 259 | } else { |
| 331 | - insert(words[0], words[1]); | |
| 260 | + set(words[0], words[1]); | |
| 332 | 261 | } |
| 333 | 262 | } |
| 334 | 263 | name = name.left(index); |
| ... | ... | @@ -391,9 +320,8 @@ void FileList::sort(const QString& key) |
| 391 | 320 | FileList sortedList; |
| 392 | 321 | |
| 393 | 322 | for (int i = 0; i < size(); i++) { |
| 394 | - if (at(i).contains(key)) { | |
| 395 | - metadata.append(at(i).get(key).toString()); | |
| 396 | - } | |
| 323 | + if (at(i).contains(key)) | |
| 324 | + metadata.append(at(i).get<QString>(key)); | |
| 397 | 325 | else sortedList.push_back(at(i)); |
| 398 | 326 | } |
| 399 | 327 | |
| ... | ... | @@ -416,7 +344,7 @@ QList<int> FileList::crossValidationPartitions() const |
| 416 | 344 | { |
| 417 | 345 | QList<int> crossValidationPartitions; crossValidationPartitions.reserve(size()); |
| 418 | 346 | foreach (const File &f, *this) |
| 419 | - crossValidationPartitions.append(f.getInt("Cross_Validation_Partition", 0)); | |
| 347 | + crossValidationPartitions.append(f.get<int>("Cross_Validation_Partition", 0)); | |
| 420 | 348 | return crossValidationPartitions; |
| 421 | 349 | } |
| 422 | 350 | |
| ... | ... | @@ -424,7 +352,7 @@ int FileList::failures() const |
| 424 | 352 | { |
| 425 | 353 | int failures = 0; |
| 426 | 354 | foreach (const File &file, *this) |
| 427 | - if (file.getBool("FTO") || file.getBool("FTE")) | |
| 355 | + if (file.get<bool>("FTO", false) || file.get<bool>("FTE", false)) | |
| 428 | 356 | failures++; |
| 429 | 357 | return failures; |
| 430 | 358 | } |
| ... | ... | @@ -447,9 +375,9 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) |
| 447 | 375 | foreach (const br::File &file, gallery.split()) { |
| 448 | 376 | QScopedPointer<Gallery> i(Gallery::make(file)); |
| 449 | 377 | TemplateList newTemplates = i->read(); |
| 450 | - newTemplates = newTemplates.mid(gallery.getInt("pos", 0), gallery.getInt("length", -1)); | |
| 451 | - if (gallery.getBool("reduce")) newTemplates = newTemplates.reduced(); | |
| 452 | - const int crossValidate = gallery.getInt("crossValidate"); | |
| 378 | + newTemplates = newTemplates.mid(gallery.get<int>("pos", 0), gallery.get<int>("length", -1)); | |
| 379 | + if (gallery.get<bool>("reduce", false)) newTemplates = newTemplates.reduced(); | |
| 380 | + const int crossValidate = gallery.get<int>("crossValidate"); | |
| 453 | 381 | if (crossValidate > 0) srand(0); |
| 454 | 382 | |
| 455 | 383 | // If file is a Format not a Gallery |
| ... | ... | @@ -460,11 +388,11 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) |
| 460 | 388 | for (int i=0; i<newTemplates.size(); i++) { |
| 461 | 389 | newTemplates[i].file.append(gallery.localMetadata()); |
| 462 | 390 | newTemplates[i].file.append(file.localMetadata()); |
| 463 | - newTemplates[i].file.insert("Index", i+templates.size()); | |
| 464 | - if (crossValidate > 0) newTemplates[i].file.insert("Cross_Validation_Partition", rand()%crossValidate); | |
| 391 | + newTemplates[i].file.set("Index", i+templates.size()); | |
| 392 | + if (crossValidate > 0) newTemplates[i].file.set("Cross_Validation_Partition", rand()%crossValidate); | |
| 465 | 393 | } |
| 466 | 394 | |
| 467 | - if (!templates.isEmpty() && gallery.getBool("merge")) { | |
| 395 | + if (!templates.isEmpty() && gallery.get<bool>("merge", false)) { | |
| 468 | 396 | if (newTemplates.size() != templates.size()) |
| 469 | 397 | qFatal("Inputs must be the same size in order to merge."); |
| 470 | 398 | for (int i=0; i<templates.size(); i++) |
| ... | ... | @@ -1136,7 +1064,7 @@ static TemplateList Downsample(const TemplateList &templates, const Transform *t |
| 1136 | 1064 | const int selectedLabel = selectedLabels[i]; |
| 1137 | 1065 | QList<int> indices; |
| 1138 | 1066 | for (int j=0; j<allLabels.size(); j++) |
| 1139 | - if ((allLabels[j] == selectedLabel) && (!templates.value(j).file.getBool("FTE"))) | |
| 1067 | + if ((allLabels[j] == selectedLabel) && (!templates.value(j).file.get<bool>("FTE", false))) | |
| 1140 | 1068 | indices.append(j); |
| 1141 | 1069 | |
| 1142 | 1070 | std::random_shuffle(indices.begin(), indices.end()); |
| ... | ... | @@ -1320,7 +1248,7 @@ static void _project(const Transform *transform, const Template *src, Template * |
| 1320 | 1248 | } catch (...) { |
| 1321 | 1249 | qWarning("Exception triggered when processing %s with transform %s", qPrintable(src->file.flat()), qPrintable(transform->objectName())); |
| 1322 | 1250 | *dst = Template(src->file); |
| 1323 | - dst->file.setBool("FTE"); | |
| 1251 | + dst->file.set("FTE", true); | |
| 1324 | 1252 | } |
| 1325 | 1253 | } |
| 1326 | 1254 | |
| ... | ... | @@ -1331,7 +1259,7 @@ static void _backProject(const Transform *transform, const Template *dst, Templa |
| 1331 | 1259 | } catch (...) { |
| 1332 | 1260 | qWarning("Exception triggered when processing %s with transform %s", qPrintable(src->file.flat()), qPrintable(transform->objectName())); |
| 1333 | 1261 | *src = Template(dst->file); |
| 1334 | - src->file.setBool("FTE"); | |
| 1262 | + src->file.set("FTE", true); | |
| 1335 | 1263 | } |
| 1336 | 1264 | } |
| 1337 | 1265 | ... | ... |
sdk/openbr_plugin.h
| ... | ... | @@ -156,7 +156,7 @@ struct BR_EXPORT File |
| 156 | 156 | |
| 157 | 157 | File() {} |
| 158 | 158 | File(const QString &file) { init(file); } /*!< \brief Construct a file from a string. */ |
| 159 | - File(const QString &file, const QVariant &label) { init(file); insert("Label", label); } /*!< \brief Construct a file from a string and assign a label. */ | |
| 159 | + File(const QString &file, const QVariant &label) { init(file); set("Label", label); } /*!< \brief Construct a file from a string and assign a label. */ | |
| 160 | 160 | File(const char *file) { init(file); } /*!< \brief Construct a file from a c-style string. */ |
| 161 | 161 | inline operator QString() const { return name; } /*!< \brief Returns #name. */ |
| 162 | 162 | QString flat() const; /*!< \brief A stringified version of the file with metadata. */ |
| ... | ... | @@ -165,15 +165,14 @@ struct BR_EXPORT File |
| 165 | 165 | |
| 166 | 166 | inline QList<QString> localKeys() const { return m_metadata.keys(); } /*!< \brief Returns the private metadata keys. */ |
| 167 | 167 | inline QHash<QString,QVariant> localMetadata() const { return m_metadata; } /*!< \brief Returns the private metadata. */ |
| 168 | - inline void insert(const QString &key, const QVariant &value) { set(key, value); } /*!< \brief Equivalent to set(). */ | |
| 169 | 168 | void append(const QHash<QString,QVariant> &localMetadata); /*!< \brief Add new metadata fields. */ |
| 170 | 169 | void append(const File &other); /*!< \brief Append another file using \c separator. */ |
| 171 | 170 | QList<File> split() const; /*!< \brief Split the file using \c separator. */ |
| 172 | 171 | QList<File> split(const QString &separator) const; /*!< \brief Split the file. */ |
| 173 | 172 | |
| 174 | - inline void insertParameter(int index, const QVariant &value) { insert("_Arg" + QString::number(index), value); } /*!< \brief Insert a keyless value. */ | |
| 175 | - inline bool containsParameter(int index) const { return m_metadata.contains("_Arg" + QString::number(index)); } /*!< \brief Check for the existence of a keyless value. */ | |
| 176 | - inline QVariant parameter(int index) const { return m_metadata.value("_Arg" + QString::number(index)); } /*!< \brief Retrieve a keyless value. */ | |
| 173 | + inline void setParameter(int index, const QVariant &value) { set("_Arg" + QString::number(index), value); } /*!< \brief Insert a keyless value. */ | |
| 174 | + inline bool containsParameter(int index) const { return contains("_Arg" + QString::number(index)); } /*!< \brief Check for the existence of a keyless value. */ | |
| 175 | + inline QVariant getParameter(int index) const { return get<QVariant>("_Arg" + QString::number(index)); } /*!< \brief Retrieve a keyless value. */ | |
| 177 | 176 | |
| 178 | 177 | inline bool operator==(const char* other) const { return name == other; } /*!< \brief Compare name to c-style string. */ |
| 179 | 178 | inline bool operator==(const File &other) const { return (name == other.name) && (m_metadata == other.m_metadata); } /*!< \brief Compare name and metadata for equality. */ |
| ... | ... | @@ -198,22 +197,32 @@ struct BR_EXPORT File |
| 198 | 197 | QVariant value(const QString &key) const; /*!< \brief Returns the value for the specified key. */ |
| 199 | 198 | static QString subject(int label); /*!< \brief Looks up the subject for the provided label. */ |
| 200 | 199 | inline QString subject() const { return subject(label()); } /*!< \brief Looks up the subject from the file's label. */ |
| 201 | - inline bool failed() const { return getBool("FTE") || getBool("FTO"); } /*!< \brief Returns \c true if the file failed to open or enroll, \c false otherwise. */ | |
| 200 | + inline bool failed() const { return get<bool>("FTE", false) || get<bool>("FTO", false); } /*!< \brief Returns \c true if the file failed to open or enroll, \c false otherwise. */ | |
| 202 | 201 | |
| 203 | 202 | void remove(const QString &key); /*!< \brief Remove the metadata key. */ |
| 204 | 203 | void set(const QString &key, const QVariant &value); /*!< \brief Insert or overwrite the metadata key with the specified value. */ |
| 205 | - QVariant get(const QString &key) const; /*!< \brief Returns a QVariant for the key, throwing an error if the key does not exist. */ | |
| 206 | - QVariant get(const QString &key, const QVariant &value) const; /*!< \brief Returns a QVariant for the key, returning \em defaultValue if the key does not exist. */ | |
| 207 | 204 | float label() const; /*!< \brief Convenience function for retrieving the file's \c Label. */ |
| 208 | - inline void setLabel(float label) { insert("Label", label); } /*!< \brief Convenience function for setting the file's \c Label. */ | |
| 209 | - bool getBool(const QString &key) const; /*!< \brief Returns a boolean value for the key. */ | |
| 210 | - void setBool(const QString &key, bool value = true); /*!< \brief Sets a boolean value for the key. */ | |
| 211 | - int getInt(const QString &key) const; /*!< \brief Returns an int value for the key, throwing an error if the key does not exist. */ | |
| 212 | - int getInt(const QString &key, int defaultValue) const; /*!< \brief Returns an int value for the key, returning \em defaultValue if the key does not exist. */ | |
| 213 | - float getFloat(const QString &key) const; /*!< \brief Returns a float value for the key, throwing an error if the key does not exist. */ | |
| 214 | - float getFloat(const QString &key, float defaultValue) const; /*!< \brief Returns a float value for the key, returning \em defaultValue if the key does not exist. */ | |
| 215 | - QString getString(const QString &key) const; /*!< \brief Returns a string value for the key, throwing an error if the key does not exist. */ | |
| 216 | - QString getString(const QString &key, const QString &defaultValue) const; /*!< \brief Returns a string value for the key, returning \em defaultValue if the key does not exist. */ | |
| 205 | + inline void setLabel(float label) { set("Label", label); } /*!< \brief Convenience function for setting the file's \c Label. */ | |
| 206 | + | |
| 207 | + /*!< \brief Returns a value for the key, throwing an error if the key does not exist. */ | |
| 208 | + template <typename T> | |
| 209 | + T get(const QString &key) const | |
| 210 | + { | |
| 211 | + if (!contains(key)) qFatal("Missing key: %s", qPrintable(key)); | |
| 212 | + QVariant variant = value(key); | |
| 213 | + if (!variant.canConvert<T>()) qFatal("Can't convert: %s", qPrintable(key)); | |
| 214 | + return variant.value<T>(); | |
| 215 | + } | |
| 216 | + | |
| 217 | + /*!< \brief Returns a value for the key, returning \em defaultValue if the key does not exist or can't be converted. */ | |
| 218 | + template <typename T> | |
| 219 | + T get(const QString &key, const T &defaultValue) const | |
| 220 | + { | |
| 221 | + if (!contains(key)) return defaultValue; | |
| 222 | + QVariant variant = value(key); | |
| 223 | + if (!variant.canConvert<T>()) return defaultValue; | |
| 224 | + return variant.value<T>(); | |
| 225 | + } | |
| 217 | 226 | |
| 218 | 227 | QList<QPointF> landmarks() const; /*!< \brief Returns the file's landmark list. */ |
| 219 | 228 | QList<QPointF> namedLandmarks() const; /*!< \brief Returns landmarks derived from metadata keys. */ | ... | ... |
sdk/plugins/cascade.cpp
| ... | ... | @@ -75,10 +75,10 @@ class CascadeTransform : public UntrainableTransform |
| 75 | 75 | { |
| 76 | 76 | CascadeClassifier *cascade = cascadeResource.acquire(); |
| 77 | 77 | vector<Rect> rects; |
| 78 | - cascade->detectMultiScale(src, rects, 1.2, 5, src.file.getBool("enrollAll") ? 0 : CV_HAAR_FIND_BIGGEST_OBJECT, Size(minSize, minSize)); | |
| 78 | + cascade->detectMultiScale(src, rects, 1.2, 5, src.file.get<bool>("enrollAll", false) ? 0 : CV_HAAR_FIND_BIGGEST_OBJECT, Size(minSize, minSize)); | |
| 79 | 79 | cascadeResource.release(cascade); |
| 80 | 80 | |
| 81 | - if (!src.file.getBool("enrollAll") && rects.empty()) | |
| 81 | + if (!src.file.get<bool>("enrollAll", false) && rects.empty()) | |
| 82 | 82 | rects.push_back(Rect(0, 0, src.m().cols, src.m().rows)); |
| 83 | 83 | |
| 84 | 84 | foreach (const Rect &rect, rects) { | ... | ... |
sdk/plugins/eigen3.cpp
| ... | ... | @@ -228,7 +228,7 @@ class DFFSTransform : public Transform |
| 228 | 228 | void project(const Template &src, Template &dst) const |
| 229 | 229 | { |
| 230 | 230 | dst = src; |
| 231 | - dst.file.insert("DFFS", sqrt(pca.residualReconstructionError((*cvtFloat)(src)))); | |
| 231 | + dst.file.set("DFFS", sqrt(pca.residualReconstructionError((*cvtFloat)(src)))); | |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | void store(QDataStream &stream) const | ... | ... |
sdk/plugins/eyes.cpp
| ... | ... | @@ -185,10 +185,10 @@ private: |
| 185 | 185 | dst = src; |
| 186 | 186 | dst.file.appendLandmark(QPointF(first_eye_x, first_eye_y)); |
| 187 | 187 | dst.file.appendLandmark(QPointF(second_eye_x, second_eye_y)); |
| 188 | - dst.file.insert("ASEF_Right_Eye_X", first_eye_x); | |
| 189 | - dst.file.insert("ASEF_Right_Eye_Y", first_eye_y); | |
| 190 | - dst.file.insert("ASEF_Left_Eye_X", second_eye_x); | |
| 191 | - dst.file.insert("ASEF_Left_Eye_Y", second_eye_y); | |
| 188 | + dst.file.set("ASEF_Right_Eye_X", first_eye_x); | |
| 189 | + dst.file.set("ASEF_Right_Eye_Y", first_eye_y); | |
| 190 | + dst.file.set("ASEF_Left_Eye_X", second_eye_x); | |
| 191 | + dst.file.set("ASEF_Left_Eye_Y", second_eye_y); | |
| 192 | 192 | } |
| 193 | 193 | }; |
| 194 | 194 | ... | ... |
sdk/plugins/format.cpp
| ... | ... | @@ -217,11 +217,11 @@ class DefaultFormat : public Format |
| 217 | 217 | } else { |
| 218 | 218 | QString fileName = file.name; |
| 219 | 219 | if (!QFileInfo(fileName).exists()) { |
| 220 | - fileName = file.getString("path") + "/" + file.name; | |
| 220 | + fileName = file.get<QString>("path") + "/" + file.name; | |
| 221 | 221 | if (!QFileInfo(fileName).exists()) { |
| 222 | 222 | fileName = file.fileName(); |
| 223 | 223 | if (!QFileInfo(fileName).exists()) { |
| 224 | - fileName = file.getString("path") + "/" + file.fileName(); | |
| 224 | + fileName = file.get<QString>("path") + "/" + file.fileName(); | |
| 225 | 225 | if (!QFileInfo(fileName).exists()) return t; |
| 226 | 226 | } |
| 227 | 227 | } |
| ... | ... | @@ -604,7 +604,7 @@ class xmlFormat : public Format |
| 604 | 604 | (e.tagName() == "RPROFILE")) { |
| 605 | 605 | // Ignore these other image fields for now |
| 606 | 606 | } else { |
| 607 | - t.file.insert(e.tagName(), e.text()); | |
| 607 | + t.file.set(e.tagName(), e.text()); | |
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | fileNode = fileNode.nextSibling(); |
| ... | ... | @@ -614,11 +614,11 @@ class xmlFormat : public Format |
| 614 | 614 | |
| 615 | 615 | // Calculate age |
| 616 | 616 | if (t.file.contains("DOB")) { |
| 617 | - const QDate dob = QDate::fromString(t.file.getString("DOB").left(10), "yyyy-MM-dd"); | |
| 617 | + const QDate dob = QDate::fromString(t.file.get<QString>("DOB").left(10), "yyyy-MM-dd"); | |
| 618 | 618 | const QDate current = QDate::currentDate(); |
| 619 | 619 | int age = current.year() - dob.year(); |
| 620 | 620 | if (current.month() < dob.month()) age--; |
| 621 | - t.file.insert("Age", age); | |
| 621 | + t.file.set("Age", age); | |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | return t; | ... | ... |
sdk/plugins/gallery.cpp
| ... | ... | @@ -47,7 +47,7 @@ class galGallery : public Gallery |
| 47 | 47 | void init() |
| 48 | 48 | { |
| 49 | 49 | gallery.setFileName(file); |
| 50 | - if (file.getBool("remove")) | |
| 50 | + if (file.get<bool>("remove", false)) | |
| 51 | 51 | gallery.remove(); |
| 52 | 52 | QtUtils::touchDir(gallery); |
| 53 | 53 | if (!gallery.open(QFile::ReadWrite | QFile::Append)) |
| ... | ... | @@ -352,7 +352,7 @@ class csvGallery : public Gallery |
| 352 | 352 | for (int i=0; i<rows; i++) |
| 353 | 353 | for (int j=0; j<columns; j++) |
| 354 | 354 | if (keys[j] == "Label") output->setRelative(files[i].label(), i, j); |
| 355 | - else output->setRelative(files[i].getFloat(keys[j], std::numeric_limits<float>::quiet_NaN()), i, j); | |
| 355 | + else output->setRelative(files[i].get<float>(keys[j], std::numeric_limits<float>::quiet_NaN()), i, j); | |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | TemplateList readBlock(bool *done) |
| ... | ... | @@ -465,9 +465,9 @@ class dbGallery : public Gallery |
| 465 | 465 | TemplateList readBlock(bool *done) |
| 466 | 466 | { |
| 467 | 467 | TemplateList templates; |
| 468 | - br::File import = file.getString("import", ""); | |
| 469 | - QString query = file.getString("query"); | |
| 470 | - QString subset = file.getString("subset", ""); | |
| 468 | + br::File import = file.get<QString>("import", ""); | |
| 469 | + QString query = file.get<QString>("query"); | |
| 470 | + QString subset = file.get<QString>("subset", ""); | |
| 471 | 471 | |
| 472 | 472 | #ifndef BR_EMBEDDED |
| 473 | 473 | QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); | ... | ... |
sdk/plugins/keypoint.cpp
| ... | ... | @@ -54,7 +54,7 @@ class KeyPointDetectorTransform : public UntrainableTransform |
| 54 | 54 | featureDetector->detect(src, keyPoints); |
| 55 | 55 | } catch (...) { |
| 56 | 56 | qWarning("Key point detection failed for file %s", qPrintable(src.file.name)); |
| 57 | - dst.file.setBool("FTE"); | |
| 57 | + dst.file.set("FTE", true); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | QList<Rect> ROIs; | ... | ... |
sdk/plugins/meta.cpp
| ... | ... | @@ -31,12 +31,12 @@ static TemplateList Expanded(const TemplateList &templates) |
| 31 | 31 | TemplateList expanded; |
| 32 | 32 | foreach (const Template &t, templates) { |
| 33 | 33 | if (t.isEmpty()) { |
| 34 | - if (!t.file.getBool("enrollAll")) | |
| 34 | + if (!t.file.get<bool>("enrollAll", false)) | |
| 35 | 35 | expanded.append(t); |
| 36 | 36 | continue; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - const bool fte = t.file.getBool("FTE"); | |
| 39 | + const bool fte = t.file.get<bool>("FTE", false); | |
| 40 | 40 | QList<QPointF> landmarks = t.file.landmarks(); |
| 41 | 41 | QList<QRectF> ROIs = t.file.ROIs(); |
| 42 | 42 | if (landmarks.size() % t.size() != 0) qFatal("Uneven landmark count."); |
| ... | ... | @@ -45,7 +45,7 @@ static TemplateList Expanded(const TemplateList &templates) |
| 45 | 45 | const int ROIStep = ROIs.size() / t.size(); |
| 46 | 46 | |
| 47 | 47 | for (int i=0; i<t.size(); i++) { |
| 48 | - if (!fte || !t.file.getBool("enrollAll")) { | |
| 48 | + if (!fte || !t.file.get<bool>("enrollAll", false)) { | |
| 49 | 49 | expanded.append(Template(t.file, t[i])); |
| 50 | 50 | expanded.last().file.setROIs(ROIs.mid(i*ROIStep, ROIStep)); |
| 51 | 51 | expanded.last().file.setLandmarks(landmarks.mid(i*landmarkStep, landmarkStep)); |
| ... | ... | @@ -233,7 +233,7 @@ class PipeTransform : public CompositeTransform |
| 233 | 233 | } catch (...) { |
| 234 | 234 | qWarning("Exception triggered when processing %s with transform %s", qPrintable(dst.file.flat()), qPrintable(f->objectName())); |
| 235 | 235 | src = Template(src.file); |
| 236 | - src.file.setBool("FTE"); | |
| 236 | + src.file.set("FTE", true); | |
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | } |
| ... | ... | @@ -247,7 +247,7 @@ class PipeTransform : public CompositeTransform |
| 247 | 247 | } catch (...) { |
| 248 | 248 | qWarning("Exception triggered when processing %s with transform %s", qPrintable(src.file.flat()), qPrintable(f->objectName())); |
| 249 | 249 | dst = Template(src.file); |
| 250 | - dst.file.setBool("FTE"); | |
| 250 | + dst.file.set("FTE", true); | |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | } |
| ... | ... | @@ -310,7 +310,7 @@ protected: |
| 310 | 310 | } catch (...) { |
| 311 | 311 | qWarning("Exception triggered when processing %s with transform %s", qPrintable(src.file.flat()), qPrintable(f->objectName())); |
| 312 | 312 | dst = Template(src.file); |
| 313 | - dst.file.setBool("FTE"); | |
| 313 | + dst.file.set("FTE", true); | |
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | } |
| ... | ... | @@ -396,7 +396,7 @@ class ForkTransform : public CompositeTransform |
| 396 | 396 | } catch (...) { |
| 397 | 397 | qWarning("Exception triggered when processing %s with transform %s", qPrintable(src.file.flat()), qPrintable(f->objectName())); |
| 398 | 398 | dst = Template(src.file); |
| 399 | - dst.file.setBool("FTE"); | |
| 399 | + dst.file.set("FTE", true); | |
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | } |
| ... | ... | @@ -453,7 +453,7 @@ protected: |
| 453 | 453 | } catch (...) { |
| 454 | 454 | qWarning("Exception triggered when processing %s with transform %s", qPrintable(src.file.flat()), qPrintable(f->objectName())); |
| 455 | 455 | dst = Template(src.file); |
| 456 | - dst.file.setBool("FTE"); | |
| 456 | + dst.file.set("FTE", true); | |
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | } |
| ... | ... | @@ -648,7 +648,7 @@ class FTETransform : public Transform |
| 648 | 648 | foreach (const Template &t, projectedData) { |
| 649 | 649 | if (!t.file.contains(transform->objectName())) |
| 650 | 650 | qFatal("Matrix metadata missing key %s.", qPrintable(transform->objectName())); |
| 651 | - vals.append(t.file.getFloat(transform->objectName())); | |
| 651 | + vals.append(t.file.get<float>(transform->objectName())); | |
| 652 | 652 | } |
| 653 | 653 | float q1, q3; |
| 654 | 654 | Common::Median(vals, &q1, &q3); |
| ... | ... | @@ -660,11 +660,11 @@ class FTETransform : public Transform |
| 660 | 660 | { |
| 661 | 661 | Template projectedSrc; |
| 662 | 662 | transform->project(src, projectedSrc); |
| 663 | - const float val = projectedSrc.file.getFloat(transform->objectName()); | |
| 663 | + const float val = projectedSrc.file.get<float>(transform->objectName()); | |
| 664 | 664 | |
| 665 | 665 | dst = src; |
| 666 | - dst.file.insert(transform->objectName(), val); | |
| 667 | - dst.file.insert("FTE", (val < min) || (val > max)); | |
| 666 | + dst.file.set(transform->objectName(), val); | |
| 667 | + dst.file.set("FTE", (val < min) || (val > max)); | |
| 668 | 668 | } |
| 669 | 669 | }; |
| 670 | 670 | ... | ... |
sdk/plugins/misc.cpp
| ... | ... | @@ -44,7 +44,7 @@ class OpenTransform : public UntrainableMetaTransform |
| 44 | 44 | dst.append(t); |
| 45 | 45 | dst.file.append(t.file.localMetadata()); |
| 46 | 46 | } |
| 47 | - dst.file.insert("FTO", dst.isEmpty()); | |
| 47 | + dst.file.set("FTO", dst.isEmpty()); | |
| 48 | 48 | } |
| 49 | 49 | }; |
| 50 | 50 | |
| ... | ... | @@ -282,7 +282,7 @@ class RenameTransform : public UntrainableMetaTransform |
| 282 | 282 | { |
| 283 | 283 | dst = src; |
| 284 | 284 | if (dst.file.localKeys().contains(find)) { |
| 285 | - dst.file.insert(replace, dst.file.get(find)); | |
| 285 | + dst.file.set(replace, dst.file.value(find)); | |
| 286 | 286 | dst.file.remove(find); |
| 287 | 287 | } |
| 288 | 288 | } |
| ... | ... | @@ -308,7 +308,7 @@ class RenameFirstTransform : public UntrainableMetaTransform |
| 308 | 308 | dst = src; |
| 309 | 309 | foreach (const QString &key, find) |
| 310 | 310 | if (dst.file.localKeys().contains(key)) { |
| 311 | - dst.file.insert(replace, dst.file.get(key)); | |
| 311 | + dst.file.set(replace, dst.file.value(key)); | |
| 312 | 312 | dst.file.remove(key); |
| 313 | 313 | break; |
| 314 | 314 | } | ... | ... |
sdk/plugins/output.cpp
| ... | ... | @@ -165,9 +165,9 @@ class rrOutput : public MatrixOutput |
| 165 | 165 | ~rrOutput() |
| 166 | 166 | { |
| 167 | 167 | if (file.isNull() || targetFiles.isEmpty() || queryFiles.isEmpty()) return; |
| 168 | - const int limit = file.getInt("limit", 20); | |
| 169 | - const bool byLine = file.getBool("byLine"); | |
| 170 | - const float threshold = file.getFloat("threshold", -std::numeric_limits<float>::max()); | |
| 168 | + const int limit = file.get<int>("limit", 20); | |
| 169 | + const bool byLine = file.get<bool>("byLine", false); | |
| 170 | + const float threshold = file.get<float>("threshold", -std::numeric_limits<float>::max()); | |
| 171 | 171 | |
| 172 | 172 | QStringList lines; |
| 173 | 173 | |
| ... | ... | @@ -279,7 +279,7 @@ class rankOutput : public MatrixOutput |
| 279 | 279 | typedef QPair<float,int> Pair; |
| 280 | 280 | int rank = 1; |
| 281 | 281 | foreach (const Pair &pair, Common::Sort(OpenCVUtils::matrixToVector(data.row(i)), true)) { |
| 282 | - if(targetFiles[pair.second].getString("Label") == queryFiles[i].getString("Label")) { | |
| 282 | + if(targetFiles[pair.second].get<QString>("Label") == queryFiles[i].get<QString>("Label")) { | |
| 283 | 283 | ranks.append(rank); |
| 284 | 284 | positions.append(pair.second); |
| 285 | 285 | scores.append(pair.first); |
| ... | ... | @@ -347,10 +347,10 @@ class tailOutput : public Output |
| 347 | 347 | void initialize(const FileList &targetFiles, const FileList &queryFiles) |
| 348 | 348 | { |
| 349 | 349 | Output::initialize(targetFiles, queryFiles); |
| 350 | - threshold = file.getFloat("threshold", -std::numeric_limits<float>::max()); | |
| 351 | - atLeast = file.getInt("atLeast", 1); | |
| 352 | - atMost = file.getInt("atMost", std::numeric_limits<int>::max()); | |
| 353 | - args = file.getBool("args"); | |
| 350 | + threshold = file.get<float>("threshold", -std::numeric_limits<float>::max()); | |
| 351 | + atLeast = file.get<int>("atLeast", 1); | |
| 352 | + atMost = file.get<int>("atMost", std::numeric_limits<int>::max()); | |
| 353 | + args = file.get<bool>("args", false); | |
| 354 | 354 | lastValue = -std::numeric_limits<float>::max(); |
| 355 | 355 | } |
| 356 | 356 | |
| ... | ... | @@ -462,9 +462,9 @@ class histOutput : public Output |
| 462 | 462 | void initialize(const FileList &targetFiles, const FileList &queryFiles) |
| 463 | 463 | { |
| 464 | 464 | Output::initialize(targetFiles, queryFiles); |
| 465 | - min = file.getFloat("min", -5); | |
| 466 | - max = file.getFloat("max", 5); | |
| 467 | - step = file.getFloat("step", 0.1); | |
| 465 | + min = file.get<float>("min", -5); | |
| 466 | + max = file.get<float>("max", 5); | |
| 467 | + step = file.get<float>("step", 0.1); | |
| 468 | 468 | bins = QVector<int>((max-min)/step, 0); |
| 469 | 469 | } |
| 470 | 470 | ... | ... |
sdk/plugins/pixel.cpp
| ... | ... | @@ -120,7 +120,7 @@ class PerPixelClassifierTransform : public MetaTransform |
| 120 | 120 | uchar *psrc = src[n].ptr(); |
| 121 | 121 | ptemp[n] = psrc[index]; |
| 122 | 122 | } |
| 123 | - cv::Mat labelMat = src.file.get("labels").value<cv::Mat>(); | |
| 123 | + cv::Mat labelMat = src.file.value("labels").value<cv::Mat>(); | |
| 124 | 124 | uchar* plabel = labelMat.ptr(); |
| 125 | 125 | temp.file.setLabel(plabel[index]); |
| 126 | 126 | ... | ... |
sdk/plugins/quality.cpp
| ... | ... | @@ -53,8 +53,8 @@ class ImpostorUniquenessMeasureTransform : public Transform |
| 53 | 53 | { |
| 54 | 54 | dst = src; |
| 55 | 55 | float ium = calculateIUM(src, impostors); |
| 56 | - dst.file.insert("Impostor_Uniqueness_Measure", ium); | |
| 57 | - dst.file.insert("Impostor_Uniqueness_Measure_Bin", ium < mean-stddev ? 0 : (ium < mean+stddev ? 1 : 2)); | |
| 56 | + dst.file.set("Impostor_Uniqueness_Measure", ium); | |
| 57 | + dst.file.set("Impostor_Uniqueness_Measure_Bin", ium < mean-stddev ? 0 : (ium < mean+stddev ? 1 : 2)); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | void store(QDataStream &stream) const | ... | ... |
sdk/plugins/register.cpp
| ... | ... | @@ -73,9 +73,9 @@ class AffineTransform : public UntrainableTransform |
| 73 | 73 | src.file.contains("Affine_1_Y") && |
| 74 | 74 | (src.file.contains("Affine_2_X") || twoPoints) && |
| 75 | 75 | (src.file.contains("Affine_2_Y") || twoPoints)) { |
| 76 | - srcPoints[0] = Point2f(src.file.getFloat("Affine_0_X"), src.file.getFloat("Affine_0_Y")); | |
| 77 | - srcPoints[1] = Point2f(src.file.getFloat("Affine_1_X"), src.file.getFloat("Affine_1_Y")); | |
| 78 | - if (!twoPoints) srcPoints[2] = Point2f(src.file.getFloat("Affine_2_X"), src.file.getFloat("Affine_2_Y")); | |
| 76 | + srcPoints[0] = Point2f(src.file.get<float>("Affine_0_X"), src.file.get<float>("Affine_0_Y")); | |
| 77 | + srcPoints[1] = Point2f(src.file.get<float>("Affine_1_X"), src.file.get<float>("Affine_1_Y")); | |
| 78 | + if (!twoPoints) srcPoints[2] = Point2f(src.file.get<float>("Affine_2_X"), src.file.get<float>("Affine_2_Y")); | |
| 79 | 79 | } else { |
| 80 | 80 | const QList<Point2f> landmarks = OpenCVUtils::toPoints(src.file.landmarks()); |
| 81 | 81 | |
| ... | ... | @@ -87,13 +87,13 @@ class AffineTransform : public UntrainableTransform |
| 87 | 87 | srcPoints[1] = landmarks[1]; |
| 88 | 88 | if (!twoPoints) srcPoints[2] = landmarks[2]; |
| 89 | 89 | |
| 90 | - dst.file.insert("Affine_0_X", landmarks[0].x); | |
| 91 | - dst.file.insert("Affine_0_Y", landmarks[0].y); | |
| 92 | - dst.file.insert("Affine_1_X", landmarks[1].x); | |
| 93 | - dst.file.insert("Affine_1_Y", landmarks[1].y); | |
| 90 | + dst.file.set("Affine_0_X", landmarks[0].x); | |
| 91 | + dst.file.set("Affine_0_Y", landmarks[0].y); | |
| 92 | + dst.file.set("Affine_1_X", landmarks[1].x); | |
| 93 | + dst.file.set("Affine_1_Y", landmarks[1].y); | |
| 94 | 94 | if (!twoPoints) { |
| 95 | - dst.file.insert("Affine_2_X", landmarks[2].x); | |
| 96 | - dst.file.insert("Affine_2_Y", landmarks[2].y); | |
| 95 | + dst.file.set("Affine_2_X", landmarks[2].x); | |
| 96 | + dst.file.set("Affine_2_Y", landmarks[2].y); | |
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | } | ... | ... |
sdk/plugins/validate.cpp
| ... | ... | @@ -22,7 +22,7 @@ class CrossValidateTransform : public MetaTransform |
| 22 | 22 | int numPartitions = 0; |
| 23 | 23 | QList<int> partitions; partitions.reserve(data.size()); |
| 24 | 24 | foreach (const File &file, data.files()) { |
| 25 | - partitions.append(file.getInt("Cross_Validation_Partition", 0)); | |
| 25 | + partitions.append(file.get<int>("Cross_Validation_Partition", 0)); | |
| 26 | 26 | numPartitions = std::max(numPartitions, partitions.last()+1); |
| 27 | 27 | } |
| 28 | 28 | |
| ... | ... | @@ -48,7 +48,7 @@ class CrossValidateTransform : public MetaTransform |
| 48 | 48 | |
| 49 | 49 | void project(const Template &src, Template &dst) const |
| 50 | 50 | { |
| 51 | - transforms[src.file.getInt("Cross_Validation_Partition", 0)]->project(src, dst); | |
| 51 | + transforms[src.file.get<int>("Cross_Validation_Partition", 0)]->project(src, dst); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | void store(QDataStream &stream) const |
| ... | ... | @@ -82,8 +82,8 @@ class CrossValidateDistance : public Distance |
| 82 | 82 | |
| 83 | 83 | float compare(const Template &a, const Template &b) const |
| 84 | 84 | { |
| 85 | - const int partitionA = a.file.getInt("Cross_Validation_Partition", 0); | |
| 86 | - const int partitionB = b.file.getInt("Cross_Validation_Partition", 0); | |
| 85 | + const int partitionA = a.file.get<int>("Cross_Validation_Partition", 0); | |
| 86 | + const int partitionB = b.file.get<int>("Cross_Validation_Partition", 0); | |
| 87 | 87 | return (partitionA != partitionB) ? -std::numeric_limits<float>::max() : 0; |
| 88 | 88 | } |
| 89 | 89 | }; |
| ... | ... | @@ -104,7 +104,7 @@ class FilterDistance : public Distance |
| 104 | 104 | (void) b; // Query template isn't checked |
| 105 | 105 | foreach (const QString &key, Globals->filters.keys()) { |
| 106 | 106 | bool keep = false; |
| 107 | - const QString metadata = a.file.getString(key, ""); | |
| 107 | + const QString metadata = a.file.get<QString>(key, ""); | |
| 108 | 108 | if (metadata.isEmpty()) continue; |
| 109 | 109 | foreach (const QString &value, Globals->filters[key]) { |
| 110 | 110 | if (metadata == value) { | ... | ... |