Commit 2fee7df6549b4612cf2891cf5c7d614332711a7e
1 parent
c01caf17
Added ListDistance
Showing
4 changed files
with
23 additions
and
33 deletions
openbr/plugins/distance/fuse.cpp
| @@ -29,11 +29,10 @@ namespace br | @@ -29,11 +29,10 @@ namespace br | ||
| 29 | * \author Scott Klum \cite sklum | 29 | * \author Scott Klum \cite sklum |
| 30 | * \note Operation: Mean, sum, min, max are supported. | 30 | * \note Operation: Mean, sum, min, max are supported. |
| 31 | */ | 31 | */ |
| 32 | -class FuseDistance : public Distance | 32 | +class FuseDistance : public ListDistance |
| 33 | { | 33 | { |
| 34 | Q_OBJECT | 34 | Q_OBJECT |
| 35 | Q_ENUMS(Operation) | 35 | Q_ENUMS(Operation) |
| 36 | - Q_PROPERTY(QList<br::Distance*> distances READ get_distances WRITE set_distances RESET reset_distances) | ||
| 37 | Q_PROPERTY(Operation operation READ get_operation WRITE set_operation RESET reset_operation STORED false) | 36 | Q_PROPERTY(Operation operation READ get_operation WRITE set_operation RESET reset_operation STORED false) |
| 38 | Q_PROPERTY(QList<float> weights READ get_weights WRITE set_weights RESET reset_weights STORED false) | 37 | Q_PROPERTY(QList<float> weights READ get_weights WRITE set_weights RESET reset_weights STORED false) |
| 39 | 38 | ||
| @@ -42,18 +41,9 @@ public: | @@ -42,18 +41,9 @@ public: | ||
| 42 | enum Operation {Mean, Sum, Max, Min}; | 41 | enum Operation {Mean, Sum, Max, Min}; |
| 43 | 42 | ||
| 44 | private: | 43 | private: |
| 45 | - BR_PROPERTY(QList<br::Distance*>, distances, QList<br::Distance*>()) | ||
| 46 | BR_PROPERTY(Operation, operation, Mean) | 44 | BR_PROPERTY(Operation, operation, Mean) |
| 47 | BR_PROPERTY(QList<float>, weights, QList<float>()) | 45 | BR_PROPERTY(QList<float>, weights, QList<float>()) |
| 48 | 46 | ||
| 49 | - bool trainable() | ||
| 50 | - { | ||
| 51 | - for (int i=0; i<distances.size(); i++) | ||
| 52 | - if (distances[i]->trainable()) | ||
| 53 | - return true; | ||
| 54 | - return false; | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | void train(const TemplateList &src) | 47 | void train(const TemplateList &src) |
| 58 | { | 48 | { |
| 59 | // Partition the templates by matrix | 49 | // Partition the templates by matrix |
openbr/plugins/distance/pipe.cpp
| @@ -30,19 +30,9 @@ namespace br | @@ -30,19 +30,9 @@ namespace br | ||
| 30 | * If the result of the comparison with any given distance is -FLOAT_MAX then this result is returned early. | 30 | * If the result of the comparison with any given distance is -FLOAT_MAX then this result is returned early. |
| 31 | * Otherwise the returned result is the value of comparing the templates using the last br::Distance. | 31 | * Otherwise the returned result is the value of comparing the templates using the last br::Distance. |
| 32 | */ | 32 | */ |
| 33 | -class PipeDistance : public Distance | 33 | +class PipeDistance : public ListDistance |
| 34 | { | 34 | { |
| 35 | Q_OBJECT | 35 | Q_OBJECT |
| 36 | - Q_PROPERTY(QList<br::Distance*> distances READ get_distances WRITE set_distances RESET reset_distances) | ||
| 37 | - BR_PROPERTY(QList<br::Distance*>, distances, QList<br::Distance*>()) | ||
| 38 | - | ||
| 39 | - bool trainable() | ||
| 40 | - { | ||
| 41 | - for (int i=0; i<distances.size(); i++) | ||
| 42 | - if (distances[i]->trainable()) | ||
| 43 | - return true; | ||
| 44 | - return false; | ||
| 45 | - } | ||
| 46 | 36 | ||
| 47 | void train(const TemplateList &data) | 37 | void train(const TemplateList &data) |
| 48 | { | 38 | { |
openbr/plugins/distance/sum.cpp
| @@ -26,19 +26,9 @@ namespace br | @@ -26,19 +26,9 @@ namespace br | ||
| 26 | * \brief Sum match scores across multiple distances | 26 | * \brief Sum match scores across multiple distances |
| 27 | * \author Scott Klum \cite sklum | 27 | * \author Scott Klum \cite sklum |
| 28 | */ | 28 | */ |
| 29 | -class SumDistance : public Distance | 29 | +class SumDistance : public ListDistance |
| 30 | { | 30 | { |
| 31 | Q_OBJECT | 31 | Q_OBJECT |
| 32 | - Q_PROPERTY(QList<br::Distance*> distances READ get_distances WRITE set_distances RESET reset_distances) | ||
| 33 | - BR_PROPERTY(QList<br::Distance*>, distances, QList<br::Distance*>()) | ||
| 34 | - | ||
| 35 | - bool trainable() | ||
| 36 | - { | ||
| 37 | - for (int i=0; i<distances.size(); i++) | ||
| 38 | - if (distances[i]->trainable()) | ||
| 39 | - return true; | ||
| 40 | - return false; | ||
| 41 | - } | ||
| 42 | 32 | ||
| 43 | void train(const TemplateList &data) | 33 | void train(const TemplateList &data) |
| 44 | { | 34 | { |
openbr/plugins/openbr_internal.h
| @@ -485,6 +485,26 @@ private: | @@ -485,6 +485,26 @@ private: | ||
| 485 | void train(const TemplateList &data) { (void) data; } | 485 | void train(const TemplateList &data) { (void) data; } |
| 486 | }; | 486 | }; |
| 487 | 487 | ||
| 488 | +/*! | ||
| 489 | + * \brief A br::Distance that does not require training data. | ||
| 490 | + */ | ||
| 491 | +class BR_EXPORT ListDistance : public Distance | ||
| 492 | +{ | ||
| 493 | + Q_OBJECT | ||
| 494 | + | ||
| 495 | +public: | ||
| 496 | + Q_PROPERTY(QList<br::Distance*> distances READ get_distances WRITE set_distances RESET reset_distances) | ||
| 497 | + BR_PROPERTY(QList<br::Distance*>, distances, QList<br::Distance*>()) | ||
| 498 | + | ||
| 499 | + bool trainable() | ||
| 500 | + { | ||
| 501 | + for (int i=0; i<distances.size(); i++) | ||
| 502 | + if (distances[i]->trainable()) | ||
| 503 | + return true; | ||
| 504 | + return false; | ||
| 505 | + } | ||
| 506 | +}; | ||
| 507 | + | ||
| 488 | } | 508 | } |
| 489 | 509 | ||
| 490 | #endif // OPENBR_INTERNAL_H | 510 | #endif // OPENBR_INTERNAL_H |