Commit 0d7217f4bc144118ac697ab3c13f11a330db1762
Merge branch 'master' of https://github.com/biometrics/openbr
Showing
57 changed files
with
562 additions
and
244 deletions
openbr/core/qtutils.cpp
| ... | ... | @@ -290,10 +290,10 @@ QPointF QtUtils::toPoint(const QString &string) |
| 290 | 290 | QStringList values = string.split(','); |
| 291 | 291 | if (values.size() == 2) { |
| 292 | 292 | values[1].chop(1); |
| 293 | - QPointF point(values[0].mid(1).toFloat(), values[1].toFloat()); | |
| 294 | - return point; | |
| 293 | + return QPointF(values[0].mid(1).toFloat(), values[1].toFloat()); | |
| 295 | 294 | } |
| 296 | - else qFatal("Failed to convert %s to QPoint format.", qPrintable(string)); | |
| 295 | + else qFatal("Failed to convert %s to QPointF format.", qPrintable(string)); | |
| 296 | + return QPointF(); | |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | QRectF QtUtils::toRect(const QString &string) |
| ... | ... | @@ -301,10 +301,10 @@ QRectF QtUtils::toRect(const QString &string) |
| 301 | 301 | QStringList values = string.split(','); |
| 302 | 302 | if (values.size() == 4) { |
| 303 | 303 | values[3].chop(1); |
| 304 | - QRectF rect(values[0].mid(1).toFloat(), values[1].toFloat(), values[2].toFloat(), values[3].toFloat()); | |
| 305 | - return rect; | |
| 304 | + return QRectF(values[0].mid(1).toFloat(), values[1].toFloat(), values[2].toFloat(), values[3].toFloat()); | |
| 306 | 305 | } |
| 307 | - else qFatal("Failed to convert %s to QRect format.", qPrintable(string)); | |
| 306 | + else qFatal("Failed to convert %s to QRectF format.", qPrintable(string)); | |
| 307 | + return QRectF(); | |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | bool QtUtils::runRScript(const QString &file) | ... | ... |
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
| ... | ... | @@ -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 | |
| 19 | 19 | namespace br |
| 20 | 20 | { |
| ... | ... | @@ -42,7 +42,8 @@ class AlgorithmsInitializer : public Initializer |
| 42 | 42 | Globals->abbreviations.insert("OpenBR", "FaceRecognition"); |
| 43 | 43 | Globals->abbreviations.insert("GenderEstimation", "GenderClassification"); |
| 44 | 44 | Globals->abbreviations.insert("AgeEstimation", "AgeRegression"); |
| 45 | - Globals->abbreviations.insert("FaceRecognitionHoG", "{PP5Register+Affine(128,128,0.25,0.35)+Cvt(Gray)}+Gradient+Bin(0,360,9,true)+Merge+Integral+RecursiveIntegralSampler(4,2,8,Center(Hellinger)+LDA(.95)+Normalize(L1)+Div(3)+ProductQuantization(3,L1,true)[fraction=0.2]):RecursiveProductQuantization"); | |
| 45 | + Globals->abbreviations.insert("FaceRecognition2", "{PP5Register+Affine(128,128,0.25,0.35)+Cvt(Gray)}+(Gradient+Bin(0,360,9,true))/(Blur(1)+Gamma(0.2)+DoG(1,2)+ContrastEq(0.1,10)+LBP(1,2,true)+Bin(0,10,10,true))+Merge+Integral+RecursiveIntegralSampler(4,2,8,Center(Hellinger)+LDA(.95)+Normalize(L1)+Div(3)+ProductQuantization(3,L1,true)[fraction=0.2]):RecursiveProductQuantization"); | |
| 46 | + Globals->abbreviations.insert("FaceRecognitionHoG", "{PP5Register+Affine(128,128,0.25,0.35)+Cvt(Gray)}+Gradient+Bin(0,360,9)+KernelHash(9,81)+Bin(0,81,81,true)+Merge+Integral+RecursiveIntegralSampler(4,2,8,LDA(.95)+Normalize(L1)+Div(3)+ProductQuantization(3,L1,true)[fraction=0.2]):RecursiveProductQuantization"); | |
| 46 | 47 | |
| 47 | 48 | // Generic Image Processing |
| 48 | 49 | Globals->abbreviations.insert("SIFT", "Open+KeyPointDetector(SIFT)+KeyPointDescriptor(SIFT):KeyPointMatcher(BruteForce)"); |
| ... | ... | @@ -50,7 +51,6 @@ class AlgorithmsInitializer : public Initializer |
| 50 | 51 | Globals->abbreviations.insert("SmallSIFT", "Open+LimitSize(512)+KeyPointDetector(SIFT)+KeyPointDescriptor(SIFT):KeyPointMatcher(BruteForce)"); |
| 51 | 52 | Globals->abbreviations.insert("SmallSURF", "Open+LimitSize(512)+KeyPointDetector(SURF)+KeyPointDescriptor(SURF):KeyPointMatcher(BruteForce)"); |
| 52 | 53 | Globals->abbreviations.insert("ColorHist", "Open+LimitSize(512)!EnsureChannels(3)+SplitChannels+Hist(256,0,8)+Cat+Normalize(L1):L2"); |
| 53 | - Globals->abbreviations.insert("ImageRetrieval", "Open+Cvt(Gray)+Cascade(FrontalFace)+ASEFEyes+Affine(88,88,0.25,0.35)+Gradient+Bin(0,360,8,true)+Merge+Integral+IntegralSampler+WordWise(RowWisePCA(8)+RowWiseMeanCenter+Binarize,RowWisePCA)+Sentence:SentenceSimilarity"); | |
| 54 | 54 | |
| 55 | 55 | // Hash |
| 56 | 56 | Globals->abbreviations.insert("FileName", "Name+Identity:Identical"); | ... | ... |
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
| ... | ... | @@ -19,7 +19,7 @@ |
| 19 | 19 | #include <QtXml> |
| 20 | 20 | #endif // BR_EMBEDDED |
| 21 | 21 | #include <opencv2/highgui/highgui.hpp> |
| 22 | -#include <openbr/openbr_plugin.h> | |
| 22 | +#include "openbr_internal.h" | |
| 23 | 23 | |
| 24 | 24 | #include "openbr/core/bee.h" |
| 25 | 25 | #include "openbr/core/opencvutils.h" |
| ... | ... | @@ -245,6 +245,31 @@ BR_REGISTER(Format, DefaultFormat) |
| 245 | 245 | |
| 246 | 246 | /*! |
| 247 | 247 | * \ingroup formats |
| 248 | + * \brief Reads a NIST LFFS file. | |
| 249 | + * \author Josh Klontz \cite jklontz | |
| 250 | + */ | |
| 251 | +class lffsFormat : public Format | |
| 252 | +{ | |
| 253 | + Q_OBJECT | |
| 254 | + | |
| 255 | + Template read() const | |
| 256 | + { | |
| 257 | + QByteArray byteArray; | |
| 258 | + QtUtils::readFile(file.name, byteArray); | |
| 259 | + return Mat(1, byteArray.size(), CV_8UC1, byteArray.data()).clone(); | |
| 260 | + } | |
| 261 | + | |
| 262 | + void write(const Template &t) const | |
| 263 | + { | |
| 264 | + QByteArray byteArray((const char*)t.m().data, t.m().total()*t.m().elemSize()); | |
| 265 | + QtUtils::writeFile(file.name, byteArray); | |
| 266 | + } | |
| 267 | +}; | |
| 268 | + | |
| 269 | +BR_REGISTER(Format, lffsFormat) | |
| 270 | + | |
| 271 | +/*! | |
| 272 | + * \ingroup formats | |
| 248 | 273 | * \brief Reads a NIST BEE similarity matrix. |
| 249 | 274 | * \author Josh Klontz \cite jklontz |
| 250 | 275 | */ | ... | ... |
openbr/plugins/gallery.cpp
openbr/plugins/gui.cpp
| 1 | 1 | #include <QApplication> |
| 2 | 2 | #include <QLabel> |
| 3 | 3 | #include <QElapsedTimer> |
| 4 | +#include <QWaitCondition> | |
| 5 | +#include <QMutex> | |
| 4 | 6 | #include <opencv2/imgproc/imgproc.hpp> |
| 5 | -#include <openbr/openbr_plugin.h> | |
| 7 | +#include "openbr_internal.h" | |
| 6 | 8 | |
| 7 | 9 | using namespace cv; |
| 8 | 10 | |
| ... | ... | @@ -47,20 +49,39 @@ QImage toQImage(const Mat &mat) |
| 47 | 49 | return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy(); |
| 48 | 50 | } |
| 49 | 51 | |
| 52 | + | |
| 50 | 53 | // Provides slots for manipulating a QLabel, but does not inherit from QWidget. |
| 51 | 54 | // Therefore, it can be moved to the main thread if not created there initially |
| 52 | 55 | // since god forbid you create a QWidget subclass in not the main thread. |
| 53 | 56 | class GUIProxy : public QObject |
| 54 | 57 | { |
| 55 | 58 | Q_OBJECT |
| 59 | + QMutex lock; | |
| 60 | + QWaitCondition wait; | |
| 61 | + | |
| 56 | 62 | public: |
| 57 | - QLabel * window; | |
| 58 | 63 | |
| 64 | + bool eventFilter(QObject * obj, QEvent * event) | |
| 65 | + { | |
| 66 | + if (event->type() == QEvent::KeyPress) | |
| 67 | + { | |
| 68 | + wait.wakeAll(); | |
| 69 | + } | |
| 70 | + return QObject::eventFilter(obj, event); | |
| 71 | + } | |
| 72 | + | |
| 73 | + QLabel * window; | |
| 59 | 74 | GUIProxy() |
| 60 | 75 | { |
| 61 | 76 | window = NULL; |
| 62 | 77 | } |
| 63 | 78 | |
| 79 | + void waitForKey() | |
| 80 | + { | |
| 81 | + QMutexLocker locker(&lock); | |
| 82 | + wait.wait(&lock); | |
| 83 | + } | |
| 84 | + | |
| 64 | 85 | public slots: |
| 65 | 86 | |
| 66 | 87 | void showImage(const QPixmap & input) |
| ... | ... | @@ -75,6 +96,13 @@ public slots: |
| 75 | 96 | delete window; |
| 76 | 97 | window = new QLabel(); |
| 77 | 98 | window->setVisible(true); |
| 99 | + | |
| 100 | + QApplication::instance()->installEventFilter(this); | |
| 101 | + Qt::WindowFlags flags = window->windowFlags(); | |
| 102 | + | |
| 103 | + flags = flags & ~Qt::WindowCloseButtonHint; | |
| 104 | + window->setWindowFlags(flags); | |
| 105 | + window->show(); | |
| 78 | 106 | } |
| 79 | 107 | }; |
| 80 | 108 | |
| ... | ... | @@ -89,9 +117,13 @@ class Show2Transform : public TimeVaryingTransform |
| 89 | 117 | { |
| 90 | 118 | Q_OBJECT |
| 91 | 119 | public: |
| 120 | + Q_PROPERTY(bool waitInput READ get_waitInput WRITE set_waitInput RESET reset_waitInput STORED false) | |
| 121 | + BR_PROPERTY(bool, waitInput, false) | |
| 122 | + | |
| 92 | 123 | Q_PROPERTY(QStringList keys READ get_keys WRITE set_keys RESET reset_keys STORED false) |
| 93 | 124 | BR_PROPERTY(QStringList, keys, QStringList("FrameNumber")) |
| 94 | 125 | |
| 126 | + | |
| 95 | 127 | Show2Transform() : TimeVaryingTransform(false, false) |
| 96 | 128 | { |
| 97 | 129 | // Create our GUI proxy |
| ... | ... | @@ -146,6 +178,11 @@ public: |
| 146 | 178 | // by the main thread isn't damaged when we update displayBuffer |
| 147 | 179 | // later. |
| 148 | 180 | emit updateImage(displayBuffer.copy(displayBuffer.rect())); |
| 181 | + | |
| 182 | + // Blocking wait for a key-press | |
| 183 | + if (this->waitInput) | |
| 184 | + gui->waitForKey(); | |
| 185 | + | |
| 149 | 186 | } |
| 150 | 187 | } |
| 151 | 188 | } | ... | ... |
openbr/plugins/hash.cpp
| ... | ... | @@ -15,10 +15,11 @@ |
| 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 | |
| 21 | +using namespace cv; | |
| 22 | + | |
| 22 | 23 | namespace br |
| 23 | 24 | { |
| 24 | 25 | |
| ... | ... | @@ -55,6 +56,40 @@ private: |
| 55 | 56 | |
| 56 | 57 | BR_REGISTER(Transform, CryptographicHashTransform) |
| 57 | 58 | |
| 59 | +/*! | |
| 60 | + * \ingroup transforms | |
| 61 | + * \brief Kernel hash | |
| 62 | + * \author Josh Klontz \cite jklontz | |
| 63 | + */ | |
| 64 | +class KernelHashTransform : public UntrainableTransform | |
| 65 | +{ | |
| 66 | + Q_OBJECT | |
| 67 | + Q_PROPERTY(uchar dimsIn READ get_dimsIn WRITE set_dimsIn RESET reset_dimsIn STORED false) | |
| 68 | + Q_PROPERTY(uchar dimsOut READ get_dimsOut WRITE set_dimsOut RESET reset_dimsOut STORED false) | |
| 69 | + BR_PROPERTY(uchar, dimsIn, 8) | |
| 70 | + BR_PROPERTY(uchar, dimsOut, 7) | |
| 71 | + | |
| 72 | + void project(const Template &src, Template &dst) const | |
| 73 | + { | |
| 74 | + if (src.m().type() != CV_8UC1) | |
| 75 | + qFatal("Expected 8UC1 input."); | |
| 76 | + | |
| 77 | + dst = Mat::zeros(src.m().rows, src.m().cols, CV_8UC1); | |
| 78 | + const uchar *srcData = src.m().data; | |
| 79 | + uchar *dstData = dst.m().data; | |
| 80 | + const int step = src.m().cols; | |
| 81 | + for (int i=0; i<src.m().rows; i++) | |
| 82 | + for (int j=0; j<src.m().cols-1; j++) { | |
| 83 | + dstData[i*step+j] = (uint(pow(float(dimsIn),1.f))*srcData[i *step+j] | |
| 84 | + /*+ uint(pow(float(dimsIn),2.f))*srcData[(i+1)*step+j]*/ | |
| 85 | + + uint(pow(float(dimsIn),0.f))*srcData[i *step+(j+1)] | |
| 86 | + /*+ uint(pow(float(dimsIn),0.f))*srcData[(i+1)*step+(j+1)]*/) % dimsOut; | |
| 87 | + } | |
| 88 | + } | |
| 89 | +}; | |
| 90 | + | |
| 91 | +BR_REGISTER(Transform, KernelHashTransform) | |
| 92 | + | |
| 58 | 93 | } // namespace br |
| 59 | 94 | |
| 60 | 95 | #include "hash.moc" | ... | ... |
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
| 1 | 1 | #include <opencv2/imgproc/imgproc.hpp> |
| 2 | 2 | #include <Eigen/Core> |
| 3 | -#include <openbr/openbr_plugin.h> | |
| 3 | +#include "openbr_internal.h" | |
| 4 | 4 | |
| 5 | 5 | #include "openbr/core/opencvutils.h" |
| 6 | 6 | |
| ... | ... | @@ -285,7 +285,6 @@ private: |
| 285 | 285 | |
| 286 | 286 | void project(const Template &src, Template &dst) const |
| 287 | 287 | { |
| 288 | - if (src.m().type() != CV_8UC1) qFatal("Requires CV_8UC1 input."); | |
| 289 | 288 | Mat dx, dy, magnitude, angle; |
| 290 | 289 | Sobel(src, dx, CV_32F, 1, 0); |
| 291 | 290 | Sobel(src, dy, CV_32F, 0, 1); | ... | ... |
openbr/plugins/ipc2013.cpp
openbr/plugins/keypoint.cpp
| ... | ... | @@ -16,8 +16,7 @@ |
| 16 | 16 | |
| 17 | 17 | #include <opencv2/features2d/features2d.hpp> |
| 18 | 18 | #include <opencv2/nonfree/nonfree.hpp> |
| 19 | -#include <openbr/openbr_plugin.h> | |
| 20 | - | |
| 19 | +#include "openbr_internal.h" | |
| 21 | 20 | #include "openbr/core/opencvutils.h" |
| 22 | 21 | |
| 23 | 22 | using namespace cv; |
| ... | ... | @@ -109,7 +108,7 @@ BR_REGISTER(Transform, KeyPointDescriptorTransform) |
| 109 | 108 | * \brief Wraps OpenCV Key Point Matcher |
| 110 | 109 | * \author Josh Klontz \cite jklontz |
| 111 | 110 | */ |
| 112 | -class KeyPointMatcherTransform : public Distance | |
| 111 | +class KeyPointMatcherDistance : public Distance | |
| 113 | 112 | { |
| 114 | 113 | Q_OBJECT |
| 115 | 114 | Q_PROPERTY(QString matcher READ get_matcher WRITE set_matcher RESET reset_matcher STORED false) |
| ... | ... | @@ -148,7 +147,7 @@ class KeyPointMatcherTransform : public Distance |
| 148 | 147 | } |
| 149 | 148 | }; |
| 150 | 149 | |
| 151 | -BR_REGISTER(Distance, KeyPointMatcherTransform) | |
| 150 | +BR_REGISTER(Distance, KeyPointMatcherDistance) | |
| 152 | 151 | |
| 153 | 152 | /*! |
| 154 | 153 | * \ingroup transforms | ... | ... |
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
| 1 | -#include <openbr/openbr_plugin.h> | |
| 1 | +#include "openbr_internal.h" | |
| 2 | 2 | #include <LatentEFS.h> |
| 3 | 3 | |
| 4 | -// necessary to allocate a large memory though the actual template size | |
| 5 | -// may be much smaller | |
| 4 | +// Necessary to allocate a large memory though the actual template size may be much smaller | |
| 6 | 5 | #define MAX_TEMPLATE_SIZE 400000 |
| 7 | 6 | |
| 8 | 7 | namespace br |
| ... | ... | @@ -21,6 +20,7 @@ class NECLatent1Initialier : public Initializer |
| 21 | 20 | { |
| 22 | 21 | Globals->abbreviations.insert("NECTenprint1", "Open+Cvt(Gray)+NECLatent1Enroll:NECLatent1Compare"); |
| 23 | 22 | Globals->abbreviations.insert("NECLatent1", "Open+Cvt(Gray)+NECLatent1Enroll(true):NECLatent1Compare"); |
| 23 | + Globals->abbreviations.insert("NECLatentLFFS1", "Open+NECLatent1Enroll(true,ELFT_M):NECLatent1Compare(ELFT_M)"); | |
| 24 | 24 | } |
| 25 | 25 | }; |
| 26 | 26 | |
| ... | ... | @@ -41,7 +41,8 @@ class NECLatent1EnrollTransform : public UntrainableTransform |
| 41 | 41 | |
| 42 | 42 | public: |
| 43 | 43 | enum Algorithm { LFML, |
| 44 | - ELFT }; | |
| 44 | + ELFT, | |
| 45 | + ELFT_M }; | |
| 45 | 46 | |
| 46 | 47 | private: |
| 47 | 48 | BR_PROPERTY(bool, latent, false) |
| ... | ... | @@ -50,27 +51,35 @@ private: |
| 50 | 51 | void project(const Template &src, Template &dst) const |
| 51 | 52 | { |
| 52 | 53 | if (src.m().type() != CV_8UC1) qFatal("Requires 8UC1 data!"); |
| 53 | - unsigned char data[MAX_TEMPLATE_SIZE]; | |
| 54 | + uchar *data = src.m().data; | |
| 55 | + const int rows = src.m().rows; | |
| 56 | + const int columns = src.m().cols; | |
| 57 | + uchar buff[MAX_TEMPLATE_SIZE]; | |
| 58 | + uchar* pBuff = NULL; | |
| 54 | 59 | int size = 0; |
| 55 | 60 | int error; |
| 56 | 61 | |
| 57 | 62 | if (latent) { |
| 58 | - if (algorithm == LFML) error = NEC_LFML_ExtractLatent(src.m().data, src.m().rows, src.m().cols, 500, data, &size); | |
| 59 | - else error = NEC_ELFT_ExtractLatent(src.m().data, src.m().rows, src.m().cols, 500, 4, data, &size); | |
| 63 | + if (algorithm == LFML) error = NEC_LFML_ExtractLatent(data, rows, columns, 500, buff, &size); | |
| 64 | + else if (algorithm == ELFT) error = NEC_ELFT_ExtractLatent(data, rows, columns, 500, 4, buff, &size); | |
| 65 | + else error = NEC_ELFT_M_ExtractLatent(data, columns, 1, &pBuff, &size); | |
| 60 | 66 | } else { |
| 61 | - if (algorithm == LFML) error = NEC_LFML_ExtractTenprint(src.m().data, src.m().rows, src.m().cols, 500, data, &size); | |
| 62 | - else error = NEC_ELFT_ExtractTenprint(src.m().data, src.m().rows, src.m().cols, 500, 2, data, &size); | |
| 67 | + if (algorithm == LFML) error = NEC_LFML_ExtractTenprint(data, rows, columns, 500, buff, &size); | |
| 68 | + else if (algorithm == ELFT) error = NEC_ELFT_ExtractTenprint(data, rows, columns, 500, 2, buff, &size); | |
| 69 | + else qFatal("ELFT_M Tenprint not implemented."); | |
| 63 | 70 | } |
| 64 | 71 | |
| 65 | 72 | if (!error) { |
| 66 | 73 | cv::Mat n(1, size, CV_8UC1); |
| 67 | - memcpy(n.data, data, size); | |
| 74 | + memcpy(n.data, buff, size); | |
| 68 | 75 | dst.m() = n; |
| 69 | 76 | } else { |
| 70 | 77 | qWarning("NECLatent1EnrollTransform error %d for file %s.", error, qPrintable(src.file.flat())); |
| 71 | 78 | dst.m() = cv::Mat(); |
| 72 | 79 | dst.file.set("FTE", true); |
| 73 | 80 | } |
| 81 | + | |
| 82 | + if (pBuff != NULL) NEC_ELFT_M_FreeTemplate(&pBuff); | |
| 74 | 83 | } |
| 75 | 84 | }; |
| 76 | 85 | |
| ... | ... | @@ -89,17 +98,21 @@ class NECLatent1CompareDistance : public Distance |
| 89 | 98 | |
| 90 | 99 | public: |
| 91 | 100 | enum Algorithm { LFML, |
| 92 | - ELFT }; | |
| 101 | + ELFT, | |
| 102 | + ELFT_M }; | |
| 93 | 103 | |
| 94 | 104 | private: |
| 95 | 105 | BR_PROPERTY(Algorithm, algorithm, LFML) |
| 96 | 106 | |
| 97 | 107 | float compare(const Template &a, const Template &b) const |
| 98 | 108 | { |
| 109 | + uchar *aData = a.m().data; | |
| 110 | + uchar *bData = b.m().data; | |
| 99 | 111 | if (!a.m().data || !b.m().data) return -std::numeric_limits<float>::max(); |
| 100 | 112 | int score; |
| 101 | - if (algorithm == LFML) NEC_LFML_Verify(b.m().data, b.m().total(), a.m().data, a.m().total(), &score); | |
| 102 | - else NEC_ELFT_Verify(b.m().data, a.m().data, &score, 2); | |
| 113 | + if (algorithm == LFML) NEC_LFML_Verify(bData, b.m().total(), aData, a.m().total(), &score); | |
| 114 | + else if (algorithm == ELFT) NEC_ELFT_Verify(bData, aData, &score, 1); | |
| 115 | + else NEC_ELFT_M_Verify(bData, aData, &score, 1); | |
| 103 | 116 | return score; |
| 104 | 117 | } |
| 105 | 118 | }; | ... | ... |
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" |
| ... | ... | @@ -58,6 +58,9 @@ class NormalizeTransform : public UntrainableTransform |
| 58 | 58 | Q_ENUMS(NormType) |
| 59 | 59 | Q_PROPERTY(NormType normType READ get_normType WRITE set_normType RESET reset_normType STORED false) |
| 60 | 60 | |
| 61 | + Q_PROPERTY(bool ByRow READ get_ByRow WRITE set_ByRow RESET reset_ByRow STORED false) | |
| 62 | + BR_PROPERTY(bool, ByRow, false) | |
| 63 | + | |
| 61 | 64 | public: |
| 62 | 65 | /*!< */ |
| 63 | 66 | enum NormType { Inf = NORM_INF, |
| ... | ... | @@ -69,7 +72,16 @@ private: |
| 69 | 72 | |
| 70 | 73 | void project(const Template &src, Template &dst) const |
| 71 | 74 | { |
| 72 | - normalize(src, dst, 1, 0, normType, CV_32F); | |
| 75 | + if (!ByRow) normalize(src, dst, 1, 0, normType, CV_32F); | |
| 76 | + else { | |
| 77 | + dst = src; | |
| 78 | + for (int i=0; i<dst.m().rows; i++) { | |
| 79 | + Mat temp; | |
| 80 | + cv::normalize(dst.m().row(i), temp, 1, 0, normType); | |
| 81 | + temp.copyTo(dst.m().row(i)); | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 73 | 85 | } |
| 74 | 86 | }; |
| 75 | 87 | ... | ... |
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
| ... | ... | @@ -5,14 +5,12 @@ |
| 5 | 5 | #include <QMap> |
| 6 | 6 | #include <opencv/highgui.h> |
| 7 | 7 | #include <QtConcurrent> |
| 8 | -#include <openbr/openbr_plugin.h> | |
| 8 | +#include "openbr_internal.h" | |
| 9 | 9 | |
| 10 | 10 | #include "openbr/core/common.h" |
| 11 | 11 | #include "openbr/core/opencvutils.h" |
| 12 | 12 | #include "openbr/core/qtutils.h" |
| 13 | 13 | |
| 14 | -#include <iostream> | |
| 15 | - | |
| 16 | 14 | using namespace cv; |
| 17 | 15 | |
| 18 | 16 | namespace br |
| ... | ... | @@ -258,12 +256,16 @@ public: |
| 258 | 256 | next_idx = 0; |
| 259 | 257 | basis = input; |
| 260 | 258 | video.open(input.file.name.toStdString()); |
| 261 | - return video.isOpened(); | |
| 259 | + video_ok = video.isOpened(); | |
| 260 | + return video_ok; | |
| 262 | 261 | } |
| 262 | + bool video_ok; | |
| 263 | 263 | |
| 264 | - bool isOpen() { return video.isOpened(); } | |
| 264 | + bool isOpen() { return video_ok; } | |
| 265 | 265 | |
| 266 | - void close() { video.release(); } | |
| 266 | + void close() { | |
| 267 | + video.release(); | |
| 268 | + } | |
| 267 | 269 | |
| 268 | 270 | private: |
| 269 | 271 | bool getNext(FrameData & output) |
| ... | ... | @@ -279,8 +281,8 @@ private: |
| 279 | 281 | |
| 280 | 282 | bool res = video.read(output.data.last().last()); |
| 281 | 283 | if (!res) { |
| 282 | - video.release(); | |
| 283 | - return false; | |
| 284 | + video_ok = false; | |
| 285 | + return video_ok; | |
| 284 | 286 | } |
| 285 | 287 | output.data.last().file.set("FrameNumber", output.sequenceNumber); |
| 286 | 288 | return true; |
| ... | ... | @@ -299,7 +301,9 @@ public: |
| 299 | 301 | TemplateDataSource(int maxFrames) : DataSource(maxFrames) |
| 300 | 302 | { |
| 301 | 303 | current_idx = INT_MAX; |
| 304 | + data_ok = false; | |
| 302 | 305 | } |
| 306 | + bool data_ok; | |
| 303 | 307 | |
| 304 | 308 | bool open(Template &input) |
| 305 | 309 | { |
| ... | ... | @@ -309,10 +313,13 @@ public: |
| 309 | 313 | final_frame = -1; |
| 310 | 314 | last_issued = -2; |
| 311 | 315 | |
| 312 | - return isOpen(); | |
| 316 | + data_ok = current_idx < basis.size(); | |
| 317 | + return data_ok; | |
| 313 | 318 | } |
| 314 | 319 | |
| 315 | - bool isOpen() { return current_idx < basis.size() ; } | |
| 320 | + bool isOpen() { | |
| 321 | + return data_ok; | |
| 322 | + } | |
| 316 | 323 | |
| 317 | 324 | void close() |
| 318 | 325 | { |
| ... | ... | @@ -323,7 +330,8 @@ public: |
| 323 | 330 | private: |
| 324 | 331 | bool getNext(FrameData & output) |
| 325 | 332 | { |
| 326 | - if (!isOpen()) | |
| 333 | + data_ok = current_idx < basis.size(); | |
| 334 | + if (!data_ok) | |
| 327 | 335 | return false; |
| 328 | 336 | |
| 329 | 337 | output.data.append(basis[current_idx]); |
| ... | ... | @@ -332,6 +340,7 @@ private: |
| 332 | 340 | output.sequenceNumber = next_sequence; |
| 333 | 341 | next_sequence++; |
| 334 | 342 | |
| 343 | + output.data.last().file.set("FrameNumber", output.sequenceNumber); | |
| 335 | 344 | return true; |
| 336 | 345 | } |
| 337 | 346 | |
| ... | ... | @@ -595,10 +604,6 @@ public: |
| 595 | 604 | |
| 596 | 605 | FrameData * run(FrameData * input, bool & should_continue) |
| 597 | 606 | { |
| 598 | - if (input != NULL) { | |
| 599 | - dataSource.returnFrame(input); | |
| 600 | - } | |
| 601 | - | |
| 602 | 607 | // Is there anything on our input buffer? If so we should start a thread with that. |
| 603 | 608 | QWriteLocker lock(&statusLock); |
| 604 | 609 | input = dataSource.tryGetFrame(); | ... | ... |
openbr/plugins/svm.cpp
openbr/plugins/synthetic.cpp
openbr/plugins/validate.cpp
openbr/plugins/wavelet.cpp
openbr/plugins/youtube.cpp
share/openbr/openbr.svg
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
| 2 | +<!-- Created with Inkscape (http://www.inkscape.org/) --> | |
| 3 | + | |
| 4 | +<svg | |
| 5 | + xmlns:dc="http://purl.org/dc/elements/1.1/" | |
| 6 | + xmlns:cc="http://creativecommons.org/ns#" | |
| 7 | + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
| 8 | + xmlns:svg="http://www.w3.org/2000/svg" | |
| 9 | + xmlns="http://www.w3.org/2000/svg" | |
| 10 | + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" | |
| 11 | + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" | |
| 12 | + width="512" | |
| 13 | + height="512" | |
| 14 | + id="svg2" | |
| 15 | + version="1.1" | |
| 16 | + inkscape:version="0.48.2 r9819" | |
| 17 | + sodipodi:docname="openbr.svg"> | |
| 18 | + <defs | |
| 19 | + id="defs4" /> | |
| 20 | + <sodipodi:namedview | |
| 21 | + id="base" | |
| 22 | + pagecolor="#ffffff" | |
| 23 | + bordercolor="#666666" | |
| 24 | + borderopacity="1.0" | |
| 25 | + inkscape:pageopacity="0.0" | |
| 26 | + inkscape:pageshadow="2" | |
| 27 | + inkscape:zoom="1.4241042" | |
| 28 | + inkscape:cx="255.99998" | |
| 29 | + inkscape:cy="224.54497" | |
| 30 | + inkscape:document-units="px" | |
| 31 | + inkscape:current-layer="layer1" | |
| 32 | + showgrid="false" | |
| 33 | + inkscape:window-width="1386" | |
| 34 | + inkscape:window-height="856" | |
| 35 | + inkscape:window-x="54" | |
| 36 | + inkscape:window-y="0" | |
| 37 | + inkscape:window-maximized="1" /> | |
| 38 | + <metadata | |
| 39 | + id="metadata7"> | |
| 40 | + <rdf:RDF> | |
| 41 | + <cc:Work | |
| 42 | + rdf:about=""> | |
| 43 | + <dc:format>image/svg+xml</dc:format> | |
| 44 | + <dc:type | |
| 45 | + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> | |
| 46 | + <dc:title></dc:title> | |
| 47 | + </cc:Work> | |
| 48 | + </rdf:RDF> | |
| 49 | + </metadata> | |
| 50 | + <g | |
| 51 | + inkscape:label="Layer 1" | |
| 52 | + inkscape:groupmode="layer" | |
| 53 | + id="layer1" | |
| 54 | + transform="translate(0,-540.36218)"> | |
| 55 | + <rect | |
| 56 | + style="fill:#ffffff;fill-opacity:0;fill-rule:evenodd;stroke:#000000;stroke-width:4;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" | |
| 57 | + id="rect2985" | |
| 58 | + width="380.73685" | |
| 59 | + height="380.73685" | |
| 60 | + x="65.631577" | |
| 61 | + y="637.99377" /> | |
| 62 | + <path | |
| 63 | + sodipodi:type="arc" | |
| 64 | + style="fill:#ffffff;fill-opacity:0;stroke:#000000;stroke-width:3.92984693;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" | |
| 65 | + id="path2991" | |
| 66 | + sodipodi:cx="350" | |
| 67 | + sodipodi:cy="393.79074" | |
| 68 | + sodipodi:rx="218.57143" | |
| 69 | + sodipodi:ry="218.57143" | |
| 70 | + d="m 568.57143,393.79074 a 218.57143,218.57143 0 1 1 -437.14286,0 218.57143,218.57143 0 1 1 437.14286,0 z" | |
| 71 | + transform="matrix(1.0178513,0,0,1.0178514,-100.24798,395.54173)" /> | |
| 72 | + <g | |
| 73 | + transform="scale(1.1432502,0.87469915)" | |
| 74 | + style="font-size:602.20269775px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans" | |
| 75 | + id="text3808"> | |
| 76 | + <path | |
| 77 | + d="m 139.95187,956.87572 0,160.84218 83.97112,0 c 31.95257,0 68.68055,-6.5669 83.97112,-19.7009 15.48604,-13.3299 27.99007,-33.619 27.99037,-60.8672 -3e-4,-27.444 -12.50433,-47.63499 -27.99037,-60.57311 -15.29057,-13.13378 -52.01855,-19.70097 -83.97112,-19.70097 m -83.97112,-180.54319 0,132.31993 83.97112,0 c 29.01214,0 69.85673,-5.39055 83.97112,-16.17244 14.30987,-10.97737 27.99008,-27.63986 27.99037,-49.98753 -2.9e-4,-22.15099 -13.6805,-38.71546 -27.99037,-49.69348 -14.11439,-10.97727 -54.95898,-16.46609 -83.97112,-16.46648 m -139.951873,-48.81135 139.951873,0 c 45.28256,0 91.95076,9.40984 116.45474,28.22825 24.50335,18.81923 36.75519,45.57723 36.75554,80.27409 -3.5e-4,26.85635 -6.27329,48.22354 -18.81883,64.10165 -12.54621,15.87865 -30.97297,25.77813 -55.28033,29.69848 29.20809,6.27317 51.84948,19.40714 67.92423,39.40193 16.27009,19.79916 20.90689,51.96712 20.90689,77.59112 l 0,119.7126 -55.98075,0 0,-44.8424 c -17.69465,15.1339 -37.06615,24.3098 -56.82746,32.0601 -17.87739,7.0114 -36.46927,12.8733 -55.13403,12.7823 -21.46529,-0.1046 -45.63727,-9.5398 -63.32089,-15.318 l -20.44109,-13.0416 -0.20914,28.3596 -55.98075,0 0,-80.0275 -3e-6,-358.98062" | |
| 78 | + id="path3816" | |
| 79 | + inkscape:connector-curvature="0" | |
| 80 | + sodipodi:nodetypes="ccsccccccscccccsccsccscccaacccccc" /> | |
| 81 | + </g> | |
| 82 | + </g> | |
| 83 | +</svg> | ... | ... |