Commit e418200fac69243ba524763bfa6e8d5b69a55231
Merge branch 'master' of https://github.com/biometrics/openbr
Showing
7 changed files
with
138 additions
and
64 deletions
openbr/core/core.cpp
| @@ -490,9 +490,18 @@ void br::Cat(const QStringList &inputGalleries, const QString &outputGallery) | @@ -490,9 +490,18 @@ void br::Cat(const QStringList &inputGalleries, const QString &outputGallery) | ||
| 490 | } | 490 | } |
| 491 | } | 491 | } |
| 492 | 492 | ||
| 493 | -QSharedPointer<br::Transform> br::Transform::fromAlgorithm(const QString &algorithm) | 493 | +QSharedPointer<br::Transform> br::Transform::fromAlgorithm(const QString &algorithm, bool preprocess) |
| 494 | { | 494 | { |
| 495 | - return AlgorithmManager::getAlgorithm(algorithm)->transform; | 495 | + if (!preprocess) |
| 496 | + return AlgorithmManager::getAlgorithm(algorithm)->transform; | ||
| 497 | + else { | ||
| 498 | + QSharedPointer<Transform> orig_tform = AlgorithmManager::getAlgorithm(algorithm)->transform; | ||
| 499 | + QSharedPointer<Transform> newRoot = QSharedPointer<Transform>(Transform::make("Stream(Identity)", NULL)); | ||
| 500 | + WrapperTransform * downcast = dynamic_cast<WrapperTransform *> (newRoot.data()); | ||
| 501 | + downcast->transform = orig_tform.data(); | ||
| 502 | + downcast->init(); | ||
| 503 | + return newRoot; | ||
| 504 | + } | ||
| 496 | } | 505 | } |
| 497 | 506 | ||
| 498 | QSharedPointer<br::Distance> br::Distance::fromAlgorithm(const QString &algorithm) | 507 | QSharedPointer<br::Distance> br::Distance::fromAlgorithm(const QString &algorithm) |
openbr/openbr_plugin.h
| @@ -1105,7 +1105,7 @@ public: | @@ -1105,7 +1105,7 @@ public: | ||
| 1105 | 1105 | ||
| 1106 | virtual ~Transform() {} | 1106 | virtual ~Transform() {} |
| 1107 | static Transform *make(QString str, QObject *parent); /*!< \brief Make a transform from a string. */ | 1107 | static Transform *make(QString str, QObject *parent); /*!< \brief Make a transform from a string. */ |
| 1108 | - static QSharedPointer<Transform> fromAlgorithm(const QString &algorithm); /*!< \brief Retrieve an algorithm's transform. */ | 1108 | + static QSharedPointer<Transform> fromAlgorithm(const QString &algorithm, bool preprocess=true); /*!< \brief Retrieve an algorithm's transform. If preprocess is true, attaches a stream transform as the root of the algorithm*/ |
| 1109 | 1109 | ||
| 1110 | virtual Transform *clone() const; /*!< \brief Copy the transform. */ | 1110 | virtual Transform *clone() const; /*!< \brief Copy the transform. */ |
| 1111 | 1111 | ||
| @@ -1124,6 +1124,7 @@ public: | @@ -1124,6 +1124,7 @@ public: | ||
| 1124 | 1124 | ||
| 1125 | /*!< \brief Apply the transform to a single template. Typically used by independent transforms */ | 1125 | /*!< \brief Apply the transform to a single template. Typically used by independent transforms */ |
| 1126 | virtual void project(const Template &src, Template &dst) const = 0; | 1126 | virtual void project(const Template &src, Template &dst) const = 0; |
| 1127 | + | ||
| 1127 | /*!< \brief Apply the transform, taking the full template list as input. | 1128 | /*!< \brief Apply the transform, taking the full template list as input. |
| 1128 | * A TemplateList is what is typically passed from transform to transform. Transforms that just | 1129 | * A TemplateList is what is typically passed from transform to transform. Transforms that just |
| 1129 | * need to operatoe on a single template at a time (and want to output exactly 1 template) can implement | 1130 | * need to operatoe on a single template at a time (and want to output exactly 1 template) can implement |
openbr/plugins/draw.cpp
| @@ -56,7 +56,7 @@ class DrawTransform : public UntrainableTransform | @@ -56,7 +56,7 @@ class DrawTransform : public UntrainableTransform | ||
| 56 | for (int i=0; i<pointsList.size(); i++) { | 56 | for (int i=0; i<pointsList.size(); i++) { |
| 57 | const Point2f &point = pointsList[i]; | 57 | const Point2f &point = pointsList[i]; |
| 58 | circle(dst, point, 3, color, -1); | 58 | circle(dst, point, 3, color, -1); |
| 59 | - if (verbose) putText(dst, QString::number(i).toStdString(), point, FONT_HERSHEY_SIMPLEX, 0.5, verboseColor, 1); | 59 | + if (verbose) putText(dst, QString("%1,(%2,%3)").arg(QString::number(i),QString::number(point.x),QString::number(point.y)).toStdString(), point, FONT_HERSHEY_SIMPLEX, 0.5, verboseColor, 1); |
| 60 | } | 60 | } |
| 61 | } | 61 | } |
| 62 | if (rects) { | 62 | if (rects) { |
| @@ -336,8 +336,7 @@ class AdjacentOverlayTransform : public Transform | @@ -336,8 +336,7 @@ class AdjacentOverlayTransform : public Transform | ||
| 336 | 336 | ||
| 337 | void init() | 337 | void init() |
| 338 | { | 338 | { |
| 339 | - opener = br::Transform::fromAlgorithm("Cache(Open)"); | ||
| 340 | - | 339 | + opener = QSharedPointer<br::Transform>(br::Transform::make("Cache(Open)", NULL)); |
| 341 | } | 340 | } |
| 342 | 341 | ||
| 343 | }; | 342 | }; |
openbr/plugins/landmarks.cpp
| @@ -305,6 +305,113 @@ class DrawDelaunayTransform : public UntrainableTransform | @@ -305,6 +305,113 @@ class DrawDelaunayTransform : public UntrainableTransform | ||
| 305 | 305 | ||
| 306 | BR_REGISTER(Transform, DrawDelaunayTransform) | 306 | BR_REGISTER(Transform, DrawDelaunayTransform) |
| 307 | 307 | ||
| 308 | +/*! | ||
| 309 | + * \ingroup transforms | ||
| 310 | + * \brief Read landmarks from a file and associate them with the correct templates. | ||
| 311 | + * \author Scott Klum \cite sklum | ||
| 312 | + * | ||
| 313 | + * Example of the format: | ||
| 314 | + * \code | ||
| 315 | + * image_001.jpg:146.000000,190.000000,227.000000,186.000000,202.000000,256.000000 | ||
| 316 | + * image_002.jpg:75.000000,235.000000,140.000000,225.000000,91.000000,300.000000 | ||
| 317 | + * image_003.jpg:158.000000,186.000000,246.000000,188.000000,208.000000,233.000000 | ||
| 318 | + * \endcode | ||
| 319 | + */ | ||
| 320 | +class ReadLandmarksTransform : public UntrainableTransform | ||
| 321 | +{ | ||
| 322 | + Q_OBJECT | ||
| 323 | + | ||
| 324 | + Q_PROPERTY(QString file READ get_file WRITE set_file RESET reset_file STORED false) | ||
| 325 | + Q_PROPERTY(QString imageDelimiter READ get_imageDelimiter WRITE set_imageDelimiter RESET reset_imageDelimiter STORED false) | ||
| 326 | + Q_PROPERTY(QString landmarkDelimiter READ get_landmarkDelimiter WRITE set_landmarkDelimiter RESET reset_landmarkDelimiter STORED false) | ||
| 327 | + BR_PROPERTY(QString, file, QString()) | ||
| 328 | + BR_PROPERTY(QString, imageDelimiter, ":") | ||
| 329 | + BR_PROPERTY(QString, landmarkDelimiter, ",") | ||
| 330 | + | ||
| 331 | + QHash<QString, QList<QPointF> > landmarks; | ||
| 332 | + | ||
| 333 | + void init() | ||
| 334 | + { | ||
| 335 | + QFile f(file); | ||
| 336 | + if (!f.open(QFile::ReadOnly | QFile::Text)) | ||
| 337 | + qFatal("Failed to open %s for reading.", qPrintable(f.fileName())); | ||
| 338 | + | ||
| 339 | + while (!f.atEnd()) { | ||
| 340 | + const QStringList words = QString(f.readLine()).split(imageDelimiter); | ||
| 341 | + const QStringList lm = words[1].split(landmarkDelimiter); | ||
| 342 | + | ||
| 343 | + QList<QPointF> points; | ||
| 344 | + bool ok; | ||
| 345 | + for (int i=0; i<lm.size(); i+=2) | ||
| 346 | + points.append(QPointF(lm[i].toFloat(&ok),lm[i+1].toFloat(&ok))); | ||
| 347 | + if (!ok) qFatal("Failed to read landmark."); | ||
| 348 | + | ||
| 349 | + landmarks.insert(words[0],points); | ||
| 350 | + } | ||
| 351 | + } | ||
| 352 | + | ||
| 353 | + void project(const Template &src, Template &dst) const | ||
| 354 | + { | ||
| 355 | + dst = src; | ||
| 356 | + | ||
| 357 | + dst.file.appendPoints(landmarks[dst.file.fileName()]); | ||
| 358 | + } | ||
| 359 | +}; | ||
| 360 | + | ||
| 361 | +BR_REGISTER(Transform, ReadLandmarksTransform) | ||
| 362 | + | ||
| 363 | +/*! | ||
| 364 | + * \ingroup transforms | ||
| 365 | + * \brief Name a point | ||
| 366 | + * \author Scott Klum \cite sklum | ||
| 367 | + */ | ||
| 368 | +class NamePointsTransform : public UntrainableMetaTransform | ||
| 369 | +{ | ||
| 370 | + Q_OBJECT | ||
| 371 | + Q_PROPERTY(QList<int> indices READ get_indices WRITE set_indices RESET reset_indices STORED false) | ||
| 372 | + Q_PROPERTY(QStringList names READ get_names WRITE set_names RESET reset_names STORED false) | ||
| 373 | + BR_PROPERTY(QList<int>, indices, QList<int>()) | ||
| 374 | + BR_PROPERTY(QStringList, names, QStringList()) | ||
| 375 | + | ||
| 376 | + void project(const Template &src, Template &dst) const | ||
| 377 | + { | ||
| 378 | + if (indices.size() != names.size()) qFatal("Point/name size mismatch"); | ||
| 379 | + | ||
| 380 | + dst = src; | ||
| 381 | + | ||
| 382 | + QList<QPointF> points = src.file.points(); | ||
| 383 | + | ||
| 384 | + for (int i=0; i<indices.size(); i++) { | ||
| 385 | + if (indices[i] < points.size()) dst.file.set(names[i], points[indices[i]]); | ||
| 386 | + else qFatal("Idex out of range."); | ||
| 387 | + } | ||
| 388 | + } | ||
| 389 | +}; | ||
| 390 | + | ||
| 391 | +BR_REGISTER(Transform, NamePointsTransform) | ||
| 392 | + | ||
| 393 | +/*! | ||
| 394 | + * \ingroup transforms | ||
| 395 | + * \brief Remove a name from a point | ||
| 396 | + * \author Scott Klum \cite sklum | ||
| 397 | + */ | ||
| 398 | +class AnonymizePointsTransform : public UntrainableMetaTransform | ||
| 399 | +{ | ||
| 400 | + Q_OBJECT | ||
| 401 | + Q_PROPERTY(QStringList names READ get_names WRITE set_names RESET reset_names STORED false) | ||
| 402 | + BR_PROPERTY(QStringList, names, QStringList()) | ||
| 403 | + | ||
| 404 | + void project(const Template &src, Template &dst) const | ||
| 405 | + { | ||
| 406 | + dst = src; | ||
| 407 | + | ||
| 408 | + foreach (const QString &name, names) | ||
| 409 | + if (src.file.contains(name)) dst.file.appendPoint(src.file.get<QPointF>(name)); | ||
| 410 | + } | ||
| 411 | +}; | ||
| 412 | + | ||
| 413 | +BR_REGISTER(Transform, AnonymizePointsTransform) | ||
| 414 | + | ||
| 308 | } // namespace br | 415 | } // namespace br |
| 309 | 416 | ||
| 310 | #include "landmarks.moc" | 417 | #include "landmarks.moc" |
openbr/plugins/meta.cpp
| @@ -248,8 +248,8 @@ class ExpandTransform : public UntrainableMetaTransform | @@ -248,8 +248,8 @@ class ExpandTransform : public UntrainableMetaTransform | ||
| 248 | 248 | ||
| 249 | virtual void project(const Template & src, Template & dst) const | 249 | virtual void project(const Template & src, Template & dst) const |
| 250 | { | 250 | { |
| 251 | - qFatal("this has gone bad"); | ||
| 252 | - (void) src; (void) dst; | 251 | + dst = src; |
| 252 | + qDebug("Called Expand project(Template,Template), nothing will happen"); | ||
| 253 | } | 253 | } |
| 254 | }; | 254 | }; |
| 255 | 255 |
openbr/plugins/stream.cpp
| @@ -1007,14 +1007,24 @@ public: | @@ -1007,14 +1007,24 @@ public: | ||
| 1007 | 1007 | ||
| 1008 | void project(const Template &src, Template &dst) const | 1008 | void project(const Template &src, Template &dst) const |
| 1009 | { | 1009 | { |
| 1010 | - (void) src; (void) dst; | ||
| 1011 | - qFatal("nope"); | 1010 | + TemplateList in; |
| 1011 | + in.append(src); | ||
| 1012 | + TemplateList out; | ||
| 1013 | + CompositeTransform::project(in,out); | ||
| 1014 | + dst = out.first(); | ||
| 1015 | + if (out.size() > 1) | ||
| 1016 | + qDebug("Returning first output template only"); | ||
| 1012 | } | 1017 | } |
| 1013 | 1018 | ||
| 1014 | void projectUpdate(const Template &src, Template &dst) | 1019 | void projectUpdate(const Template &src, Template &dst) |
| 1015 | { | 1020 | { |
| 1016 | - (void) src; (void) dst; | ||
| 1017 | - qFatal("whatever"); | 1021 | + TemplateList in; |
| 1022 | + in.append(src); | ||
| 1023 | + TemplateList out; | ||
| 1024 | + projectUpdate(in,out); | ||
| 1025 | + dst = out.first(); | ||
| 1026 | + if (out.size() > 1) | ||
| 1027 | + qDebug("Returning first output template only"); | ||
| 1018 | } | 1028 | } |
| 1019 | 1029 | ||
| 1020 | 1030 |
openbr/plugins/template.cpp
| @@ -50,58 +50,6 @@ class RemoveTemplatesTransform : public UntrainableMetaTransform | @@ -50,58 +50,6 @@ class RemoveTemplatesTransform : public UntrainableMetaTransform | ||
| 50 | 50 | ||
| 51 | BR_REGISTER(Transform, RemoveTemplatesTransform) | 51 | BR_REGISTER(Transform, RemoveTemplatesTransform) |
| 52 | 52 | ||
| 53 | -/*! | ||
| 54 | - * \ingroup transforms | ||
| 55 | - * \brief Name a point | ||
| 56 | - * \author Scott Klum \cite sklum | ||
| 57 | - */ | ||
| 58 | -class NamePointsTransform : public UntrainableMetaTransform | ||
| 59 | -{ | ||
| 60 | - Q_OBJECT | ||
| 61 | - Q_PROPERTY(QList<int> indices READ get_indices WRITE set_indices RESET reset_indices STORED false) | ||
| 62 | - Q_PROPERTY(QStringList names READ get_names WRITE set_names RESET reset_names STORED false) | ||
| 63 | - BR_PROPERTY(QList<int>, indices, QList<int>()) | ||
| 64 | - BR_PROPERTY(QStringList, names, QStringList()) | ||
| 65 | - | ||
| 66 | - void project(const Template &src, Template &dst) const | ||
| 67 | - { | ||
| 68 | - if (indices.size() != names.size()) qFatal("Point/name size mismatch"); | ||
| 69 | - | ||
| 70 | - dst = src; | ||
| 71 | - | ||
| 72 | - QList<QPointF> points = src.file.points(); | ||
| 73 | - | ||
| 74 | - for (int i=0; i<indices.size(); i++) { | ||
| 75 | - if (indices[i] < points.size()) dst.file.set(names[i], points[indices[i]]); | ||
| 76 | - else qFatal("Idex out of range."); | ||
| 77 | - } | ||
| 78 | - } | ||
| 79 | -}; | ||
| 80 | - | ||
| 81 | -BR_REGISTER(Transform, NamePointsTransform) | ||
| 82 | - | ||
| 83 | -/*! | ||
| 84 | - * \ingroup transforms | ||
| 85 | - * \brief Remove a name from a point | ||
| 86 | - * \author Scott Klum \cite sklum | ||
| 87 | - */ | ||
| 88 | -class AnonymizePointsTransform : public UntrainableMetaTransform | ||
| 89 | -{ | ||
| 90 | - Q_OBJECT | ||
| 91 | - Q_PROPERTY(QStringList names READ get_names WRITE set_names RESET reset_names STORED false) | ||
| 92 | - BR_PROPERTY(QStringList, names, QStringList()) | ||
| 93 | - | ||
| 94 | - void project(const Template &src, Template &dst) const | ||
| 95 | - { | ||
| 96 | - dst = src; | ||
| 97 | - | ||
| 98 | - foreach (const QString &name, names) | ||
| 99 | - if (src.file.contains(name)) dst.file.appendPoint(src.file.get<QPointF>(name)); | ||
| 100 | - } | ||
| 101 | -}; | ||
| 102 | - | ||
| 103 | -BR_REGISTER(Transform, AnonymizePointsTransform) | ||
| 104 | - | ||
| 105 | } // namespace br | 53 | } // namespace br |
| 106 | 54 | ||
| 107 | #include "template.moc" | 55 | #include "template.moc" |