Commit 854948b3d64261984ef284dbd5fc789501f0aa8b
Merge branch 'master' of https://github.com/biometrics/openbr
Showing
8 changed files
with
67 additions
and
27 deletions
openbr/core/eigenutils.cpp
| ... | ... | @@ -16,4 +16,32 @@ void writeEigen(MatrixXf X, QString filename) { |
| 16 | 16 | format->write(br::Template(m)); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | +void writeEigen(MatrixXd X, QString filename) { | |
| 20 | + Mat m(X.rows(),X.cols(),CV_32FC1); | |
| 21 | + for (int i = 0; i < X.rows(); i++) { | |
| 22 | + for (int j = 0; j < X.cols(); j++) { | |
| 23 | + m.at<float>(i,j) = (float)X(i,j); | |
| 24 | + } | |
| 25 | + } | |
| 26 | + QScopedPointer<br::Format> format(br::Factory<br::Format>::make(filename)); | |
| 27 | + format->write(br::Template(m)); | |
| 28 | +} | |
| 19 | 29 | |
| 30 | +void writeEigen(VectorXd X, QString filename) { | |
| 31 | + Mat m(X.size(),1,CV_32FC1); | |
| 32 | + for (int i = 0; i < X.rows(); i++) { | |
| 33 | + m.at<float>(i,0) = (float)X(i); | |
| 34 | + } | |
| 35 | + QScopedPointer<br::Format> format(br::Factory<br::Format>::make(filename)); | |
| 36 | + format->write(br::Template(m)); | |
| 37 | +} | |
| 38 | + | |
| 39 | +void printEigen(Eigen::MatrixXd X) { | |
| 40 | + for (int i = 0; i < X.rows(); i++) { | |
| 41 | + QString str; | |
| 42 | + for (int j = 0; j < X.cols(); j++) { | |
| 43 | + str.append(QString::number(X(i,j)) + " "); | |
| 44 | + } | |
| 45 | + qDebug() << str; | |
| 46 | + } | |
| 47 | +} | ... | ... |
openbr/core/eigenutils.h
| ... | ... | @@ -22,6 +22,9 @@ |
| 22 | 22 | #include <assert.h> |
| 23 | 23 | |
| 24 | 24 | void writeEigen(Eigen::MatrixXf X, QString filename); |
| 25 | +void writeEigen(Eigen::MatrixXd X, QString filename); | |
| 26 | +void writeEigen(Eigen::VectorXd X, QString filename); | |
| 27 | +void printEigen(Eigen::MatrixXd X); | |
| 25 | 28 | |
| 26 | 29 | template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> |
| 27 | 30 | inline QDataStream &operator<<(QDataStream &stream, const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &mat) | ... | ... |
openbr/janus.cpp
| ... | ... | @@ -112,3 +112,14 @@ janus_error janus_verify(const janus_template a, const janus_template b, float * |
| 112 | 112 | *similarity = a_templates * b_templates / dist; |
| 113 | 113 | return JANUS_SUCCESS; |
| 114 | 114 | } |
| 115 | + | |
| 116 | +struct janus_incomplete_gallery_type | |
| 117 | +{ | |
| 118 | + QList< QPair<janus_template, janus_template_id> > templates; | |
| 119 | +}; | |
| 120 | + | |
| 121 | +janus_error janus_initialize_gallery(janus_incomplete_gallery *incomplete_gallery) | |
| 122 | +{ | |
| 123 | + *incomplete_gallery = new janus_incomplete_gallery_type(); | |
| 124 | + return JANUS_SUCCESS; | |
| 125 | +} | ... | ... |
openbr/openbr_plugin.h
| ... | ... | @@ -239,6 +239,13 @@ struct BR_EXPORT File |
| 239 | 239 | return variant.value<T>(); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | + /*!< \brief Specialization for boolean type. */ | |
| 243 | + template <bool> | |
| 244 | + bool get(const QString &key) const | |
| 245 | + { | |
| 246 | + return getBool(key); | |
| 247 | + } | |
| 248 | + | |
| 242 | 249 | /*!< \brief Returns a value for the key, returning \em defaultValue if the key does not exist or can't be converted. */ |
| 243 | 250 | template <typename T> |
| 244 | 251 | T get(const QString &key, const T &defaultValue) const |
| ... | ... | @@ -250,6 +257,13 @@ struct BR_EXPORT File |
| 250 | 257 | } |
| 251 | 258 | |
| 252 | 259 | /*!< \brief Specialization for boolean type. */ |
| 260 | + template <bool> | |
| 261 | + bool get(const QString &key, const bool &defaultValue) const | |
| 262 | + { | |
| 263 | + return getBool(key, defaultValue); | |
| 264 | + } | |
| 265 | + | |
| 266 | + /*!< \brief Specialization for boolean type. */ | |
| 253 | 267 | bool getBool(const QString &key, bool defaultValue = false) const; |
| 254 | 268 | |
| 255 | 269 | /*!< \brief Specialization for list type. Returns a list of type T for the key, throwing an error if the key does not exist or if the value cannot be converted to the specified type. */ | ... | ... |
openbr/plugins/gallery.cpp
| ... | ... | @@ -99,12 +99,12 @@ class galGallery : public Gallery |
| 99 | 99 | void init() |
| 100 | 100 | { |
| 101 | 101 | gallery.setFileName(file); |
| 102 | - if (file.get<bool>("remove", false)) | |
| 102 | + if (file.get<bool>("remove")) | |
| 103 | 103 | gallery.remove(); |
| 104 | 104 | QtUtils::touchDir(gallery); |
| 105 | 105 | QFile::OpenMode mode = QFile::ReadWrite; |
| 106 | 106 | |
| 107 | - if (file.contains("append")) | |
| 107 | + if (file.get<bool>("append")) | |
| 108 | 108 | mode |= QFile::Append; |
| 109 | 109 | |
| 110 | 110 | if (!gallery.open(mode)) | ... | ... |
openbr/plugins/template.cpp
| ... | ... | @@ -52,39 +52,23 @@ BR_REGISTER(Transform, RemoveTemplatesTransform) |
| 52 | 52 | |
| 53 | 53 | /*! |
| 54 | 54 | * \ingroup transforms |
| 55 | - * \brief Filters a gallery based on the value of a metadata field. | |
| 55 | + * \brief Removes a metadata field from all templates | |
| 56 | 56 | * \author Brendan Klare \cite bklare |
| 57 | 57 | */ |
| 58 | -class FilterOnMetadataTransform : public UntrainableMetaTransform | |
| 58 | +class RemoveMetadataTransform : public UntrainableTransform | |
| 59 | 59 | { |
| 60 | 60 | Q_OBJECT |
| 61 | 61 | Q_PROPERTY(QString attributeName READ get_attributeName WRITE set_attributeName RESET reset_attributeName STORED false) |
| 62 | - Q_PROPERTY(float threshold READ get_threshold WRITE set_threshold RESET reset_threshold STORED false) | |
| 63 | - Q_PROPERTY(bool isGreaterThan READ get_isGreaterThan WRITE set_isGreaterThan RESET reset_isGreaterThan STORED false) | |
| 64 | - BR_PROPERTY(QString, attributeName, "Confidence") | |
| 65 | - BR_PROPERTY(float, threshold, 0) | |
| 66 | - BR_PROPERTY(bool, isGreaterThan, true) | |
| 67 | - | |
| 68 | - void project(const TemplateList &src, TemplateList &dst) const | |
| 69 | - { | |
| 70 | - QList<Template> filtered; | |
| 71 | - foreach (Template t, src) { | |
| 72 | - if (!t.file.contains(attributeName)) | |
| 73 | - continue; | |
| 74 | - bool pass = t.file.get<float>(attributeName) > threshold; | |
| 75 | - if (isGreaterThan ? pass : !pass) | |
| 76 | - filtered.append(t); | |
| 77 | - } | |
| 78 | - dst = TemplateList(filtered); | |
| 79 | - } | |
| 62 | + BR_PROPERTY(QString, attributeName, "None") | |
| 80 | 63 | |
| 81 | 64 | void project(const Template &src, Template &dst) const |
| 82 | 65 | { |
| 83 | - (void) src; (void) dst; qFatal("shouldn't be here"); | |
| 66 | + dst = src; | |
| 67 | + if (dst.file.contains(attributeName)) | |
| 68 | + dst.file.remove(attributeName); | |
| 84 | 69 | } |
| 85 | 70 | }; |
| 86 | - | |
| 87 | -BR_REGISTER(Transform, FilterOnMetadataTransform) | |
| 71 | +BR_REGISTER(Transform, RemoveMetadataTransform) | |
| 88 | 72 | |
| 89 | 73 | } // namespace br |
| 90 | 74 | ... | ... |
scripts/lfpwToSigset.py
| ... | ... | @@ -37,7 +37,7 @@ for lfpwType in ['train','test']: |
| 37 | 37 | if not os.path.exists('sigset'): |
| 38 | 38 | os.mkdir('sigset') |
| 39 | 39 | out = open('sigset/%s.xml' % lfpwType,'w') |
| 40 | - print >> out, xmlRoot.toprettyxml() | |
| 40 | + out.write(xmlRoot.toprettyxml()) | |
| 41 | 41 | out.close() |
| 42 | 42 | |
| 43 | 43 | ... | ... |