diff --git a/openbr/plugins/metadata/expandrect.cpp b/openbr/plugins/metadata/expandrect.cpp index 0fc8727..54ac0f1 100644 --- a/openbr/plugins/metadata/expandrect.cpp +++ b/openbr/plugins/metadata/expandrect.cpp @@ -23,6 +23,7 @@ namespace br * \ingroup transforms * \brief Expand the width and height of a Template's rects by input width and height factors. * \author Charles Otto \cite caotto + * \author Brendan Klare \cite bklare */ class ExpandRectTransform : public UntrainableTransform { @@ -31,35 +32,23 @@ class ExpandRectTransform : public UntrainableTransform 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(); + dst.file.clearRects(); + QList rects = src.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); + qreal widthGrowth = rects[i].width() * widthExpand; + qreal heightGrowth = rects[i].height() * heightExpand; - rect.setWidth(x2 - rect.x()); - rect.setHeight(y2 - rect.y()); + qreal x = std::max(qreal(0), rects[i].x() - widthGrowth / 2.); + qreal y = std::max(qreal(0), rects[i].y() - heightGrowth / 2.); + dst.file.appendRect(QRectF(x, y, + std::min(src.m().cols - x - 1, rects[i].width() + widthGrowth), + std::min(src.m().rows - y - 1, rects[i].height() + heightGrowth))); - rects[i] = rect; } - dst.file.setRects(rects); } }; diff --git a/openbr/plugins/metadata/pointstorects.cpp b/openbr/plugins/metadata/pointstorects.cpp new file mode 100644 index 0000000..8e3fb67 --- /dev/null +++ b/openbr/plugins/metadata/pointstorects.cpp @@ -0,0 +1,58 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright 2015 Rank One Computing Corporation * + * * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * + * See the License for the specific language governing permissions and * + * limitations under the License. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include + +namespace br +{ + +/*! + * \ingroup transforms + * \brief For each point, add a rectangle with radius as a half width + * \author Brendan Klare \cite bklare + */ + +class PointsToRectsTransform : public UntrainableTransform +{ + Q_OBJECT + Q_PROPERTY(float radius READ get_radius WRITE set_radius RESET reset_radius STORED false) + Q_PROPERTY(bool clearRects READ get_clearRects WRITE set_clearRects RESET reset_clearRects STORED false) + BR_PROPERTY(float, radius, 4) + BR_PROPERTY(bool, clearRects, true) + + void project(const Template &src, Template &dst) const + { + dst = src; + + if (clearRects) + dst.file.clearRects(); + + if (src.file.points().isEmpty()) { + if (Globals->verbose) qWarning("No landmarks"); + return; + } + + for (int i = 0; i < src.file.points().size(); i++) { + dst.file.appendRect(QRectF(src.file.points()[i].x() - radius, src.file.points()[i].y() - radius, radius * 2, radius * 2)); + } + } +}; + +BR_REGISTER(Transform, PointsToRectsTransform) + +} // namespace br + +#include "metadata/pointstorects.moc" diff --git a/openbr/plugins/metadata/rectstomats.cpp b/openbr/plugins/metadata/rectstomats.cpp new file mode 100644 index 0000000..42c55da --- /dev/null +++ b/openbr/plugins/metadata/rectstomats.cpp @@ -0,0 +1,45 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright 2015 Rank One Computing Corporation * + * * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * + * See the License for the specific language governing permissions and * + * limitations under the License. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include +#include + +namespace br +{ + +/*! + * \ingroup transforms + * \brief For each rectangle bounding box in src, the mat is cropped and appended + * the the template's list of mats. + * \author Brendan Klare \cite bklare + */ +class RectsToMatsTransform : public UntrainableTransform +{ + Q_OBJECT + +private: + void project(const Template &src, Template &dst) const + { + for (int i = 0; i < src.file.rects().size(); i++) + dst += cv::Mat(src, OpenCVUtils::toRect(src.file.rects()[i])); + } +}; + +BR_REGISTER(Transform, RectsToMatsTransform) + +} // namespace br + +#include "metadata/rectstomats.moc" diff --git a/openbr/plugins/metadata/rectstotemplates.cpp b/openbr/plugins/metadata/rectstotemplates.cpp index bcfde35..bfe8e77 100644 --- a/openbr/plugins/metadata/rectstotemplates.cpp +++ b/openbr/plugins/metadata/rectstotemplates.cpp @@ -1,19 +1,3 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright 2012 The MITRE Corporation * - * * - * Licensed under the Apache License, Version 2.0 (the "License"); * - * you may not use this file except in compliance with the License. * - * You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software * - * distributed under the License is distributed on an "AS IS" BASIS, * - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * - * See the License for the specific language governing permissions and * - * limitations under the License. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - #include #include