diff --git a/openbr/plugins/imgproc/cropfromlandmarks.cpp b/openbr/plugins/imgproc/cropfromlandmarks.cpp new file mode 100644 index 0000000..c23e2aa --- /dev/null +++ b/openbr/plugins/imgproc/cropfromlandmarks.cpp @@ -0,0 +1,54 @@ +#include + +using namespace cv; + +namespace br +{ + +/*! + * \ingroup transforms + * \brief Crops around the landmarks numbers provided. + * \author Brendan Klare \cite bklare + * \param padding Percentage of height and width to pad the image. + */ +class CropFromLandmarksTransform : public UntrainableTransform +{ + Q_OBJECT + + Q_PROPERTY(QList indices READ get_indices WRITE set_indices RESET reset_indices STORED false) + Q_PROPERTY(float paddingHorizontal READ get_paddingHorizontal WRITE set_paddingHorizontal RESET reset_paddingHorizontal STORED false) + Q_PROPERTY(float paddingVertical READ get_paddingVertical WRITE set_paddingVertical RESET reset_paddingVertical STORED false) + BR_PROPERTY(QList, indices, QList()) + BR_PROPERTY(float, paddingHorizontal, .1) + BR_PROPERTY(float, paddingVertical, .1) + + void project(const Template &src, Template &dst) const + { + int minX = src.m().cols - 1, + maxX = 1, + minY = src.m().rows - 1, + maxY = 1; + + for (int i = 0; i src.file.points()[indices[i]].x()) + minX = src.file.points()[indices[i]].x(); + if (minY > src.file.points()[indices[i]].y()) + minY = src.file.points()[indices[i]].y(); + if (maxX < src.file.points()[indices[i]].x()) + maxX = src.file.points()[indices[i]].x(); + if (maxY < src.file.points()[indices[i]].y()) + maxY = src.file.points()[indices[i]].y(); + } + + int padW = qRound((maxX - minX) * (paddingHorizontal / 2)); + int padH = qRound((maxY - minY) * (paddingVertical / 2)); + + dst = Mat(src, Rect(minX - padW, minY - padH, (maxX - minX + 1) + padW * 2, (maxY - minY + 1) + padH * 2)); + } +}; + +BR_REGISTER(Transform, CropFromLandmarksTransform) + +} // namespace br + +#include "imgproc/cropfromlandmarks.moc"