diff --git a/openbr/plugins/draw.cpp b/openbr/plugins/draw.cpp index 01d816a..304431f 100644 --- a/openbr/plugins/draw.cpp +++ b/openbr/plugins/draw.cpp @@ -213,6 +213,41 @@ class DrawGridTransform : public UntrainableTransform BR_REGISTER(Transform, DrawGridTransform) +/*! + * \ingroup transforms + * \brief Computes the mean of a set of templates. + * \note Suitable for visualization only as it sets every projected template to the mean template. + * \author Scott Klum \cite sklum + */ +class MeanTransform : public Transform +{ + Q_OBJECT + + Mat mean; + + void train(const TemplateList &data) + { + mean = Mat::zeros(data[0].m().rows,data[0].m().cols,CV_32F); + + for (int i = 0; i < data.size(); i++) { + Mat converted; + data[i].m().convertTo(converted, CV_32F); + mean += converted; + } + + mean /= data.size(); + } + + void project(const Template &src, Template &dst) const + { + dst = src; + dst.m() = mean; + } + +}; + +BR_REGISTER(Transform, MeanTransform) + // TODO: re-implement EditTransform using Qt #if 0 /*! diff --git a/openbr/plugins/gui.cpp b/openbr/plugins/gui.cpp index ac26d00..46e40f6 100644 --- a/openbr/plugins/gui.cpp +++ b/openbr/plugins/gui.cpp @@ -67,6 +67,10 @@ public: { wait.wakeAll(); } + else if (event->type() == QEvent::MouseButtonPress) + { + qDebug() << "hey there"; + } return QObject::eventFilter(obj, event); } diff --git a/openbr/plugins/landmarks.cpp b/openbr/plugins/landmarks.cpp index b9fed85..4f25593 100644 --- a/openbr/plugins/landmarks.cpp +++ b/openbr/plugins/landmarks.cpp @@ -149,13 +149,9 @@ class DelaunayTransform : public UntrainableTransform Q_OBJECT Q_PROPERTY(float scaleFactor READ get_scaleFactor WRITE set_scaleFactor RESET reset_scaleFactor STORED false) - Q_PROPERTY(QString widthCrop READ get_widthCrop WRITE set_widthCrop RESET reset_widthCrop STORED false) - Q_PROPERTY(QString heightCrop READ get_heightCrop WRITE set_heightCrop RESET reset_heightCrop STORED false) Q_PROPERTY(bool warp READ get_warp WRITE set_warp RESET reset_warp STORED false) Q_PROPERTY(bool draw READ get_draw WRITE set_draw RESET reset_draw STORED false) BR_PROPERTY(float, scaleFactor, 1) - BR_PROPERTY(QString, widthCrop, QString()) - BR_PROPERTY(QString, heightCrop, QString()) BR_PROPERTY(bool, warp, true) BR_PROPERTY(bool, draw, false) @@ -289,13 +285,7 @@ class DelaunayTransform : public UntrainableTransform } Rect boundingBox = boundingRect(mappedPoints.toVector().toStdVector()); - - boundingBox.x += boundingBox.width * QtUtils::toPoint(widthCrop).x(); - boundingBox.y += boundingBox.height * QtUtils::toPoint(heightCrop).x(); - boundingBox.width *= 1-QtUtils::toPoint(widthCrop).y(); - boundingBox.height *= 1-QtUtils::toPoint(heightCrop).y(); - - dst.m() = Mat(dst.m(), boundingBox); + dst.file.appendRect(OpenCVUtils::fromRect(boundingBox)); } } @@ -303,41 +293,6 @@ class DelaunayTransform : public UntrainableTransform BR_REGISTER(Transform, DelaunayTransform) -/*! - * \ingroup transforms - * \brief Computes the mean of a set of templates. - * \note Suitable for visualization only as it sets every projected template to the mean template. - * \author Scott Klum \cite sklum - */ -class MeanTransform : public Transform -{ - Q_OBJECT - - Mat mean; - - void train(const TemplateList &data) - { - mean = Mat::zeros(data[0].m().rows,data[0].m().cols,CV_32F); - - for (int i = 0; i < data.size(); i++) { - Mat converted; - data[i].m().convertTo(converted, CV_32F); - mean += converted; - } - - mean /= data.size(); - } - - void project(const Template &src, Template &dst) const - { - dst = src; - dst.m() = mean; - } - -}; - -BR_REGISTER(Transform, MeanTransform) - } // namespace br #include "landmarks.moc" diff --git a/openbr/plugins/misc.cpp b/openbr/plugins/misc.cpp index f0b1fbb..567fa0d 100644 --- a/openbr/plugins/misc.cpp +++ b/openbr/plugins/misc.cpp @@ -516,52 +516,6 @@ class RestoreMatTransform : public UntrainableMetaTransform }; BR_REGISTER(Transform, RestoreMatTransform) -/*! - * \ingroup transforms - * \brief Expand the width and height of a template's rects by input width and height factors. - * \author Charles Otto \cite caotto - */ -class ExpandRectTransform : public UntrainableTransform -{ - Q_OBJECT - Q_PROPERTY(float widthExpand READ get_widthExpand WRITE set_widthExpand RESET reset_widthExpand STORED false) - Q_PROPERTY(float heightExpand READ get_heightExpand WRITE set_heightExpand RESET reset_heightExpand STORED false) - BR_PROPERTY(float, widthExpand, .5) - BR_PROPERTY(float, heightExpand, .5) - void project(const Template &src, Template &dst) const - { - dst = src; - QList rects = dst.file.rects(); - for (int i=0;i < rects.size(); i++) { - QRectF rect = rects[i]; - - qreal width = rect.width(); - qreal height = rect.height(); - float half_w_expansion = widthExpand / 2; - float half_h_expansion = heightExpand / 2; - - qreal half_width = width * widthExpand; - qreal quarter_width = width * half_w_expansion; - qreal half_height = height * heightExpand; - qreal quarter_height = height * half_h_expansion; - - rect.setX(std::max(qreal(0),(rect.x() - quarter_width))); - rect.setY(std::max(qreal(0),(rect.y() - quarter_height))); - - qreal x2 = std::min(rect.width() + half_width + rect.x(), qreal(src.m().cols) - 1); - qreal y2 = std::min(rect.height() + half_height + rect.y(), qreal(src.m().rows) - 1); - - rect.setWidth(x2 - rect.x()); - rect.setHeight(y2 - rect.y()); - - rects[i] = rect; - } - dst.file.setRects(rects); - } -}; - -BR_REGISTER(Transform, ExpandRectTransform) - class EventTransform : public UntrainableMetaTransform { diff --git a/openbr/plugins/regions.cpp b/openbr/plugins/regions.cpp index 020f3e1..0a20202 100644 --- a/openbr/plugins/regions.cpp +++ b/openbr/plugins/regions.cpp @@ -191,6 +191,87 @@ BR_REGISTER(Transform, DupTransform) /*! * \ingroup transforms + * \brief Expand the width and height of a template's rects by input width and height factors. + * \author Charles Otto \cite caotto + */ +class ExpandRectTransform : public UntrainableTransform +{ + Q_OBJECT + Q_PROPERTY(float widthExpand READ get_widthExpand WRITE set_widthExpand RESET reset_widthExpand STORED false) + Q_PROPERTY(float heightExpand READ get_heightExpand WRITE set_heightExpand RESET reset_heightExpand STORED false) + BR_PROPERTY(float, widthExpand, .5) + BR_PROPERTY(float, heightExpand, .5) + void project(const Template &src, Template &dst) const + { + dst = src; + QList rects = dst.file.rects(); + for (int i=0;i < rects.size(); i++) { + QRectF rect = rects[i]; + + qreal width = rect.width(); + qreal height = rect.height(); + float half_w_expansion = widthExpand / 2; + float half_h_expansion = heightExpand / 2; + + qreal half_width = width * widthExpand; + qreal quarter_width = width * half_w_expansion; + qreal half_height = height * heightExpand; + qreal quarter_height = height * half_h_expansion; + + rect.setX(std::max(qreal(0),(rect.x() - quarter_width))); + rect.setY(std::max(qreal(0),(rect.y() - quarter_height))); + + qreal x2 = std::min(rect.width() + half_width + rect.x(), qreal(src.m().cols) - 1); + qreal y2 = std::min(rect.height() + half_height + rect.y(), qreal(src.m().rows) - 1); + + rect.setWidth(x2 - rect.x()); + rect.setHeight(y2 - rect.y()); + + rects[i] = rect; + } + dst.file.setRects(rects); + } +}; + +BR_REGISTER(Transform, ExpandRectTransform) + +/*! + * \ingroup transforms + * \brief Crops the width and height of a template's rects by input width and height factors. + * \author Scott Klum \cite sklum + */ +class CropRectTransform : public UntrainableTransform +{ + Q_OBJECT + + Q_PROPERTY(QString widthCrop READ get_widthCrop WRITE set_widthCrop RESET reset_widthCrop STORED false) + Q_PROPERTY(QString heightCrop READ get_heightCrop WRITE set_heightCrop RESET reset_heightCrop STORED false) + BR_PROPERTY(QString, widthCrop, QString()) + BR_PROPERTY(QString, heightCrop, QString()) + + void project(const Template &src, Template &dst) const + { + dst = src; + QList rects = dst.file.rects(); + for (int i=0;i < rects.size(); i++) { + QRectF rect = rects[i]; + + // Do a bit of error checking + rect.x += rect.width * QtUtils::toPoint(widthCrop).x(); + rect.y += rect.height * QtUtils::toPoint(heightCrop).x(); + rect.width *= 1-QtUtils::toPoint(widthCrop).y(); + rect.height *= 1-QtUtils::toPoint(heightCrop).y(); + + dst.m() = Mat(dst.m(), rect); + } + dst.file.setRects(rects); + } +}; + +BR_REGISTER(Transform, CropRectTransform) + +/*! + * \ingroup transforms * \brief Create matrix from landmarks. * \author Scott Klum \cite sklum * \todo Padding should be a percent of total image size