diff --git a/openbr/core/core.cpp b/openbr/core/core.cpp index cea16f1..2afb530 100644 --- a/openbr/core/core.cpp +++ b/openbr/core/core.cpp @@ -490,9 +490,18 @@ void br::Cat(const QStringList &inputGalleries, const QString &outputGallery) } } -QSharedPointer br::Transform::fromAlgorithm(const QString &algorithm) +QSharedPointer br::Transform::fromAlgorithm(const QString &algorithm, bool preprocess) { - return AlgorithmManager::getAlgorithm(algorithm)->transform; + if (!preprocess) + return AlgorithmManager::getAlgorithm(algorithm)->transform; + else { + QSharedPointer orig_tform = AlgorithmManager::getAlgorithm(algorithm)->transform; + QSharedPointer newRoot = QSharedPointer(Transform::make("Stream(Identity)", NULL)); + WrapperTransform * downcast = dynamic_cast (newRoot.data()); + downcast->transform = orig_tform.data(); + downcast->init(); + return newRoot; + } } QSharedPointer br::Distance::fromAlgorithm(const QString &algorithm) diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index f9acbf8..60a13e6 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -1105,7 +1105,7 @@ public: virtual ~Transform() {} static Transform *make(QString str, QObject *parent); /*!< \brief Make a transform from a string. */ - static QSharedPointer fromAlgorithm(const QString &algorithm); /*!< \brief Retrieve an algorithm's transform. */ + static QSharedPointer 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*/ virtual Transform *clone() const; /*!< \brief Copy the transform. */ @@ -1124,6 +1124,7 @@ public: /*!< \brief Apply the transform to a single template. Typically used by independent transforms */ virtual void project(const Template &src, Template &dst) const = 0; + /*!< \brief Apply the transform, taking the full template list as input. * A TemplateList is what is typically passed from transform to transform. Transforms that just * need to operatoe on a single template at a time (and want to output exactly 1 template) can implement diff --git a/openbr/plugins/draw.cpp b/openbr/plugins/draw.cpp index ea34e8b..3057b8a 100644 --- a/openbr/plugins/draw.cpp +++ b/openbr/plugins/draw.cpp @@ -56,7 +56,7 @@ class DrawTransform : public UntrainableTransform for (int i=0; i(br::Transform::make("Cache(Open)", NULL)); } }; diff --git a/openbr/plugins/landmarks.cpp b/openbr/plugins/landmarks.cpp index 79732cb..2d5e612 100644 --- a/openbr/plugins/landmarks.cpp +++ b/openbr/plugins/landmarks.cpp @@ -305,6 +305,113 @@ class DrawDelaunayTransform : public UntrainableTransform BR_REGISTER(Transform, DrawDelaunayTransform) +/*! + * \ingroup transforms + * \brief Read landmarks from a file and associate them with the correct templates. + * \author Scott Klum \cite sklum + * + * Example of the format: + * \code + * image_001.jpg:146.000000,190.000000,227.000000,186.000000,202.000000,256.000000 + * image_002.jpg:75.000000,235.000000,140.000000,225.000000,91.000000,300.000000 + * image_003.jpg:158.000000,186.000000,246.000000,188.000000,208.000000,233.000000 + * \endcode + */ +class ReadLandmarksTransform : public UntrainableTransform +{ + Q_OBJECT + + Q_PROPERTY(QString file READ get_file WRITE set_file RESET reset_file STORED false) + Q_PROPERTY(QString imageDelimiter READ get_imageDelimiter WRITE set_imageDelimiter RESET reset_imageDelimiter STORED false) + Q_PROPERTY(QString landmarkDelimiter READ get_landmarkDelimiter WRITE set_landmarkDelimiter RESET reset_landmarkDelimiter STORED false) + BR_PROPERTY(QString, file, QString()) + BR_PROPERTY(QString, imageDelimiter, ":") + BR_PROPERTY(QString, landmarkDelimiter, ",") + + QHash > landmarks; + + void init() + { + QFile f(file); + if (!f.open(QFile::ReadOnly | QFile::Text)) + qFatal("Failed to open %s for reading.", qPrintable(f.fileName())); + + while (!f.atEnd()) { + const QStringList words = QString(f.readLine()).split(imageDelimiter); + const QStringList lm = words[1].split(landmarkDelimiter); + + QList points; + bool ok; + for (int i=0; i indices READ get_indices WRITE set_indices RESET reset_indices STORED false) + Q_PROPERTY(QStringList names READ get_names WRITE set_names RESET reset_names STORED false) + BR_PROPERTY(QList, indices, QList()) + BR_PROPERTY(QStringList, names, QStringList()) + + void project(const Template &src, Template &dst) const + { + if (indices.size() != names.size()) qFatal("Point/name size mismatch"); + + dst = src; + + QList points = src.file.points(); + + for (int i=0; i(name)); + } +}; + +BR_REGISTER(Transform, AnonymizePointsTransform) + } // namespace br #include "landmarks.moc" diff --git a/openbr/plugins/meta.cpp b/openbr/plugins/meta.cpp index 7d61341..19aa56b 100644 --- a/openbr/plugins/meta.cpp +++ b/openbr/plugins/meta.cpp @@ -248,8 +248,8 @@ class ExpandTransform : public UntrainableMetaTransform virtual void project(const Template & src, Template & dst) const { - qFatal("this has gone bad"); - (void) src; (void) dst; + dst = src; + qDebug("Called Expand project(Template,Template), nothing will happen"); } }; diff --git a/openbr/plugins/stream.cpp b/openbr/plugins/stream.cpp index 65c3501..56f8b55 100644 --- a/openbr/plugins/stream.cpp +++ b/openbr/plugins/stream.cpp @@ -1007,14 +1007,24 @@ public: void project(const Template &src, Template &dst) const { - (void) src; (void) dst; - qFatal("nope"); + TemplateList in; + in.append(src); + TemplateList out; + CompositeTransform::project(in,out); + dst = out.first(); + if (out.size() > 1) + qDebug("Returning first output template only"); } void projectUpdate(const Template &src, Template &dst) { - (void) src; (void) dst; - qFatal("whatever"); + TemplateList in; + in.append(src); + TemplateList out; + projectUpdate(in,out); + dst = out.first(); + if (out.size() > 1) + qDebug("Returning first output template only"); } diff --git a/openbr/plugins/template.cpp b/openbr/plugins/template.cpp index 7c10c9f..5d92eba 100644 --- a/openbr/plugins/template.cpp +++ b/openbr/plugins/template.cpp @@ -50,58 +50,6 @@ class RemoveTemplatesTransform : public UntrainableMetaTransform BR_REGISTER(Transform, RemoveTemplatesTransform) -/*! - * \ingroup transforms - * \brief Name a point - * \author Scott Klum \cite sklum - */ -class NamePointsTransform : public UntrainableMetaTransform -{ - Q_OBJECT - Q_PROPERTY(QList indices READ get_indices WRITE set_indices RESET reset_indices STORED false) - Q_PROPERTY(QStringList names READ get_names WRITE set_names RESET reset_names STORED false) - BR_PROPERTY(QList, indices, QList()) - BR_PROPERTY(QStringList, names, QStringList()) - - void project(const Template &src, Template &dst) const - { - if (indices.size() != names.size()) qFatal("Point/name size mismatch"); - - dst = src; - - QList points = src.file.points(); - - for (int i=0; i(name)); - } -}; - -BR_REGISTER(Transform, AnonymizePointsTransform) - } // namespace br #include "template.moc"