From 35ab70c92afd319af7f22fc5e742267c2c33d021 Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Fri, 8 Mar 2013 15:11:22 -0500 Subject: [PATCH] function cleanup --- app/examples/age_estimation.cpp | 2 +- app/examples/face_recognition.cpp | 4 ++-- app/examples/gender_estimation.cpp | 2 +- app/openbr-gui/classifier.cpp | 7 +++---- app/openbr-gui/gallerytoolbar.cpp | 4 ++-- app/openbr-gui/templatemetadata.cpp | 2 +- app/openbr-gui/templateviewer.cpp | 4 ++-- sdk/core/bee.cpp | 18 +++++++++--------- sdk/core/core.cpp | 8 ++++---- sdk/core/plot.cpp | 6 +++--- sdk/openbr_plugin.cpp | 110 +++++++++++++++++++------------------------------------------------------------------------------------------- sdk/openbr_plugin.h | 43 ++++++++++++++++++++++++++----------------- sdk/plugins/cascade.cpp | 4 ++-- sdk/plugins/eigen3.cpp | 2 +- sdk/plugins/eyes.cpp | 8 ++++---- sdk/plugins/format.cpp | 10 +++++----- sdk/plugins/gallery.cpp | 10 +++++----- sdk/plugins/keypoint.cpp | 2 +- sdk/plugins/meta.cpp | 24 ++++++++++++------------ sdk/plugins/misc.cpp | 6 +++--- sdk/plugins/output.cpp | 22 +++++++++++----------- sdk/plugins/pixel.cpp | 2 +- sdk/plugins/quality.cpp | 4 ++-- sdk/plugins/register.cpp | 18 +++++++++--------- sdk/plugins/validate.cpp | 10 +++++----- 25 files changed, 134 insertions(+), 198 deletions(-) diff --git a/app/examples/age_estimation.cpp b/app/examples/age_estimation.cpp index fa55ade..2b2b97b 100644 --- a/app/examples/age_estimation.cpp +++ b/app/examples/age_estimation.cpp @@ -31,7 +31,7 @@ static void printTemplate(const br::Template &t) { printf("%s age: %d\n", qPrintable(t.file.fileName()), - t.file.getInt("Label")); + t.file.get("Label")); } int main(int argc, char *argv[]) diff --git a/app/examples/face_recognition.cpp b/app/examples/face_recognition.cpp index 48b0c4b..3da6a3f 100644 --- a/app/examples/face_recognition.cpp +++ b/app/examples/face_recognition.cpp @@ -32,8 +32,8 @@ static void printTemplate(const br::Template &t) { printf("%s eyes: (%d, %d) (%d, %d)\n", qPrintable(t.file.fileName()), - t.file.getInt("Affine_0_X"), t.file.getInt("Affine_0_Y"), - t.file.getInt("Affine_1_X"), t.file.getInt("Affine_1_Y")); + t.file.get("Affine_0_X"), t.file.get("Affine_0_Y"), + t.file.get("Affine_1_X"), t.file.get("Affine_1_Y")); } int main(int argc, char *argv[]) diff --git a/app/examples/gender_estimation.cpp b/app/examples/gender_estimation.cpp index fd88eea..6987707 100644 --- a/app/examples/gender_estimation.cpp +++ b/app/examples/gender_estimation.cpp @@ -31,7 +31,7 @@ static void printTemplate(const br::Template &t) { printf("%s gender: %s\n", qPrintable(t.file.fileName()), - t.file.getInt("Label") == 1 ? "Female" : "Male"); + t.file.get("Label") == 1 ? "Female" : "Male"); } int main(int argc, char *argv[]) diff --git a/app/openbr-gui/classifier.cpp b/app/openbr-gui/classifier.cpp index 481950c..8b65e52 100644 --- a/app/openbr-gui/classifier.cpp +++ b/app/openbr-gui/classifier.cpp @@ -39,19 +39,18 @@ void Classifier::_classify(File file) { QString key, value; foreach (const File &f, Enroll(file.flat(), File("[algorithm=" + algorithm + "]"))) { - qDebug() << f.flat(); if (!f.contains("Label")) continue; if (algorithm == "GenderClassification") { key = "Gender"; - value = (f.getInt("Label", 0) == 0 ? "Male" : "Female"); + value = (f.get("Label", 0) == 0 ? "Male" : "Female"); } else if (algorithm == "AgeRegression") { key = "Age"; - value = QString::number(int(f.getFloat("Label", 0)+0.5)) + " Years"; + value = QString::number(int(f.get("Label", 0)+0.5)) + " Years"; } else { key = algorithm; - value = f.getString("Label"); + value = f.get("Label"); } break; } diff --git a/app/openbr-gui/gallerytoolbar.cpp b/app/openbr-gui/gallerytoolbar.cpp index 87dd5cd..79855e0 100644 --- a/app/openbr-gui/gallerytoolbar.cpp +++ b/app/openbr-gui/gallerytoolbar.cpp @@ -117,7 +117,7 @@ void br::GalleryToolBar::checkWebcam() void br::GalleryToolBar::enrollmentFinished() { if (files.isEmpty()) { - if (input.getBool("enrollAll") && !tbWebcam.isChecked()) { + if (input.get("enrollAll", false) && !tbWebcam.isChecked()) { QMessageBox msgBox; msgBox.setText("Quality test failed."); msgBox.setInformativeText("Enroll anyway?"); @@ -127,7 +127,7 @@ void br::GalleryToolBar::enrollmentFinished() if (ret == QMessageBox::Ok) { br::File file = input; - file.setBool("enrollAll", false); + file.set("enrollAll", false); enroll(file); } } diff --git a/app/openbr-gui/templatemetadata.cpp b/app/openbr-gui/templatemetadata.cpp index ee5fb9d..1c4b8b3 100644 --- a/app/openbr-gui/templatemetadata.cpp +++ b/app/openbr-gui/templatemetadata.cpp @@ -28,7 +28,7 @@ void br::TemplateMetadata::setFile(const br::File &file) { if (file.isNull()) lFile.clear(); else lFile.setText("File: " + file.fileName()); - lQuality.setText(QString("Quality: %1").arg(file.getBool("FTE") ? "Low" : "High")); + lQuality.setText(QString("Quality: %1").arg(file.get("FTE", false) ? "Low" : "High")); foreach (const ConditionalClassifier &classifier, conditionalClassifiers) if (classifier.action->isVisible()) classifier.classifier->classify(file); } diff --git a/app/openbr-gui/templateviewer.cpp b/app/openbr-gui/templateviewer.cpp index c3b1b88..e1cd18a 100644 --- a/app/openbr-gui/templateviewer.cpp +++ b/app/openbr-gui/templateviewer.cpp @@ -40,9 +40,9 @@ void TemplateViewer::setFile(const File &file_) // Update landmarks landmarks.clear(); if (file.contains("Affine_0_X") && file.contains("Affine_0_Y")) - landmarks.append(QPointF(file.getFloat("Affine_0_X"), file.getFloat("Affine_0_Y"))); + landmarks.append(QPointF(file.get("Affine_0_X"), file.get("Affine_0_Y"))); if (file.contains("Affine_1_X") && file.contains("Affine_1_Y")) - landmarks.append(QPointF(file.getFloat("Affine_1_X"), file.getFloat("Affine_1_Y"))); + landmarks.append(QPointF(file.get("Affine_1_X"), file.get("Affine_1_Y"))); while (landmarks.size() < NumLandmarks) landmarks.append(QPointF()); nearestLandmark = -1; diff --git a/sdk/core/bee.cpp b/sdk/core/bee.cpp index 9016f6c..1bbca0d 100644 --- a/sdk/core/bee.cpp +++ b/sdk/core/bee.cpp @@ -71,7 +71,7 @@ FileList BEE::readSigset(const QString &sigset, bool ignoreMetadata) newFile.append(file); file = newFile; } else if (!ignoreMetadata) { - file.insert(key, value); + file.set(key, value); } } @@ -99,7 +99,7 @@ void BEE::writeSigset(const QString &sigset, const br::FileList &files, bool ign QStringList metadata; if (!ignoreMetadata) foreach (const QString &key, file.localKeys()) - metadata.append(key+"=\""+file.getString(key, "?")+"\""); + metadata.append(key+"=\""+file.get(key, "?")+"\""); lines.append("\t"); lines.append("\t\t"); lines.append("\t"); @@ -113,19 +113,19 @@ Mat readMatrix(const br::File &matrix) { // Special case matrix construction if (matrix == "Identity") { - int rows = matrix.getInt("rows", -1); - int columns = matrix.getInt("columns", -1); - const int size = matrix.getInt("size", -1); + int rows = matrix.get("rows", -1); + int columns = matrix.get("columns", -1); + const int size = matrix.get("size", -1); if (size != -1) { if (rows == -1) rows = size; if (columns == -1) columns = size; } - const int step = matrix.getInt("step", 1); + const int step = matrix.get("step", 1); if (rows % step != 0) qFatal("Step does not divide rows evenly."); if (columns % step != 0) qFatal("Step does not divide columns evenly."); if (sizeof(T) == sizeof(BEE::Mask_t)) { - const bool selfSimilar = matrix.getBool("selfSimilar"); + const bool selfSimilar = matrix.get("selfSimilar", false); Mat m(rows, columns, CV_8UC1); m.setTo(BEE::NonMatch); @@ -171,8 +171,8 @@ Mat readMatrix(const br::File &matrix) file.close(); Mat result; - if (isDistance ^ matrix.getBool("negate")) m.convertTo(result, -1, -1); - else result = m.clone(); + if (isDistance ^ matrix.get("negate", false)) m.convertTo(result, -1, -1); + else result = m.clone(); return result; } diff --git a/sdk/core/core.cpp b/sdk/core/core.cpp index da57f89..b5bdefb 100644 --- a/sdk/core/core.cpp +++ b/sdk/core/core.cpp @@ -194,7 +194,7 @@ struct AlgorithmCore void compare(File targetGallery, File queryGallery, File output) { - if (output.exists() && output.getBool("cache")) return; + if (output.exists() && output.get("cache", false)) return; if (queryGallery == ".") queryGallery = targetGallery; QScopedPointer t, q; @@ -316,14 +316,14 @@ void br::Train(const File &input, const File &model) { qDebug("Training on %s%s", qPrintable(input.flat()), model.isNull() ? "" : qPrintable(" to " + model.flat())); - AlgorithmManager::getAlgorithm(model.getString("algorithm"))->train(input, model); + AlgorithmManager::getAlgorithm(model.get("algorithm"))->train(input, model); } FileList br::Enroll(const File &input, const File &gallery) { qDebug("Enrolling %s%s", qPrintable(input.flat()), gallery.isNull() ? "" : qPrintable(" to " + gallery.flat())); - return AlgorithmManager::getAlgorithm(gallery.getString("algorithm"))->enroll(input, gallery); + return AlgorithmManager::getAlgorithm(gallery.get("algorithm"))->enroll(input, gallery); } 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 qDebug("Comparing %s and %s%s", qPrintable(targetGallery.flat()), qPrintable(queryGallery.flat()), output.isNull() ? "" : qPrintable(" to " + output.flat())); - AlgorithmManager::getAlgorithm(output.getString("algorithm"))->compare(targetGallery, queryGallery, output); + AlgorithmManager::getAlgorithm(output.get("algorithm"))->compare(targetGallery, queryGallery, output); } void br::Convert(const File &src, const File &dst) diff --git a/sdk/core/plot.cpp b/sdk/core/plot.cpp index 53982a7..5d0d3f4 100644 --- a/sdk/core/plot.cpp +++ b/sdk/core/plot.cpp @@ -119,8 +119,8 @@ float Evaluate(const QString &simmat, const QString &mask, const QString &csv) // Read files const Mat scores = BEE::readSimmat(simmat); File maskFile(mask); - maskFile.insert("rows", scores.rows); - maskFile.insert("columns", scores.cols); + maskFile.set("rows", scores.rows); + maskFile.set("columns", scores.cols); const Mat masks = BEE::readMask(maskFile); if (scores.size() != masks.size()) qFatal("Simmat/Mask size mismatch."); @@ -416,7 +416,7 @@ struct RPlot } } - const QString &smooth = destination.getString("smooth", ""); + const QString &smooth = destination.get("smooth", ""); major.smooth = !smooth.isEmpty() && (major.header == smooth) && (major.size > 1); minor.smooth = !smooth.isEmpty() && (minor.header == smooth) && (minor.size > 1); if (major.smooth) major.size = 1; diff --git a/sdk/openbr_plugin.cpp b/sdk/openbr_plugin.cpp index a767c72..4750594 100644 --- a/sdk/openbr_plugin.cpp +++ b/sdk/openbr_plugin.cpp @@ -61,7 +61,7 @@ QString File::hash() const void File::append(const QHash &metadata) { foreach (const QString &key, metadata.keys()) - insert(key, metadata[key]); + set(key, metadata[key]); } void File::append(const File &other) @@ -70,7 +70,7 @@ void File::append(const File &other) if (name.isEmpty()) { name = other.name; } else { - if (!contains("separator")) insert("separator", ";"); + if (!contains("separator")) set("separator", ";"); name += value("separator").toString() + other.name; } } @@ -153,77 +153,6 @@ void File::set(const QString &key, const QVariant &value) m_metadata.insert(key, value); } -QVariant File::get(const QString &key) const -{ - if (!contains(key)) qFatal("Missing key: %s", qPrintable(key)); - return value(key); -} - -QVariant File::get(const QString &key, const QVariant &defaultValue) const -{ - if (!contains(key)) return defaultValue; - return value(key); -} - -bool File::getBool(const QString &key) const -{ - if (!contains(key)) return false; - QString v = value(key).toString(); - if (v.isEmpty() || (v == "true")) return true; - if (v == "false") return false; - return v.toInt(); -} - -void File::setBool(const QString &key, bool value) -{ - if (value) m_metadata.insert(key, QVariant()); - else m_metadata.remove(key); -} - -int File::getInt(const QString &key) const -{ - if (!contains(key)) qFatal("Missing key: %s", qPrintable(key)); - bool ok; int result = value(key).toInt(&ok); - if (!ok) qFatal("Invalid conversion from: %s", qPrintable(getString(key))); - return result; -} - -int File::getInt(const QString &key, int defaultValue) const -{ - if (!contains(key)) return defaultValue; - bool ok; int result = value(key).toInt(&ok); - if (!ok) return defaultValue; - return result; -} - -float File::getFloat(const QString &key) const -{ - if (!contains(key)) qFatal("Missing key: %s", qPrintable(key)); - bool ok; float result = value(key).toFloat(&ok); - if (!ok) qFatal("Invalid conversion from: %s", qPrintable(getString(key))); - return result; -} - -float File::getFloat(const QString &key, float defaultValue) const -{ - if (!contains(key)) return defaultValue; - bool ok; float result = value(key).toFloat(&ok); - if (!ok) return defaultValue; - return result; -} - -QString File::getString(const QString &key) const -{ - if (!contains(key)) qFatal("Missing key: %s", qPrintable(key)); - return value(key).toString(); -} - -QString File::getString(const QString &key, const QString &defaultValue) const -{ - if (!contains(key)) return defaultValue; - return value(key).toString(); -} - QList File::landmarks() const { QList landmarks; @@ -245,7 +174,7 @@ QList File::namedLandmarks() const keys.contains(keyBaseName+"_Height") || keys.contains(keyBaseName+"_Radius")) continue; - landmarks.append(QPointF(getFloat(keyBaseName+"_X"), getFloat(keyBaseName+"_Y"))); + landmarks.append(QPointF(get(keyBaseName+"_X"), get(keyBaseName+"_Y"))); } return landmarks; } @@ -325,10 +254,10 @@ void File::init(const QString &file) QStringList words = QtUtils::parse(parameters[i], '='); QtUtils::checkArgsSize("File", words, 1, 2); if (words.size() < 2) { - if (unnamed) insertParameter(i, words[0]); - else insert(words[0], QVariant()); + if (unnamed) setParameter(i, words[0]); + else set(words[0], QVariant()); } else { - insert(words[0], words[1]); + set(words[0], words[1]); } } name = name.left(index); @@ -391,9 +320,8 @@ void FileList::sort(const QString& key) FileList sortedList; for (int i = 0; i < size(); i++) { - if (at(i).contains(key)) { - metadata.append(at(i).get(key).toString()); - } + if (at(i).contains(key)) + metadata.append(at(i).get(key)); else sortedList.push_back(at(i)); } @@ -416,7 +344,7 @@ QList FileList::crossValidationPartitions() const { QList crossValidationPartitions; crossValidationPartitions.reserve(size()); foreach (const File &f, *this) - crossValidationPartitions.append(f.getInt("Cross_Validation_Partition", 0)); + crossValidationPartitions.append(f.get("Cross_Validation_Partition", 0)); return crossValidationPartitions; } @@ -424,7 +352,7 @@ int FileList::failures() const { int failures = 0; foreach (const File &file, *this) - if (file.getBool("FTO") || file.getBool("FTE")) + if (file.get("FTO", false) || file.get("FTE", false)) failures++; return failures; } @@ -447,9 +375,9 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) foreach (const br::File &file, gallery.split()) { QScopedPointer i(Gallery::make(file)); TemplateList newTemplates = i->read(); - newTemplates = newTemplates.mid(gallery.getInt("pos", 0), gallery.getInt("length", -1)); - if (gallery.getBool("reduce")) newTemplates = newTemplates.reduced(); - const int crossValidate = gallery.getInt("crossValidate"); + newTemplates = newTemplates.mid(gallery.get("pos", 0), gallery.get("length", -1)); + if (gallery.get("reduce", false)) newTemplates = newTemplates.reduced(); + const int crossValidate = gallery.get("crossValidate"); if (crossValidate > 0) srand(0); // If file is a Format not a Gallery @@ -460,11 +388,11 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) for (int i=0; i 0) newTemplates[i].file.insert("Cross_Validation_Partition", rand()%crossValidate); + newTemplates[i].file.set("Index", i+templates.size()); + if (crossValidate > 0) newTemplates[i].file.set("Cross_Validation_Partition", rand()%crossValidate); } - if (!templates.isEmpty() && gallery.getBool("merge")) { + if (!templates.isEmpty() && gallery.get("merge", false)) { if (newTemplates.size() != templates.size()) qFatal("Inputs must be the same size in order to merge."); for (int i=0; i indices; for (int j=0; j("FTE", false))) indices.append(j); std::random_shuffle(indices.begin(), indices.end()); @@ -1320,7 +1248,7 @@ static void _project(const Transform *transform, const Template *src, Template * } catch (...) { qWarning("Exception triggered when processing %s with transform %s", qPrintable(src->file.flat()), qPrintable(transform->objectName())); *dst = Template(src->file); - dst->file.setBool("FTE"); + dst->file.set("FTE", true); } } @@ -1331,7 +1259,7 @@ static void _backProject(const Transform *transform, const Template *dst, Templa } catch (...) { qWarning("Exception triggered when processing %s with transform %s", qPrintable(src->file.flat()), qPrintable(transform->objectName())); *src = Template(dst->file); - src->file.setBool("FTE"); + src->file.set("FTE", true); } } diff --git a/sdk/openbr_plugin.h b/sdk/openbr_plugin.h index aa116a1..ce9648e 100644 --- a/sdk/openbr_plugin.h +++ b/sdk/openbr_plugin.h @@ -156,7 +156,7 @@ struct BR_EXPORT File File() {} File(const QString &file) { init(file); } /*!< \brief Construct a file from a string. */ - File(const QString &file, const QVariant &label) { init(file); insert("Label", label); } /*!< \brief Construct a file from a string and assign a label. */ + File(const QString &file, const QVariant &label) { init(file); set("Label", label); } /*!< \brief Construct a file from a string and assign a label. */ File(const char *file) { init(file); } /*!< \brief Construct a file from a c-style string. */ inline operator QString() const { return name; } /*!< \brief Returns #name. */ QString flat() const; /*!< \brief A stringified version of the file with metadata. */ @@ -165,15 +165,14 @@ struct BR_EXPORT File inline QList localKeys() const { return m_metadata.keys(); } /*!< \brief Returns the private metadata keys. */ inline QHash localMetadata() const { return m_metadata; } /*!< \brief Returns the private metadata. */ - inline void insert(const QString &key, const QVariant &value) { set(key, value); } /*!< \brief Equivalent to set(). */ void append(const QHash &localMetadata); /*!< \brief Add new metadata fields. */ void append(const File &other); /*!< \brief Append another file using \c separator. */ QList split() const; /*!< \brief Split the file using \c separator. */ QList split(const QString &separator) const; /*!< \brief Split the file. */ - inline void insertParameter(int index, const QVariant &value) { insert("_Arg" + QString::number(index), value); } /*!< \brief Insert a keyless value. */ - inline bool containsParameter(int index) const { return m_metadata.contains("_Arg" + QString::number(index)); } /*!< \brief Check for the existence of a keyless value. */ - inline QVariant parameter(int index) const { return m_metadata.value("_Arg" + QString::number(index)); } /*!< \brief Retrieve a keyless value. */ + inline void setParameter(int index, const QVariant &value) { set("_Arg" + QString::number(index), value); } /*!< \brief Insert a keyless value. */ + inline bool containsParameter(int index) const { return contains("_Arg" + QString::number(index)); } /*!< \brief Check for the existence of a keyless value. */ + inline QVariant getParameter(int index) const { return get("_Arg" + QString::number(index)); } /*!< \brief Retrieve a keyless value. */ inline bool operator==(const char* other) const { return name == other; } /*!< \brief Compare name to c-style string. */ 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 QVariant value(const QString &key) const; /*!< \brief Returns the value for the specified key. */ static QString subject(int label); /*!< \brief Looks up the subject for the provided label. */ inline QString subject() const { return subject(label()); } /*!< \brief Looks up the subject from the file's label. */ - inline bool failed() const { return getBool("FTE") || getBool("FTO"); } /*!< \brief Returns \c true if the file failed to open or enroll, \c false otherwise. */ + inline bool failed() const { return get("FTE", false) || get("FTO", false); } /*!< \brief Returns \c true if the file failed to open or enroll, \c false otherwise. */ void remove(const QString &key); /*!< \brief Remove the metadata key. */ void set(const QString &key, const QVariant &value); /*!< \brief Insert or overwrite the metadata key with the specified value. */ - QVariant get(const QString &key) const; /*!< \brief Returns a QVariant for the key, throwing an error if the key does not exist. */ - 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. */ float label() const; /*!< \brief Convenience function for retrieving the file's \c Label. */ - inline void setLabel(float label) { insert("Label", label); } /*!< \brief Convenience function for setting the file's \c Label. */ - bool getBool(const QString &key) const; /*!< \brief Returns a boolean value for the key. */ - void setBool(const QString &key, bool value = true); /*!< \brief Sets a boolean value for the key. */ - int getInt(const QString &key) const; /*!< \brief Returns an int value for the key, throwing an error if the key does not exist. */ - 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. */ - float getFloat(const QString &key) const; /*!< \brief Returns a float value for the key, throwing an error if the key does not exist. */ - 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. */ - QString getString(const QString &key) const; /*!< \brief Returns a string value for the key, throwing an error if the key does not exist. */ - 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. */ + inline void setLabel(float label) { set("Label", label); } /*!< \brief Convenience function for setting the file's \c Label. */ + + /*!< \brief Returns a value for the key, throwing an error if the key does not exist. */ + template + T get(const QString &key) const + { + if (!contains(key)) qFatal("Missing key: %s", qPrintable(key)); + QVariant variant = value(key); + if (!variant.canConvert()) qFatal("Can't convert: %s", qPrintable(key)); + return variant.value(); + } + + /*!< \brief Returns a value for the key, returning \em defaultValue if the key does not exist or can't be converted. */ + template + T get(const QString &key, const T &defaultValue) const + { + if (!contains(key)) return defaultValue; + QVariant variant = value(key); + if (!variant.canConvert()) return defaultValue; + return variant.value(); + } QList landmarks() const; /*!< \brief Returns the file's landmark list. */ QList namedLandmarks() const; /*!< \brief Returns landmarks derived from metadata keys. */ diff --git a/sdk/plugins/cascade.cpp b/sdk/plugins/cascade.cpp index 480ab7b..0097191 100644 --- a/sdk/plugins/cascade.cpp +++ b/sdk/plugins/cascade.cpp @@ -75,10 +75,10 @@ class CascadeTransform : public UntrainableTransform { CascadeClassifier *cascade = cascadeResource.acquire(); vector rects; - cascade->detectMultiScale(src, rects, 1.2, 5, src.file.getBool("enrollAll") ? 0 : CV_HAAR_FIND_BIGGEST_OBJECT, Size(minSize, minSize)); + cascade->detectMultiScale(src, rects, 1.2, 5, src.file.get("enrollAll", false) ? 0 : CV_HAAR_FIND_BIGGEST_OBJECT, Size(minSize, minSize)); cascadeResource.release(cascade); - if (!src.file.getBool("enrollAll") && rects.empty()) + if (!src.file.get("enrollAll", false) && rects.empty()) rects.push_back(Rect(0, 0, src.m().cols, src.m().rows)); foreach (const Rect &rect, rects) { diff --git a/sdk/plugins/eigen3.cpp b/sdk/plugins/eigen3.cpp index 557af04..3026651 100644 --- a/sdk/plugins/eigen3.cpp +++ b/sdk/plugins/eigen3.cpp @@ -228,7 +228,7 @@ class DFFSTransform : public Transform void project(const Template &src, Template &dst) const { dst = src; - dst.file.insert("DFFS", sqrt(pca.residualReconstructionError((*cvtFloat)(src)))); + dst.file.set("DFFS", sqrt(pca.residualReconstructionError((*cvtFloat)(src)))); } void store(QDataStream &stream) const diff --git a/sdk/plugins/eyes.cpp b/sdk/plugins/eyes.cpp index 233ed6e..bd604b0 100644 --- a/sdk/plugins/eyes.cpp +++ b/sdk/plugins/eyes.cpp @@ -185,10 +185,10 @@ private: dst = src; dst.file.appendLandmark(QPointF(first_eye_x, first_eye_y)); dst.file.appendLandmark(QPointF(second_eye_x, second_eye_y)); - dst.file.insert("ASEF_Right_Eye_X", first_eye_x); - dst.file.insert("ASEF_Right_Eye_Y", first_eye_y); - dst.file.insert("ASEF_Left_Eye_X", second_eye_x); - dst.file.insert("ASEF_Left_Eye_Y", second_eye_y); + dst.file.set("ASEF_Right_Eye_X", first_eye_x); + dst.file.set("ASEF_Right_Eye_Y", first_eye_y); + dst.file.set("ASEF_Left_Eye_X", second_eye_x); + dst.file.set("ASEF_Left_Eye_Y", second_eye_y); } }; diff --git a/sdk/plugins/format.cpp b/sdk/plugins/format.cpp index 47f10b8..680c452 100644 --- a/sdk/plugins/format.cpp +++ b/sdk/plugins/format.cpp @@ -217,11 +217,11 @@ class DefaultFormat : public Format } else { QString fileName = file.name; if (!QFileInfo(fileName).exists()) { - fileName = file.getString("path") + "/" + file.name; + fileName = file.get("path") + "/" + file.name; if (!QFileInfo(fileName).exists()) { fileName = file.fileName(); if (!QFileInfo(fileName).exists()) { - fileName = file.getString("path") + "/" + file.fileName(); + fileName = file.get("path") + "/" + file.fileName(); if (!QFileInfo(fileName).exists()) return t; } } @@ -604,7 +604,7 @@ class xmlFormat : public Format (e.tagName() == "RPROFILE")) { // Ignore these other image fields for now } else { - t.file.insert(e.tagName(), e.text()); + t.file.set(e.tagName(), e.text()); } fileNode = fileNode.nextSibling(); @@ -614,11 +614,11 @@ class xmlFormat : public Format // Calculate age if (t.file.contains("DOB")) { - const QDate dob = QDate::fromString(t.file.getString("DOB").left(10), "yyyy-MM-dd"); + const QDate dob = QDate::fromString(t.file.get("DOB").left(10), "yyyy-MM-dd"); const QDate current = QDate::currentDate(); int age = current.year() - dob.year(); if (current.month() < dob.month()) age--; - t.file.insert("Age", age); + t.file.set("Age", age); } return t; diff --git a/sdk/plugins/gallery.cpp b/sdk/plugins/gallery.cpp index 7c07e57..a99972f 100644 --- a/sdk/plugins/gallery.cpp +++ b/sdk/plugins/gallery.cpp @@ -47,7 +47,7 @@ class galGallery : public Gallery void init() { gallery.setFileName(file); - if (file.getBool("remove")) + if (file.get("remove", false)) gallery.remove(); QtUtils::touchDir(gallery); if (!gallery.open(QFile::ReadWrite | QFile::Append)) @@ -352,7 +352,7 @@ class csvGallery : public Gallery for (int i=0; isetRelative(files[i].label(), i, j); - else output->setRelative(files[i].getFloat(keys[j], std::numeric_limits::quiet_NaN()), i, j); + else output->setRelative(files[i].get(keys[j], std::numeric_limits::quiet_NaN()), i, j); } TemplateList readBlock(bool *done) @@ -465,9 +465,9 @@ class dbGallery : public Gallery TemplateList readBlock(bool *done) { TemplateList templates; - br::File import = file.getString("import", ""); - QString query = file.getString("query"); - QString subset = file.getString("subset", ""); + br::File import = file.get("import", ""); + QString query = file.get("query"); + QString subset = file.get("subset", ""); #ifndef BR_EMBEDDED QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); diff --git a/sdk/plugins/keypoint.cpp b/sdk/plugins/keypoint.cpp index 318d375..ac5c54e 100644 --- a/sdk/plugins/keypoint.cpp +++ b/sdk/plugins/keypoint.cpp @@ -54,7 +54,7 @@ class KeyPointDetectorTransform : public UntrainableTransform featureDetector->detect(src, keyPoints); } catch (...) { qWarning("Key point detection failed for file %s", qPrintable(src.file.name)); - dst.file.setBool("FTE"); + dst.file.set("FTE", true); } QList ROIs; diff --git a/sdk/plugins/meta.cpp b/sdk/plugins/meta.cpp index 71257e0..2d8307a 100644 --- a/sdk/plugins/meta.cpp +++ b/sdk/plugins/meta.cpp @@ -31,12 +31,12 @@ static TemplateList Expanded(const TemplateList &templates) TemplateList expanded; foreach (const Template &t, templates) { if (t.isEmpty()) { - if (!t.file.getBool("enrollAll")) + if (!t.file.get("enrollAll", false)) expanded.append(t); continue; } - const bool fte = t.file.getBool("FTE"); + const bool fte = t.file.get("FTE", false); QList landmarks = t.file.landmarks(); QList ROIs = t.file.ROIs(); if (landmarks.size() % t.size() != 0) qFatal("Uneven landmark count."); @@ -45,7 +45,7 @@ static TemplateList Expanded(const TemplateList &templates) const int ROIStep = ROIs.size() / t.size(); for (int i=0; i("enrollAll", false)) { expanded.append(Template(t.file, t[i])); expanded.last().file.setROIs(ROIs.mid(i*ROIStep, ROIStep)); expanded.last().file.setLandmarks(landmarks.mid(i*landmarkStep, landmarkStep)); @@ -233,7 +233,7 @@ class PipeTransform : public CompositeTransform } catch (...) { qWarning("Exception triggered when processing %s with transform %s", qPrintable(dst.file.flat()), qPrintable(f->objectName())); src = Template(src.file); - src.file.setBool("FTE"); + src.file.set("FTE", true); } } } @@ -247,7 +247,7 @@ class PipeTransform : public CompositeTransform } catch (...) { qWarning("Exception triggered when processing %s with transform %s", qPrintable(src.file.flat()), qPrintable(f->objectName())); dst = Template(src.file); - dst.file.setBool("FTE"); + dst.file.set("FTE", true); } } } @@ -310,7 +310,7 @@ protected: } catch (...) { qWarning("Exception triggered when processing %s with transform %s", qPrintable(src.file.flat()), qPrintable(f->objectName())); dst = Template(src.file); - dst.file.setBool("FTE"); + dst.file.set("FTE", true); } } } @@ -396,7 +396,7 @@ class ForkTransform : public CompositeTransform } catch (...) { qWarning("Exception triggered when processing %s with transform %s", qPrintable(src.file.flat()), qPrintable(f->objectName())); dst = Template(src.file); - dst.file.setBool("FTE"); + dst.file.set("FTE", true); } } } @@ -453,7 +453,7 @@ protected: } catch (...) { qWarning("Exception triggered when processing %s with transform %s", qPrintable(src.file.flat()), qPrintable(f->objectName())); dst = Template(src.file); - dst.file.setBool("FTE"); + dst.file.set("FTE", true); } } } @@ -648,7 +648,7 @@ class FTETransform : public Transform foreach (const Template &t, projectedData) { if (!t.file.contains(transform->objectName())) qFatal("Matrix metadata missing key %s.", qPrintable(transform->objectName())); - vals.append(t.file.getFloat(transform->objectName())); + vals.append(t.file.get(transform->objectName())); } float q1, q3; Common::Median(vals, &q1, &q3); @@ -660,11 +660,11 @@ class FTETransform : public Transform { Template projectedSrc; transform->project(src, projectedSrc); - const float val = projectedSrc.file.getFloat(transform->objectName()); + const float val = projectedSrc.file.get(transform->objectName()); dst = src; - dst.file.insert(transform->objectName(), val); - dst.file.insert("FTE", (val < min) || (val > max)); + dst.file.set(transform->objectName(), val); + dst.file.set("FTE", (val < min) || (val > max)); } }; diff --git a/sdk/plugins/misc.cpp b/sdk/plugins/misc.cpp index 97b30aa..82d1ddc 100644 --- a/sdk/plugins/misc.cpp +++ b/sdk/plugins/misc.cpp @@ -44,7 +44,7 @@ class OpenTransform : public UntrainableMetaTransform dst.append(t); dst.file.append(t.file.localMetadata()); } - dst.file.insert("FTO", dst.isEmpty()); + dst.file.set("FTO", dst.isEmpty()); } }; @@ -282,7 +282,7 @@ class RenameTransform : public UntrainableMetaTransform { dst = src; if (dst.file.localKeys().contains(find)) { - dst.file.insert(replace, dst.file.get(find)); + dst.file.set(replace, dst.file.value(find)); dst.file.remove(find); } } @@ -308,7 +308,7 @@ class RenameFirstTransform : public UntrainableMetaTransform dst = src; foreach (const QString &key, find) if (dst.file.localKeys().contains(key)) { - dst.file.insert(replace, dst.file.get(key)); + dst.file.set(replace, dst.file.value(key)); dst.file.remove(key); break; } diff --git a/sdk/plugins/output.cpp b/sdk/plugins/output.cpp index 83c626a..5c6c6e2 100644 --- a/sdk/plugins/output.cpp +++ b/sdk/plugins/output.cpp @@ -165,9 +165,9 @@ class rrOutput : public MatrixOutput ~rrOutput() { if (file.isNull() || targetFiles.isEmpty() || queryFiles.isEmpty()) return; - const int limit = file.getInt("limit", 20); - const bool byLine = file.getBool("byLine"); - const float threshold = file.getFloat("threshold", -std::numeric_limits::max()); + const int limit = file.get("limit", 20); + const bool byLine = file.get("byLine", false); + const float threshold = file.get("threshold", -std::numeric_limits::max()); QStringList lines; @@ -279,7 +279,7 @@ class rankOutput : public MatrixOutput typedef QPair Pair; int rank = 1; foreach (const Pair &pair, Common::Sort(OpenCVUtils::matrixToVector(data.row(i)), true)) { - if(targetFiles[pair.second].getString("Label") == queryFiles[i].getString("Label")) { + if(targetFiles[pair.second].get("Label") == queryFiles[i].get("Label")) { ranks.append(rank); positions.append(pair.second); scores.append(pair.first); @@ -347,10 +347,10 @@ class tailOutput : public Output void initialize(const FileList &targetFiles, const FileList &queryFiles) { Output::initialize(targetFiles, queryFiles); - threshold = file.getFloat("threshold", -std::numeric_limits::max()); - atLeast = file.getInt("atLeast", 1); - atMost = file.getInt("atMost", std::numeric_limits::max()); - args = file.getBool("args"); + threshold = file.get("threshold", -std::numeric_limits::max()); + atLeast = file.get("atLeast", 1); + atMost = file.get("atMost", std::numeric_limits::max()); + args = file.get("args", false); lastValue = -std::numeric_limits::max(); } @@ -462,9 +462,9 @@ class histOutput : public Output void initialize(const FileList &targetFiles, const FileList &queryFiles) { Output::initialize(targetFiles, queryFiles); - min = file.getFloat("min", -5); - max = file.getFloat("max", 5); - step = file.getFloat("step", 0.1); + min = file.get("min", -5); + max = file.get("max", 5); + step = file.get("step", 0.1); bins = QVector((max-min)/step, 0); } diff --git a/sdk/plugins/pixel.cpp b/sdk/plugins/pixel.cpp index 3514b53..e301442 100644 --- a/sdk/plugins/pixel.cpp +++ b/sdk/plugins/pixel.cpp @@ -120,7 +120,7 @@ class PerPixelClassifierTransform : public MetaTransform uchar *psrc = src[n].ptr(); ptemp[n] = psrc[index]; } - cv::Mat labelMat = src.file.get("labels").value(); + cv::Mat labelMat = src.file.value("labels").value(); uchar* plabel = labelMat.ptr(); temp.file.setLabel(plabel[index]); diff --git a/sdk/plugins/quality.cpp b/sdk/plugins/quality.cpp index ce476bd..561fa48 100644 --- a/sdk/plugins/quality.cpp +++ b/sdk/plugins/quality.cpp @@ -53,8 +53,8 @@ class ImpostorUniquenessMeasureTransform : public Transform { dst = src; float ium = calculateIUM(src, impostors); - dst.file.insert("Impostor_Uniqueness_Measure", ium); - dst.file.insert("Impostor_Uniqueness_Measure_Bin", ium < mean-stddev ? 0 : (ium < mean+stddev ? 1 : 2)); + dst.file.set("Impostor_Uniqueness_Measure", ium); + dst.file.set("Impostor_Uniqueness_Measure_Bin", ium < mean-stddev ? 0 : (ium < mean+stddev ? 1 : 2)); } void store(QDataStream &stream) const diff --git a/sdk/plugins/register.cpp b/sdk/plugins/register.cpp index d8c2dbc..bd96176 100644 --- a/sdk/plugins/register.cpp +++ b/sdk/plugins/register.cpp @@ -73,9 +73,9 @@ class AffineTransform : public UntrainableTransform src.file.contains("Affine_1_Y") && (src.file.contains("Affine_2_X") || twoPoints) && (src.file.contains("Affine_2_Y") || twoPoints)) { - srcPoints[0] = Point2f(src.file.getFloat("Affine_0_X"), src.file.getFloat("Affine_0_Y")); - srcPoints[1] = Point2f(src.file.getFloat("Affine_1_X"), src.file.getFloat("Affine_1_Y")); - if (!twoPoints) srcPoints[2] = Point2f(src.file.getFloat("Affine_2_X"), src.file.getFloat("Affine_2_Y")); + srcPoints[0] = Point2f(src.file.get("Affine_0_X"), src.file.get("Affine_0_Y")); + srcPoints[1] = Point2f(src.file.get("Affine_1_X"), src.file.get("Affine_1_Y")); + if (!twoPoints) srcPoints[2] = Point2f(src.file.get("Affine_2_X"), src.file.get("Affine_2_Y")); } else { const QList landmarks = OpenCVUtils::toPoints(src.file.landmarks()); @@ -87,13 +87,13 @@ class AffineTransform : public UntrainableTransform srcPoints[1] = landmarks[1]; if (!twoPoints) srcPoints[2] = landmarks[2]; - dst.file.insert("Affine_0_X", landmarks[0].x); - dst.file.insert("Affine_0_Y", landmarks[0].y); - dst.file.insert("Affine_1_X", landmarks[1].x); - dst.file.insert("Affine_1_Y", landmarks[1].y); + dst.file.set("Affine_0_X", landmarks[0].x); + dst.file.set("Affine_0_Y", landmarks[0].y); + dst.file.set("Affine_1_X", landmarks[1].x); + dst.file.set("Affine_1_Y", landmarks[1].y); if (!twoPoints) { - dst.file.insert("Affine_2_X", landmarks[2].x); - dst.file.insert("Affine_2_Y", landmarks[2].y); + dst.file.set("Affine_2_X", landmarks[2].x); + dst.file.set("Affine_2_Y", landmarks[2].y); } } } diff --git a/sdk/plugins/validate.cpp b/sdk/plugins/validate.cpp index db9a2a5..e372858 100644 --- a/sdk/plugins/validate.cpp +++ b/sdk/plugins/validate.cpp @@ -22,7 +22,7 @@ class CrossValidateTransform : public MetaTransform int numPartitions = 0; QList partitions; partitions.reserve(data.size()); foreach (const File &file, data.files()) { - partitions.append(file.getInt("Cross_Validation_Partition", 0)); + partitions.append(file.get("Cross_Validation_Partition", 0)); numPartitions = std::max(numPartitions, partitions.last()+1); } @@ -48,7 +48,7 @@ class CrossValidateTransform : public MetaTransform void project(const Template &src, Template &dst) const { - transforms[src.file.getInt("Cross_Validation_Partition", 0)]->project(src, dst); + transforms[src.file.get("Cross_Validation_Partition", 0)]->project(src, dst); } void store(QDataStream &stream) const @@ -82,8 +82,8 @@ class CrossValidateDistance : public Distance float compare(const Template &a, const Template &b) const { - const int partitionA = a.file.getInt("Cross_Validation_Partition", 0); - const int partitionB = b.file.getInt("Cross_Validation_Partition", 0); + const int partitionA = a.file.get("Cross_Validation_Partition", 0); + const int partitionB = b.file.get("Cross_Validation_Partition", 0); return (partitionA != partitionB) ? -std::numeric_limits::max() : 0; } }; @@ -104,7 +104,7 @@ class FilterDistance : public Distance (void) b; // Query template isn't checked foreach (const QString &key, Globals->filters.keys()) { bool keep = false; - const QString metadata = a.file.getString(key, ""); + const QString metadata = a.file.get(key, ""); if (metadata.isEmpty()) continue; foreach (const QString &value, Globals->filters[key]) { if (metadata == value) { -- libgit2 0.21.4