Commit 0f0434052642ebff4d936af079482df20176b562
Merge pull request #39 from biometrics/distribute_update
Give Distribute better support for handling timevarying transforms
Showing
55 changed files
with
313 additions
and
205 deletions
openbr/frvt2012.cpp
openbr/openbr_plugin.cpp
openbr/openbr_plugin.h
| ... | ... | @@ -1085,6 +1085,14 @@ public: |
| 1085 | 1085 | return dst; |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | + /*! | |
| 1089 | + * \brief Perform the minimum amount of work necessary to make a | |
| 1090 | + * transform that can be used safely from a different thread than this | |
| 1091 | + * transform. For transforms that aren't time-varying, nothing needs to be | |
| 1092 | + * done, returning this is sufficient. | |
| 1093 | + */ | |
| 1094 | + virtual Transform * smartCopy() { return this;} | |
| 1095 | + | |
| 1088 | 1096 | protected: |
| 1089 | 1097 | Transform(bool independent = true, bool trainable = true); /*!< \brief Construct a transform. */ |
| 1090 | 1098 | inline Transform *make(const QString &description) { return make(description, this); } /*!< \brief Make a subtransform. */ |
| ... | ... | @@ -1125,133 +1133,6 @@ inline QDataStream &operator>>(QDataStream &stream, Transform &f) |
| 1125 | 1133 | f.load(stream); |
| 1126 | 1134 | return stream; |
| 1127 | 1135 | } |
| 1128 | - | |
| 1129 | -/*! | |
| 1130 | - * \brief A br::Transform for which the results of project may change due to prior calls to project | |
| 1131 | - */ | |
| 1132 | -class BR_EXPORT TimeVaryingTransform : public Transform | |
| 1133 | -{ | |
| 1134 | - Q_OBJECT | |
| 1135 | - | |
| 1136 | -public: | |
| 1137 | - virtual bool timeVarying() const { return true; } | |
| 1138 | - | |
| 1139 | - virtual void project(const Template &src, Template &dst) const | |
| 1140 | - { | |
| 1141 | - qFatal("No const project defined for time-varying transform"); | |
| 1142 | - (void) dst; (void) src; | |
| 1143 | - } | |
| 1144 | - | |
| 1145 | - virtual void project(const TemplateList &src, TemplateList &dst) const | |
| 1146 | - { | |
| 1147 | - qFatal("No const project defined for time-varying transform"); | |
| 1148 | - (void) dst; (void) src; | |
| 1149 | - } | |
| 1150 | - | |
| 1151 | - // Get a compile failure if this isn't here to go along with the other | |
| 1152 | - // projectUpdate, no idea why | |
| 1153 | - virtual void projectUpdate(const Template & src, Template & dst) | |
| 1154 | - { | |
| 1155 | - (void) src; (void) dst; | |
| 1156 | - qFatal("do something useful"); | |
| 1157 | - } | |
| 1158 | - | |
| 1159 | - virtual void projectUpdate(const TemplateList &src, TemplateList &dst) | |
| 1160 | - { | |
| 1161 | - foreach (const Template & src_part, src) { | |
| 1162 | - Template out; | |
| 1163 | - projectUpdate(src_part, out); | |
| 1164 | - dst.append(out); | |
| 1165 | - } | |
| 1166 | - } | |
| 1167 | - | |
| 1168 | -protected: | |
| 1169 | - TimeVaryingTransform(bool independent = true, bool trainable = true) : Transform(independent, trainable) {} | |
| 1170 | -}; | |
| 1171 | - | |
| 1172 | -/*! | |
| 1173 | - * \brief A br::Transform expecting multiple matrices per template. | |
| 1174 | - */ | |
| 1175 | -class BR_EXPORT MetaTransform : public Transform | |
| 1176 | -{ | |
| 1177 | - Q_OBJECT | |
| 1178 | - | |
| 1179 | -protected: | |
| 1180 | - MetaTransform() : Transform(false) {} | |
| 1181 | -}; | |
| 1182 | - | |
| 1183 | -/*! | |
| 1184 | - * \brief A br::Transform that does not require training data. | |
| 1185 | - */ | |
| 1186 | -class BR_EXPORT UntrainableTransform : public Transform | |
| 1187 | -{ | |
| 1188 | - Q_OBJECT | |
| 1189 | - | |
| 1190 | -protected: | |
| 1191 | - UntrainableTransform(bool independent = true) : Transform(independent, false) {} /*!< \brief Construct an untrainable transform. */ | |
| 1192 | - | |
| 1193 | -private: | |
| 1194 | - Transform *clone() const { return const_cast<UntrainableTransform*>(this); } | |
| 1195 | - void train(const TemplateList &data) { (void) data; } | |
| 1196 | - void store(QDataStream &stream) const { (void) stream; } | |
| 1197 | - void load(QDataStream &stream) { (void) stream; } | |
| 1198 | -}; | |
| 1199 | - | |
| 1200 | -/*! | |
| 1201 | - * \brief A br::MetaTransform that does not require training data. | |
| 1202 | - */ | |
| 1203 | -class BR_EXPORT UntrainableMetaTransform : public UntrainableTransform | |
| 1204 | -{ | |
| 1205 | - Q_OBJECT | |
| 1206 | - | |
| 1207 | -protected: | |
| 1208 | - UntrainableMetaTransform() : UntrainableTransform(false) {} | |
| 1209 | -}; | |
| 1210 | - | |
| 1211 | -/*! | |
| 1212 | - * \brief A MetaTransform that aggregates some sub-transforms | |
| 1213 | - */ | |
| 1214 | -class BR_EXPORT CompositeTransform : public TimeVaryingTransform | |
| 1215 | -{ | |
| 1216 | - Q_OBJECT | |
| 1217 | - | |
| 1218 | -public: | |
| 1219 | - Q_PROPERTY(QList<br::Transform*> transforms READ get_transforms WRITE set_transforms RESET reset_transforms) | |
| 1220 | - BR_PROPERTY(QList<br::Transform*>, transforms, QList<br::Transform*>()) | |
| 1221 | - | |
| 1222 | - virtual void project(const Template &src, Template &dst) const | |
| 1223 | - { | |
| 1224 | - if (timeVarying()) qFatal("No const project defined for time-varying transform"); | |
| 1225 | - _project(src, dst); | |
| 1226 | - } | |
| 1227 | - | |
| 1228 | - virtual void project(const TemplateList &src, TemplateList &dst) const | |
| 1229 | - { | |
| 1230 | - if (timeVarying()) qFatal("No const project defined for time-varying transform"); | |
| 1231 | - _project(src, dst); | |
| 1232 | - } | |
| 1233 | - | |
| 1234 | - bool timeVarying() const { return isTimeVarying; } | |
| 1235 | - | |
| 1236 | - void init() | |
| 1237 | - { | |
| 1238 | - isTimeVarying = false; | |
| 1239 | - trainable = false; | |
| 1240 | - foreach (const br::Transform *transform, transforms) { | |
| 1241 | - isTimeVarying = isTimeVarying || transform->timeVarying(); | |
| 1242 | - trainable = trainable || transform->trainable; | |
| 1243 | - } | |
| 1244 | - } | |
| 1245 | - | |
| 1246 | -protected: | |
| 1247 | - bool isTimeVarying; | |
| 1248 | - | |
| 1249 | - virtual void _project(const Template & src, Template & dst) const = 0; | |
| 1250 | - virtual void _project(const TemplateList & src, TemplateList & dst) const = 0; | |
| 1251 | - | |
| 1252 | - CompositeTransform() : TimeVaryingTransform(false) {} | |
| 1253 | -}; | |
| 1254 | - | |
| 1255 | 1136 | /*! @}*/ |
| 1256 | 1137 | |
| 1257 | 1138 | /*! | ... | ... |
openbr/plugins/algorithms.cpp
openbr/plugins/cascade.cpp
| ... | ... | @@ -15,8 +15,7 @@ |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | 17 | #include <opencv2/objdetect/objdetect.hpp> |
| 18 | -#include <openbr/openbr_plugin.h> | |
| 19 | - | |
| 18 | +#include "openbr_internal.h" | |
| 20 | 19 | #include "openbr/core/opencvutils.h" |
| 21 | 20 | #include "openbr/core/resource.h" |
| 22 | 21 | ... | ... |
openbr/plugins/cluster.cpp
| ... | ... | @@ -14,7 +14,7 @@ |
| 14 | 14 | * limitations under the License. * |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | -#include <openbr/openbr_plugin.h> | |
| 17 | +#include "openbr_internal.h" | |
| 18 | 18 | #include <opencv2/flann/flann.hpp> |
| 19 | 19 | |
| 20 | 20 | #include "openbr/core/opencvutils.h" | ... | ... |
openbr/plugins/crop.cpp
openbr/plugins/ct8.cpp
openbr/plugins/cvt.cpp
| ... | ... | @@ -15,8 +15,7 @@ |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | 17 | #include <opencv2/imgproc/imgproc.hpp> |
| 18 | -#include <openbr/openbr_plugin.h> | |
| 19 | - | |
| 18 | +#include "openbr_internal.h" | |
| 20 | 19 | #include "openbr/core/opencvutils.h" |
| 21 | 20 | |
| 22 | 21 | using namespace cv; | ... | ... |
openbr/plugins/denoising.cpp
openbr/plugins/distance.cpp
| ... | ... | @@ -17,7 +17,7 @@ |
| 17 | 17 | #include <QFutureSynchronizer> |
| 18 | 18 | #include <QtConcurrentRun> |
| 19 | 19 | #include <opencv2/imgproc/imgproc.hpp> |
| 20 | -#include <openbr/openbr_plugin.h> | |
| 20 | +#include "openbr_internal.h" | |
| 21 | 21 | |
| 22 | 22 | #include "openbr/core/distance_sse.h" |
| 23 | 23 | #include "openbr/core/qtutils.h" | ... | ... |
openbr/plugins/draw.cpp
| ... | ... | @@ -15,8 +15,7 @@ |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | 17 | #include <opencv2/highgui/highgui.hpp> |
| 18 | -#include <openbr/openbr_plugin.h> | |
| 19 | - | |
| 18 | +#include "openbr_internal.h" | |
| 20 | 19 | #include "openbr/core/opencvutils.h" |
| 21 | 20 | |
| 22 | 21 | using namespace cv; | ... | ... |
openbr/plugins/eigen3.cpp
| ... | ... | @@ -15,7 +15,7 @@ |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | 17 | #include <Eigen/Dense> |
| 18 | -#include <openbr/openbr_plugin.h> | |
| 18 | +#include "openbr_internal.h" | |
| 19 | 19 | |
| 20 | 20 | #include "openbr/core/common.h" |
| 21 | 21 | #include "openbr/core/eigenutils.h" | ... | ... |
openbr/plugins/eyes.cpp
openbr/plugins/fill.cpp
openbr/plugins/filter.cpp
| ... | ... | @@ -15,8 +15,7 @@ |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | 17 | #include <opencv2/imgproc/imgproc.hpp> |
| 18 | -#include <openbr/openbr_plugin.h> | |
| 19 | - | |
| 18 | +#include "openbr_internal.h" | |
| 20 | 19 | #include "openbr/core/tanh_sse.h" |
| 21 | 20 | |
| 22 | 21 | using namespace cv; | ... | ... |
openbr/plugins/format.cpp
openbr/plugins/gallery.cpp
openbr/plugins/gui.cpp
openbr/plugins/hash.cpp
| ... | ... | @@ -15,8 +15,7 @@ |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | 17 | #include <QCryptographicHash> |
| 18 | -#include <openbr/openbr_plugin.h> | |
| 19 | - | |
| 18 | +#include "openbr_internal.h" | |
| 20 | 19 | #include "openbr/core/qtutils.h" |
| 21 | 20 | |
| 22 | 21 | namespace br | ... | ... |
openbr/plugins/hist.cpp
| ... | ... | @@ -15,8 +15,7 @@ |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | 17 | #include <opencv2/imgproc/imgproc.hpp> |
| 18 | -#include <openbr/openbr_plugin.h> | |
| 19 | - | |
| 18 | +#include "openbr_internal.h" | |
| 20 | 19 | #include "openbr/core/common.h" |
| 21 | 20 | #include "openbr/core/opencvutils.h" |
| 22 | 21 | ... | ... |
openbr/plugins/integral.cpp
openbr/plugins/ipc2013.cpp
openbr/plugins/keypoint.cpp
openbr/plugins/lbp.cpp
openbr/plugins/mask.cpp
openbr/plugins/meta.cpp
| ... | ... | @@ -16,11 +16,11 @@ |
| 16 | 16 | |
| 17 | 17 | #include <QFutureSynchronizer> |
| 18 | 18 | #include <QtConcurrentRun> |
| 19 | -#include <openbr/openbr_plugin.h> | |
| 20 | - | |
| 19 | +#include "openbr_internal.h" | |
| 21 | 20 | #include "openbr/core/common.h" |
| 22 | 21 | #include "openbr/core/opencvutils.h" |
| 23 | 22 | #include "openbr/core/qtutils.h" |
| 23 | +#include "openbr/core/resource.h" | |
| 24 | 24 | |
| 25 | 25 | using namespace cv; |
| 26 | 26 | |
| ... | ... | @@ -183,7 +183,6 @@ class PipeTransform : public CompositeTransform |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - | |
| 187 | 186 | protected: |
| 188 | 187 | // Template list project -- process templates in parallel through Transform::project |
| 189 | 188 | // or if parallelism is disabled, handle them sequentially |
| ... | ... | @@ -590,6 +589,56 @@ static void _projectList(const Transform *transform, const TemplateList *src, Te |
| 590 | 589 | } |
| 591 | 590 | |
| 592 | 591 | |
| 592 | +class TransformCopier : public ResourceMaker<Transform> | |
| 593 | +{ | |
| 594 | +public: | |
| 595 | + Transform * basis; | |
| 596 | + TransformCopier(Transform * _basis) | |
| 597 | + { | |
| 598 | + basis = _basis; | |
| 599 | + } | |
| 600 | + | |
| 601 | + virtual Transform *make() const | |
| 602 | + { | |
| 603 | + return basis->smartCopy(); | |
| 604 | + } | |
| 605 | + | |
| 606 | +}; | |
| 607 | + | |
| 608 | +class TimeInvariantWrapperTransform : public MetaTransform | |
| 609 | +{ | |
| 610 | +public: | |
| 611 | + Resource<Transform> transformSource; | |
| 612 | + | |
| 613 | + TimeInvariantWrapperTransform(Transform * basis) : transformSource(new TransformCopier(basis)) | |
| 614 | + { | |
| 615 | + baseTransform = basis; | |
| 616 | + } | |
| 617 | + | |
| 618 | + virtual void project(const Template &src, Template &dst) const | |
| 619 | + { | |
| 620 | + Transform * aTransform = transformSource.acquire(); | |
| 621 | + aTransform->projectUpdate(src,dst); | |
| 622 | + transformSource.release(aTransform); | |
| 623 | + } | |
| 624 | + | |
| 625 | + | |
| 626 | + void project(const TemplateList &src, TemplateList &dst) const | |
| 627 | + { | |
| 628 | + Transform * aTransform = transformSource.acquire(); | |
| 629 | + aTransform->projectUpdate(src,dst); | |
| 630 | + transformSource.release(aTransform); | |
| 631 | + } | |
| 632 | + | |
| 633 | + void train(const TemplateList &data) | |
| 634 | + { | |
| 635 | + baseTransform->train(data); | |
| 636 | + } | |
| 637 | + | |
| 638 | +private: | |
| 639 | + Transform * baseTransform; | |
| 640 | +}; | |
| 641 | + | |
| 593 | 642 | class DistributeTemplateTransform : public MetaTransform |
| 594 | 643 | { |
| 595 | 644 | Q_OBJECT |
| ... | ... | @@ -598,6 +647,16 @@ class DistributeTemplateTransform : public MetaTransform |
| 598 | 647 | |
| 599 | 648 | public: |
| 600 | 649 | |
| 650 | + Transform * smartCopy() | |
| 651 | + { | |
| 652 | + if (!transform->timeVarying()) | |
| 653 | + return this; | |
| 654 | + | |
| 655 | + DistributeTemplateTransform * output = new DistributeTemplateTransform; | |
| 656 | + output->transform = transform->smartCopy(); | |
| 657 | + return output; | |
| 658 | + } | |
| 659 | + | |
| 601 | 660 | void train(const TemplateList &data) |
| 602 | 661 | { |
| 603 | 662 | transform->train(data); |
| ... | ... | @@ -620,15 +679,6 @@ public: |
| 620 | 679 | // Process the single elemnt templates in parallel if parallelism is enabled. |
| 621 | 680 | void project(const TemplateList &src, TemplateList &dst) const |
| 622 | 681 | { |
| 623 | - // Little ugly, but if we own a timeVaryingTransform and this gets called | |
| 624 | - // cast off the const modifier and use projectUpdate. This allows us to | |
| 625 | - // act as a single point of entry. | |
| 626 | - if (transform->timeVarying()) | |
| 627 | - { | |
| 628 | - DistributeTemplateTransform * non_const = (DistributeTemplateTransform *) this; | |
| 629 | - non_const->projectUpdate(src,dst); | |
| 630 | - return; | |
| 631 | - } | |
| 632 | 682 | // Pre-allocate output for each template |
| 633 | 683 | QList<TemplateList> output_buffer; |
| 634 | 684 | output_buffer.reserve(src.size()); |
| ... | ... | @@ -655,15 +705,16 @@ public: |
| 655 | 705 | |
| 656 | 706 | void projectUpdate(const TemplateList &src, TemplateList &dst) |
| 657 | 707 | { |
| 658 | - if (!transform->timeVarying()) { | |
| 659 | - this->project(src, dst); | |
| 660 | - return; | |
| 661 | - } | |
| 662 | - this->transform->projectUpdate(src, dst); | |
| 708 | + this->project(src, dst); | |
| 709 | + return; | |
| 663 | 710 | } |
| 664 | 711 | |
| 712 | + void init() | |
| 713 | + { | |
| 665 | 714 | |
| 666 | - private: | |
| 715 | + if (transform && transform->timeVarying()) | |
| 716 | + transform = new br::TimeInvariantWrapperTransform(transform); | |
| 717 | + } | |
| 667 | 718 | |
| 668 | 719 | }; |
| 669 | 720 | BR_REGISTER(Transform, DistributeTemplateTransform) | ... | ... |
openbr/plugins/misc.cpp
| ... | ... | @@ -15,8 +15,7 @@ |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | 17 | #include <opencv2/highgui/highgui.hpp> |
| 18 | -#include <openbr/openbr_plugin.h> | |
| 19 | - | |
| 18 | +#include "openbr_internal.h" | |
| 20 | 19 | #include "openbr/core/opencvutils.h" |
| 21 | 20 | |
| 22 | 21 | using namespace cv; | ... | ... |
openbr/plugins/mongoose.cpp
openbr/plugins/nec3.cpp
openbr/plugins/neclatent1.cpp
openbr/plugins/normalize.cpp
| ... | ... | @@ -19,7 +19,7 @@ |
| 19 | 19 | #include <opencv2/imgproc/imgproc.hpp> |
| 20 | 20 | #include <opencv2/highgui/highgui.hpp> |
| 21 | 21 | #include <Eigen/Core> |
| 22 | -#include <openbr/openbr_plugin.h> | |
| 22 | +#include "openbr_internal.h" | |
| 23 | 23 | |
| 24 | 24 | #include "openbr/core/common.h" |
| 25 | 25 | #include "openbr/core/opencvutils.h" | ... | ... |
openbr/plugins/nt4.cpp
openbr/plugins/openbr_internal.h
0 โ 100644
| 1 | +#ifndef __OPENBR_INTERNAL_H | |
| 2 | +#define __OPENBR_INTERNAL_H | |
| 3 | + | |
| 4 | +#include "openbr/openbr_plugin.h" | |
| 5 | + | |
| 6 | +namespace br | |
| 7 | +{ | |
| 8 | +/*! | |
| 9 | + * \brief A br::Transform that does not require training data. | |
| 10 | + */ | |
| 11 | +class BR_EXPORT UntrainableTransform : public Transform | |
| 12 | +{ | |
| 13 | + Q_OBJECT | |
| 14 | + | |
| 15 | +protected: | |
| 16 | + UntrainableTransform(bool independent = true) : Transform(independent, false) {} /*!< \brief Construct an untrainable transform. */ | |
| 17 | + | |
| 18 | +private: | |
| 19 | + Transform *clone() const { return const_cast<UntrainableTransform*>(this); } | |
| 20 | + void train(const TemplateList &data) { (void) data; } | |
| 21 | + void store(QDataStream &stream) const { (void) stream; } | |
| 22 | + void load(QDataStream &stream) { (void) stream; } | |
| 23 | +}; | |
| 24 | + | |
| 25 | +/*! | |
| 26 | + * \brief A br::MetaTransform that does not require training data. | |
| 27 | + */ | |
| 28 | +class BR_EXPORT UntrainableMetaTransform : public UntrainableTransform | |
| 29 | +{ | |
| 30 | + Q_OBJECT | |
| 31 | + | |
| 32 | +protected: | |
| 33 | + UntrainableMetaTransform() : UntrainableTransform(false) {} | |
| 34 | +}; | |
| 35 | + | |
| 36 | +/*! | |
| 37 | + * \brief A br::Transform for which the results of project may change due to prior calls to project | |
| 38 | + */ | |
| 39 | +class BR_EXPORT TimeVaryingTransform : public Transform | |
| 40 | +{ | |
| 41 | + Q_OBJECT | |
| 42 | + | |
| 43 | +public: | |
| 44 | + virtual bool timeVarying() const { return true; } | |
| 45 | + | |
| 46 | + virtual void project(const Template &src, Template &dst) const | |
| 47 | + { | |
| 48 | + qFatal("No const project defined for time-varying transform"); | |
| 49 | + (void) dst; (void) src; | |
| 50 | + } | |
| 51 | + | |
| 52 | + virtual void project(const TemplateList &src, TemplateList &dst) const | |
| 53 | + { | |
| 54 | + qFatal("No const project defined for time-varying transform"); | |
| 55 | + (void) dst; (void) src; | |
| 56 | + } | |
| 57 | + | |
| 58 | + // Get a compile failure if this isn't here to go along with the other | |
| 59 | + // projectUpdate, no idea why | |
| 60 | + virtual void projectUpdate(const Template & src, Template & dst) | |
| 61 | + { | |
| 62 | + (void) src; (void) dst; | |
| 63 | + qFatal("do something useful"); | |
| 64 | + } | |
| 65 | + | |
| 66 | + virtual void projectUpdate(const TemplateList &src, TemplateList &dst) | |
| 67 | + { | |
| 68 | + foreach (const Template & src_part, src) { | |
| 69 | + Template out; | |
| 70 | + projectUpdate(src_part, out); | |
| 71 | + dst.append(out); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 75 | + /*! | |
| 76 | + *\brief For transforms that don't do any training, this default implementation | |
| 77 | + * which creates a new copy of the Transform from its description string is sufficient. | |
| 78 | + */ | |
| 79 | + virtual Transform * smartCopy() | |
| 80 | + { | |
| 81 | + return this->clone(); | |
| 82 | + } | |
| 83 | + | |
| 84 | + | |
| 85 | +protected: | |
| 86 | + TimeVaryingTransform(bool independent = true, bool trainable = true) : Transform(independent, trainable) {} | |
| 87 | +}; | |
| 88 | + | |
| 89 | +/*! | |
| 90 | + * \brief A br::Transform expecting multiple matrices per template. | |
| 91 | + */ | |
| 92 | +class BR_EXPORT MetaTransform : public Transform | |
| 93 | +{ | |
| 94 | + Q_OBJECT | |
| 95 | + | |
| 96 | +protected: | |
| 97 | + MetaTransform() : Transform(false) {} | |
| 98 | +}; | |
| 99 | + | |
| 100 | +/*! | |
| 101 | + * \brief A MetaTransform that aggregates some sub-transforms | |
| 102 | + */ | |
| 103 | +class BR_EXPORT CompositeTransform : public TimeVaryingTransform | |
| 104 | +{ | |
| 105 | + Q_OBJECT | |
| 106 | + | |
| 107 | +public: | |
| 108 | + Q_PROPERTY(QList<br::Transform*> transforms READ get_transforms WRITE set_transforms RESET reset_transforms) | |
| 109 | + BR_PROPERTY(QList<br::Transform*>, transforms, QList<br::Transform*>()) | |
| 110 | + | |
| 111 | + virtual void project(const Template &src, Template &dst) const | |
| 112 | + { | |
| 113 | + if (timeVarying()) qFatal("No const project defined for time-varying transform"); | |
| 114 | + _project(src, dst); | |
| 115 | + } | |
| 116 | + | |
| 117 | + virtual void project(const TemplateList &src, TemplateList &dst) const | |
| 118 | + { | |
| 119 | + if (timeVarying()) qFatal("No const project defined for time-varying transform"); | |
| 120 | + _project(src, dst); | |
| 121 | + } | |
| 122 | + | |
| 123 | + bool timeVarying() const { return isTimeVarying; } | |
| 124 | + | |
| 125 | + void init() | |
| 126 | + { | |
| 127 | + isTimeVarying = false; | |
| 128 | + trainable = false; | |
| 129 | + foreach (const br::Transform *transform, transforms) { | |
| 130 | + isTimeVarying = isTimeVarying || transform->timeVarying(); | |
| 131 | + trainable = trainable || transform->trainable; | |
| 132 | + } | |
| 133 | + } | |
| 134 | + | |
| 135 | + /*! | |
| 136 | + * \brief Composite transforms need to create a copy of themselves if they | |
| 137 | + * have any time-varying children. If this object is flagged as time-varying, | |
| 138 | + * it creates a new copy of its own class, and gives that copy the child transforms | |
| 139 | + * returned by calling smartCopy on this transforms children | |
| 140 | + */ | |
| 141 | + Transform * smartCopy() | |
| 142 | + { | |
| 143 | + if (!timeVarying()) | |
| 144 | + return this; | |
| 145 | + | |
| 146 | + QString name = metaObject()->className(); | |
| 147 | + name.replace("Transform",""); | |
| 148 | + name += "([])"; | |
| 149 | + name.replace("br::",""); | |
| 150 | + CompositeTransform * output = dynamic_cast<CompositeTransform *>(Transform::make(name, NULL)); | |
| 151 | + | |
| 152 | + if (output == NULL) | |
| 153 | + qFatal("Dynamic cast failed!"); | |
| 154 | + | |
| 155 | + foreach(Transform* t, transforms ) | |
| 156 | + { | |
| 157 | + Transform * maybe_copy = t->smartCopy(); | |
| 158 | + if (maybe_copy->parent() == NULL) | |
| 159 | + maybe_copy->setParent(output); | |
| 160 | + output->transforms.append(t->smartCopy()); | |
| 161 | + } | |
| 162 | + | |
| 163 | + output->file = this->file; | |
| 164 | + output->classes = classes; | |
| 165 | + output->instances = instances; | |
| 166 | + output->fraction = fraction; | |
| 167 | + | |
| 168 | + output->init(); | |
| 169 | + | |
| 170 | + return output; | |
| 171 | + } | |
| 172 | + | |
| 173 | +protected: | |
| 174 | + bool isTimeVarying; | |
| 175 | + | |
| 176 | + virtual void _project(const Template & src, Template & dst) const = 0; | |
| 177 | + virtual void _project(const TemplateList & src, TemplateList & dst) const = 0; | |
| 178 | + | |
| 179 | + CompositeTransform() : TimeVaryingTransform(false) {} | |
| 180 | +}; | |
| 181 | + | |
| 182 | +} | |
| 183 | + | |
| 184 | +#endif | ... | ... |
openbr/plugins/output.cpp
openbr/plugins/pbd.cpp
openbr/plugins/pixel.cpp
openbr/plugins/plugins.cmake
| 1 | 1 | # Add source to BR_THIRDPARTY_SRC |
| 2 | 2 | # Add libs to BR_THIRDPARTY_LIBS |
| 3 | 3 | |
| 4 | -file(GLOB PLUGINS plugins/*.cpp) | |
| 4 | +file(GLOB PLUGINS plugins/*.cpp plugins/*.h) | |
| 5 | 5 | foreach(PLUGIN ${PLUGINS} ${BR_THIRDPARTY_PLUGINS}) |
| 6 | 6 | get_filename_component(PLUGIN_BASENAME ${PLUGIN} NAME_WE) |
| 7 | 7 | get_filename_component(PLUGIN_PATH ${PLUGIN} PATH) | ... | ... |
openbr/plugins/pp5.cpp
openbr/plugins/qtnetwork.cpp
openbr/plugins/quality.cpp
openbr/plugins/quantize.cpp
openbr/plugins/quantize2.cpp
openbr/plugins/random.cpp
| ... | ... | @@ -15,7 +15,7 @@ |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | 17 | #include <opencv2/imgproc/imgproc.hpp> |
| 18 | -#include <openbr/openbr_plugin.h> | |
| 18 | +#include "openbr_internal.h" | |
| 19 | 19 | |
| 20 | 20 | #include "openbr/core/common.h" |
| 21 | 21 | #include "openbr/core/opencvutils.h" | ... | ... |
openbr/plugins/reduce.cpp
openbr/plugins/regions.cpp
openbr/plugins/register.cpp
openbr/plugins/sentence.cpp
openbr/plugins/stasm.cpp
openbr/plugins/stream.cpp
openbr/plugins/svm.cpp
openbr/plugins/synthetic.cpp
openbr/plugins/validate.cpp
openbr/plugins/wavelet.cpp