Commit b32f0957c09fd4c6b53fec705d91600c0fe36d32
Merge pull request #288 from biometrics/classification_interface
Implementation of Classification Interface
Showing
5 changed files
with
38 additions
and
14 deletions
openbr/gui/classifier.cpp
| ... | ... | @@ -7,7 +7,7 @@ using namespace br; |
| 7 | 7 | |
| 8 | 8 | /**** CLASSIFIER ****/ |
| 9 | 9 | /*** PUBLIC ***/ |
| 10 | -Classifier::Classifier(QWidget *parent) | |
| 10 | +GUIClassifier::GUIClassifier(QWidget *parent) | |
| 11 | 11 | : QLabel(parent) |
| 12 | 12 | { |
| 13 | 13 | setAlignment(Qt::AlignCenter); |
| ... | ... | @@ -15,26 +15,26 @@ Classifier::Classifier(QWidget *parent) |
| 15 | 15 | connect(this, SIGNAL(newClassification(QString,QString)), this, SLOT(setClassification(QString,QString))); |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | -void Classifier::setAlgorithm(const QString &algorithm) | |
| 18 | +void GUIClassifier::setAlgorithm(const QString &algorithm) | |
| 19 | 19 | { |
| 20 | 20 | this->algorithm = algorithm; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /*** PUBLIC SLOTS ***/ |
| 24 | -void Classifier::classify(const File &file) | |
| 24 | +void GUIClassifier::classify(const File &file) | |
| 25 | 25 | { |
| 26 | - QtConcurrent::run(this, &Classifier::_classify, file); | |
| 26 | + QtConcurrent::run(this, &GUIClassifier::_classify, file); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /*** PRIVATE SLOTS ***/ |
| 30 | -void Classifier::setClassification(const QString &key, const QString &value) | |
| 30 | +void GUIClassifier::setClassification(const QString &key, const QString &value) | |
| 31 | 31 | { |
| 32 | 32 | if (key.isEmpty()) clear(); |
| 33 | 33 | else setText(QString("%1: <b>%2</b>").arg(key, value)); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /*** PRIVATE ***/ |
| 37 | -void Classifier::_classify(File file) | |
| 37 | +void GUIClassifier::_classify(File file) | |
| 38 | 38 | { |
| 39 | 39 | QString key, value; |
| 40 | 40 | QSharedPointer<Transform> transform = Transform::fromAlgorithm(algorithm); | ... | ... |
openbr/gui/classifier.h
| 1 | -#ifndef BR_CLASSIFIER_H | |
| 2 | -#define BR_CLASSIFIER_H | |
| 1 | +#ifndef BR_GUICLASSIFIER_H | |
| 2 | +#define BR_GUICLASSIFIER_H | |
| 3 | 3 | |
| 4 | 4 | #include <QLabel> |
| 5 | 5 | #include <QWidget> |
| ... | ... | @@ -9,13 +9,13 @@ |
| 9 | 9 | namespace br |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | -class BR_EXPORT Classifier : public QLabel | |
| 12 | +class BR_EXPORT GUIClassifier : public QLabel | |
| 13 | 13 | { |
| 14 | 14 | Q_OBJECT |
| 15 | 15 | QString algorithm; |
| 16 | 16 | |
| 17 | 17 | public: |
| 18 | - explicit Classifier(QWidget *parent = 0); | |
| 18 | + explicit GUIClassifier(QWidget *parent = 0); | |
| 19 | 19 | void setAlgorithm(const QString &algorithm); |
| 20 | 20 | |
| 21 | 21 | public slots: |
| ... | ... | @@ -33,4 +33,4 @@ signals: |
| 33 | 33 | |
| 34 | 34 | } // namespace br |
| 35 | 35 | |
| 36 | -#endif // BR_CLASSIFIER_H | |
| 36 | +#endif // BR_GUICLASSIFIER_H | ... | ... |
openbr/gui/templatemetadata.cpp
| ... | ... | @@ -21,7 +21,7 @@ TemplateMetadata::TemplateMetadata(QWidget *parent) |
| 21 | 21 | |
| 22 | 22 | void TemplateMetadata::addClassifier(const QString &classifier_, const QString algorithm) |
| 23 | 23 | { |
| 24 | - QSharedPointer<Classifier> classifier(new Classifier()); | |
| 24 | + QSharedPointer<GUIClassifier> classifier(new GUIClassifier()); | |
| 25 | 25 | classifier->setAlgorithm(classifier_); |
| 26 | 26 | layout->addWidget(classifier.data()); |
| 27 | 27 | conditionalClassifiers.append(ConditionalClassifier(algorithm, classifier)); | ... | ... |
openbr/gui/templatemetadata.h
| ... | ... | @@ -24,10 +24,10 @@ class BR_EXPORT TemplateMetadata : public QWidget |
| 24 | 24 | struct ConditionalClassifier |
| 25 | 25 | { |
| 26 | 26 | QString algorithm; |
| 27 | - QSharedPointer<Classifier> classifier; | |
| 27 | + QSharedPointer<GUIClassifier> classifier; | |
| 28 | 28 | |
| 29 | 29 | ConditionalClassifier() {} |
| 30 | - ConditionalClassifier(const QString &algorithm_, const QSharedPointer<Classifier> &classifier_) | |
| 30 | + ConditionalClassifier(const QString &algorithm_, const QSharedPointer<GUIClassifier> &classifier_) | |
| 31 | 31 | : algorithm(algorithm_), classifier(classifier_) {} |
| 32 | 32 | }; |
| 33 | 33 | QList<ConditionalClassifier> conditionalClassifiers; | ... | ... |
openbr/openbr_plugin.h
| ... | ... | @@ -1376,6 +1376,30 @@ private: |
| 1376 | 1376 | { (void) targetGallery; (void) queryGallery; (void) output; return false; } |
| 1377 | 1377 | }; |
| 1378 | 1378 | |
| 1379 | +class BR_EXPORT Representation : public Object | |
| 1380 | +{ | |
| 1381 | + Q_OBJECT | |
| 1382 | + | |
| 1383 | +public: | |
| 1384 | + virtual ~Representation() {} | |
| 1385 | + | |
| 1386 | + virtual cv::Mat preprocess(const cv::Mat &image) const { return image; } | |
| 1387 | + // By convention, an empty indices list will result in all feature responses being calculated | |
| 1388 | + // and returned. | |
| 1389 | + virtual cv::Mat evaluate(const cv::Mat &image, const QList<int> &indices = QList<int>()) const = 0; | |
| 1390 | +}; | |
| 1391 | + | |
| 1392 | +class BR_EXPORT Classifier : public Object | |
| 1393 | +{ | |
| 1394 | + Q_OBJECT | |
| 1395 | + | |
| 1396 | +public: | |
| 1397 | + virtual ~Classifier() {} | |
| 1398 | + | |
| 1399 | + virtual void train(const QList<cv::Mat> &images, const QList<float> &labels) = 0; | |
| 1400 | + virtual float classify(const cv::Mat &image) const = 0; | |
| 1401 | +}; | |
| 1402 | + | |
| 1379 | 1403 | /*! |
| 1380 | 1404 | * \brief Returns \c true if the algorithm is a classifier, \c false otherwise. |
| 1381 | 1405 | * | ... | ... |