diff --git a/openbr/plugins/metadata/averagepoints.cpp b/openbr/plugins/metadata/averagepoints.cpp new file mode 100644 index 0000000..09d2285 --- /dev/null +++ b/openbr/plugins/metadata/averagepoints.cpp @@ -0,0 +1,43 @@ +#include + +namespace br +{ + +/*! + * \ingroup transforms + * \brief Averages a set of landmarks into a new landmark + * \author Brendan Klare \cite bklare + */ +class AveragePointsTransform : public UntrainableMetadataTransform +{ + Q_OBJECT + Q_PROPERTY(QList indices READ get_indices WRITE set_indices RESET reset_indices STORED false) + Q_PROPERTY(QString metaName READ get_metaName WRITE set_metaName RESET reset_metaName STORED true) + Q_PROPERTY(bool append READ get_append WRITE set_append RESET reset_append STORED true) + BR_PROPERTY(QList, indices, QList()) + BR_PROPERTY(QString, metaName, "") + BR_PROPERTY(bool, append, false) + + void projectMetadata(const File &src, File &dst) const + { + dst = src; + float x1 = 0, y1 = 0; + + for (int i = 0; i < indices.size(); i++) { + x1 += src.points()[indices[i]].x(); + y1 += src.points()[indices[i]].y(); + } + + QPointF p(x1 / indices.size(), y1 / indices.size()); + if (!metaName.isEmpty()) + dst.set(metaName, p); + if (append) + dst.appendPoint(p); + } +}; + +BR_REGISTER(Transform, AveragePointsTransform) + +} // namespace br + +#include "metadata/averagepoints.moc"