Commit 04767c735cfe8d433f9fe81da4e97bf90d22687e

Authored by Scott Klum
1 parent 6685e4b1

Added squarefrompoints

openbr/plugins/metadata/squarefrompoints.cpp 0 → 100644
  1 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2 + * Copyright 2012 The MITRE Corporation *
  3 + * *
  4 + * Licensed under the Apache License, Version 2.0 (the "License"); *
  5 + * you may not use this file except in compliance with the License. *
  6 + * You may obtain a copy of the License at *
  7 + * *
  8 + * http://www.apache.org/licenses/LICENSE-2.0 *
  9 + * *
  10 + * Unless required by applicable law or agreed to in writing, software *
  11 + * distributed under the License is distributed on an "AS IS" BASIS, *
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
  13 + * See the License for the specific language governing permissions and *
  14 + * limitations under the License. *
  15 + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  16 +
  17 +#include <opencv2/imgproc/imgproc.hpp>
  18 +
  19 +#include <openbr/plugins/openbr_internal.h>
  20 +#include <openbr/core/opencvutils.h>
  21 +
  22 +using namespace cv;
  23 +
  24 +namespace br
  25 +{
  26 +
  27 +/*!
  28 + * \ingroup transforms
  29 + * \brief Creates a bounding square around three points (typically the two eyes and the chin).
  30 + * \author Scott Klum \cite sklum
  31 + * \br_property int eyeL index of left eye point.
  32 + * \br_property int eyeR Index of right eye point.
  33 + * \br_property int chin Index of chin point.
  34 + */
  35 +class SquareFromPointsTransform : public UntrainableMetadataTransform
  36 +{
  37 + Q_OBJECT
  38 +
  39 + Q_PROPERTY(int eyeR READ get_eyeR WRITE set_eyeR RESET reset_eyeR STORED false)
  40 + Q_PROPERTY(int eyeL READ get_eyeL WRITE set_eyeL RESET reset_eyeL STORED false)
  41 + Q_PROPERTY(int chin READ get_chin WRITE set_chin RESET reset_chin STORED false)
  42 + BR_PROPERTY(int, eyeL, 7)
  43 + BR_PROPERTY(int, eyeR, 10)
  44 + BR_PROPERTY(int, chin, 20)
  45 +
  46 + void projectMetadata(const File &src, File &dst) const
  47 + {
  48 + dst = src;
  49 + QList<QPointF> points = src.points();
  50 +
  51 + float side = points[chin].y() - points[eyeL].y();
  52 + float left = points[eyeL].x()+(points[eyeR].x() - points[eyeL].x())/2.-side/2.;
  53 + QRectF rect(left,points[eyeL].y(),side,side);
  54 +
  55 + dst.setRects(OpenCVUtils::toRects(QList<QRectF>() << rect));
  56 + }
  57 +};
  58 +
  59 +BR_REGISTER(Transform, SquareFromPointsTransform)
  60 +
  61 +} // namespace br
  62 +
  63 +#include "metadata/squarefrompoints.moc"