From ffcbc59fe5680bb9a3d65fdeb1d5d66183fc2f3f Mon Sep 17 00:00:00 2001 From: Brendan Klare Date: Wed, 20 Nov 2013 23:10:29 -0500 Subject: [PATCH] Transform added to convert eye locations to face bounding box --- openbr/plugins/regions.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+), 0 deletions(-) diff --git a/openbr/plugins/regions.cpp b/openbr/plugins/regions.cpp index aeb3b52..b634ed3 100644 --- a/openbr/plugins/regions.cpp +++ b/openbr/plugins/regions.cpp @@ -353,6 +353,49 @@ class RectFromPointsTransform : public UntrainableTransform BR_REGISTER(Transform, RectFromPointsTransform) +/*! + * \ingroup transforms + * \brief Create face bounding box from two eye locations. `widthPadding` specifies + * what percentage of the interpupliary distance (ipd) will be padded in both + * horizontal directions. The `verticalLocation` specifies where vertically the + * eyes are within the bounding box (0.5 would be the center). + * \author Brendan Klare \cite bklare + */ + +class FaceFromEyesTransform : public UntrainableTransform +{ + Q_OBJECT + Q_PROPERTY(double widthPadding READ get_widthPadding WRITE set_widthPadding RESET reset_widthPadding STORED false) + Q_PROPERTY(double verticalLocation READ get_verticalLocation WRITE set_verticalLocation RESET reset_verticalLocation STORED false) + Q_PROPERTY(int leftEyeIdx READ get_leftEyeIdx WRITE set_leftEyeIdx RESET reset_leftEyeIdx STORED false) + Q_PROPERTY(int rightEyeIdx READ get_rightEyeIdx WRITE set_rightEyeIdx RESET reset_rightEyeIdx STORED false) + BR_PROPERTY(double, widthPadding, 0.7) + BR_PROPERTY(double, verticalLocation, 0.25) + BR_PROPERTY(int, leftEyeIdx, 0) + BR_PROPERTY(int, rightEyeIdx, 0) + + void project(const Template &src, Template &dst) const + { + dst = src; + + if (src.file.points().isEmpty()) { + qWarning("No landmarks"); + dst = src; + return; + } + + QPointF eyeL = src.file.points()[0]; + QPointF eyeR = src.file.points()[1]; + QPointF eyeCenter((eyeL.x() + eyeR.x()) / 2, (eyeL.y() + eyeR.y()) / 2); + float ipd = sqrt(pow(eyeL.x() - eyeR.x(), 2) + pow(eyeL.y() - eyeR.y(), 2)); + float width = ipd + 2 * widthPadding * ipd; + + dst.file.appendRect(QRectF(eyeCenter.x() - width / 2, eyeCenter.y() - width * verticalLocation, width, width)); + } +}; + +BR_REGISTER(Transform, FaceFromEyesTransform) + } // namespace br #include "regions.moc" -- libgit2 0.21.4