Commit cf88ffbde31e6fcedc3434fbdf6306fe602d859d
Merge pull request #339 from biometrics/averagePointsX
Added new transform
Showing
1 changed file
with
52 additions
and
0 deletions
openbr/plugins/metadata/averagepoints.cpp
0 → 100644
| 1 | +#include <openbr/plugins/openbr_internal.h> | ||
| 2 | + | ||
| 3 | +namespace br | ||
| 4 | +{ | ||
| 5 | + | ||
| 6 | +/*! | ||
| 7 | + * \ingroup transforms | ||
| 8 | + * \brief Averages a set of landmarks into a new landmark | ||
| 9 | + * \author Brendan Klare \cite bklare | ||
| 10 | + */ | ||
| 11 | +class AveragePointsTransform : public UntrainableMetadataTransform | ||
| 12 | +{ | ||
| 13 | + Q_OBJECT | ||
| 14 | + Q_PROPERTY(QList<int> indices READ get_indices WRITE set_indices RESET reset_indices STORED false) | ||
| 15 | + Q_PROPERTY(QString metaName READ get_metaName WRITE set_metaName RESET reset_metaName STORED true) | ||
| 16 | + Q_PROPERTY(bool append READ get_append WRITE set_append RESET reset_append STORED true) | ||
| 17 | + Q_PROPERTY(int nLandmarks READ get_nLandmarks WRITE set_nLandmarks RESET reset_nLandmarks STORED true) | ||
| 18 | + BR_PROPERTY(QList<int>, indices, QList<int>()) | ||
| 19 | + BR_PROPERTY(QString, metaName, "") | ||
| 20 | + BR_PROPERTY(bool, append, false) | ||
| 21 | + BR_PROPERTY(int, nLandmarks, 51) | ||
| 22 | + | ||
| 23 | + void projectMetadata(const File &src, File &dst) const | ||
| 24 | + { | ||
| 25 | + dst = src; | ||
| 26 | + if (src.points().size() != nLandmarks) { | ||
| 27 | + if (Globals->verbose) | ||
| 28 | + qDebug() << "Warning: Face has " << src.points().size() << "points; should be " << nLandmarks; | ||
| 29 | + dst.fte = true; | ||
| 30 | + return; | ||
| 31 | + } | ||
| 32 | + int x1 = 0, | ||
| 33 | + y1 = 0; | ||
| 34 | + | ||
| 35 | + for (int i = 0; i < indices.size(); i++) { | ||
| 36 | + x1 += src.points()[indices[i]].x(); | ||
| 37 | + y1 += src.points()[indices[i]].y(); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + QPointF p(x1 / indices.size(), y1 / indices.size()); | ||
| 41 | + if (!metaName.isEmpty()) | ||
| 42 | + dst.set(metaName, p); | ||
| 43 | + if (append) | ||
| 44 | + dst.appendPoint(p); | ||
| 45 | + } | ||
| 46 | +}; | ||
| 47 | + | ||
| 48 | +BR_REGISTER(Transform, AveragePointsTransform) | ||
| 49 | + | ||
| 50 | +} // namespace br | ||
| 51 | + | ||
| 52 | +#include "metadata/averagepoints.moc" |