Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Average points #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions openbr/plugins/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ class DrawTransform : public UntrainableTransform
Q_PROPERTY(int lineThickness READ get_lineThickness WRITE set_lineThickness RESET reset_lineThickness STORED false)
Q_PROPERTY(bool named READ get_named WRITE set_named RESET reset_named STORED false)
Q_PROPERTY(bool location READ get_location WRITE set_location RESET reset_location STORED false)
Q_PROPERTY(bool eyes READ get_eyes WRITE set_eyes RESET reset_eyes STORED false)
BR_PROPERTY(bool, verbose, false)
BR_PROPERTY(bool, points, true)
BR_PROPERTY(bool, rects, true)
BR_PROPERTY(bool, inPlace, false)
BR_PROPERTY(int, lineThickness, 1)
BR_PROPERTY(bool, named, true)
BR_PROPERTY(bool, location, true)
BR_PROPERTY(bool, eyes, true)

void project(const Template &src, Template &dst) const
{
Expand All @@ -71,6 +73,13 @@ class DrawTransform : public UntrainableTransform
foreach (const Rect &rect, OpenCVUtils::toRects(src.file.namedRects() + src.file.rects()))
rectangle(dst, rect, color, lineThickness);
}
if (eyes && src.file.contains("First_Eye") && src.file.contains("Second_Eye")) {
const Point2f &point1 = OpenCVUtils::toPoint(src.file.get<QPointF>("First_Eye"));
const Point2f &point2 = OpenCVUtils::toPoint(src.file.get<QPointF>("Second_Eye"));
const Scalar eyeColor(255, 0, 0);
circle(dst, point1, 3, eyeColor, -1);
circle(dst, point2, 3, eyeColor, -1);
}
}
};

Expand Down
44 changes: 44 additions & 0 deletions openbr/plugins/template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,50 @@ class SelectPointsTransform : public UntrainableMetadataTransform

BR_REGISTER(Transform, SelectPointsTransform)

/*!
* \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<int> 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)
Q_PROPERTY(int nLandmarks READ get_nLandmarks WRITE set_nLandmarks RESET reset_nLandmarks STORED true)
BR_PROPERTY(QList<int>, indices, QList<int>())
BR_PROPERTY(QString, metaName, "")
BR_PROPERTY(bool, append, false)
BR_PROPERTY(int, nLandmarks, 51)

void projectMetadata(const File &src, File &dst) const
{
dst = src;
if (src.points().size() != nLandmarks) {
if (Globals->verbose)
qDebug() << "Warning: Face has " << src.points().size() << "points; should be " << nLandmarks;
dst.fte = true;
return;
}
int 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.points().append(p);
}
};

BR_REGISTER(Transform, AveragePointsTransform)

/*!
* \ingroup transforms
* \brief Removes duplicate templates based on a unique metadata key
Expand Down