Commit f8dc291bdd0fc79fa46645e28bf0f5cf9a68a555
Merge pull request #399 from biometrics/rectTransforms
Rect transforms
Showing
4 changed files
with
114 additions
and
38 deletions
openbr/plugins/metadata/expandrect.cpp
| ... | ... | @@ -23,6 +23,7 @@ namespace br |
| 23 | 23 | * \ingroup transforms |
| 24 | 24 | * \brief Expand the width and height of a Template's rects by input width and height factors. |
| 25 | 25 | * \author Charles Otto \cite caotto |
| 26 | + * \author Brendan Klare \cite bklare | |
| 26 | 27 | */ |
| 27 | 28 | class ExpandRectTransform : public UntrainableTransform |
| 28 | 29 | { |
| ... | ... | @@ -31,35 +32,23 @@ class ExpandRectTransform : public UntrainableTransform |
| 31 | 32 | Q_PROPERTY(float heightExpand READ get_heightExpand WRITE set_heightExpand RESET reset_heightExpand STORED false) |
| 32 | 33 | BR_PROPERTY(float, widthExpand, .5) |
| 33 | 34 | BR_PROPERTY(float, heightExpand, .5) |
| 35 | + | |
| 34 | 36 | void project(const Template &src, Template &dst) const |
| 35 | 37 | { |
| 36 | 38 | dst = src; |
| 37 | - QList<QRectF> rects = dst.file.rects(); | |
| 39 | + dst.file.clearRects(); | |
| 40 | + QList<QRectF> rects = src.file.rects(); | |
| 38 | 41 | for (int i=0;i < rects.size(); i++) { |
| 39 | - QRectF rect = rects[i]; | |
| 40 | - | |
| 41 | - qreal width = rect.width(); | |
| 42 | - qreal height = rect.height(); | |
| 43 | - float half_w_expansion = widthExpand / 2; | |
| 44 | - float half_h_expansion = heightExpand / 2; | |
| 45 | - | |
| 46 | - qreal half_width = width * widthExpand; | |
| 47 | - qreal quarter_width = width * half_w_expansion; | |
| 48 | - qreal half_height = height * heightExpand; | |
| 49 | - qreal quarter_height = height * half_h_expansion; | |
| 50 | - | |
| 51 | - rect.setX(std::max(qreal(0),(rect.x() - quarter_width))); | |
| 52 | - rect.setY(std::max(qreal(0),(rect.y() - quarter_height))); | |
| 53 | - | |
| 54 | - qreal x2 = std::min(rect.width() + half_width + rect.x(), qreal(src.m().cols) - 1); | |
| 55 | - qreal y2 = std::min(rect.height() + half_height + rect.y(), qreal(src.m().rows) - 1); | |
| 42 | + qreal widthGrowth = rects[i].width() * widthExpand; | |
| 43 | + qreal heightGrowth = rects[i].height() * heightExpand; | |
| 56 | 44 | |
| 57 | - rect.setWidth(x2 - rect.x()); | |
| 58 | - rect.setHeight(y2 - rect.y()); | |
| 45 | + qreal x = std::max(qreal(0), rects[i].x() - widthGrowth / 2.); | |
| 46 | + qreal y = std::max(qreal(0), rects[i].y() - heightGrowth / 2.); | |
| 47 | + dst.file.appendRect(QRectF(x, y, | |
| 48 | + std::min(src.m().cols - x - 1, rects[i].width() + widthGrowth), | |
| 49 | + std::min(src.m().rows - y - 1, rects[i].height() + heightGrowth))); | |
| 59 | 50 | |
| 60 | - rects[i] = rect; | |
| 61 | 51 | } |
| 62 | - dst.file.setRects(rects); | |
| 63 | 52 | } |
| 64 | 53 | }; |
| 65 | 54 | ... | ... |
openbr/plugins/metadata/pointstorects.cpp
0 → 100644
| 1 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
| 2 | + * Copyright 2015 Rank One Computing 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 <openbr/plugins/openbr_internal.h> | |
| 18 | + | |
| 19 | +namespace br | |
| 20 | +{ | |
| 21 | + | |
| 22 | +/*! | |
| 23 | + * \ingroup transforms | |
| 24 | + * \brief For each point, add a rectangle with radius as a half width | |
| 25 | + * \author Brendan Klare \cite bklare | |
| 26 | + */ | |
| 27 | + | |
| 28 | +class PointsToRectsTransform : public UntrainableTransform | |
| 29 | +{ | |
| 30 | + Q_OBJECT | |
| 31 | + Q_PROPERTY(float radius READ get_radius WRITE set_radius RESET reset_radius STORED false) | |
| 32 | + Q_PROPERTY(bool clearRects READ get_clearRects WRITE set_clearRects RESET reset_clearRects STORED false) | |
| 33 | + BR_PROPERTY(float, radius, 4) | |
| 34 | + BR_PROPERTY(bool, clearRects, true) | |
| 35 | + | |
| 36 | + void project(const Template &src, Template &dst) const | |
| 37 | + { | |
| 38 | + dst = src; | |
| 39 | + | |
| 40 | + if (clearRects) | |
| 41 | + dst.file.clearRects(); | |
| 42 | + | |
| 43 | + if (src.file.points().isEmpty()) { | |
| 44 | + if (Globals->verbose) qWarning("No landmarks"); | |
| 45 | + return; | |
| 46 | + } | |
| 47 | + | |
| 48 | + for (int i = 0; i < src.file.points().size(); i++) { | |
| 49 | + dst.file.appendRect(QRectF(src.file.points()[i].x() - radius, src.file.points()[i].y() - radius, radius * 2, radius * 2)); | |
| 50 | + } | |
| 51 | + } | |
| 52 | +}; | |
| 53 | + | |
| 54 | +BR_REGISTER(Transform, PointsToRectsTransform) | |
| 55 | + | |
| 56 | +} // namespace br | |
| 57 | + | |
| 58 | +#include "metadata/pointstorects.moc" | ... | ... |
openbr/plugins/metadata/rectstomats.cpp
0 → 100644
| 1 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
| 2 | + * Copyright 2015 Rank One Computing 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 <openbr/plugins/openbr_internal.h> | |
| 18 | +#include <openbr/core/opencvutils.h> | |
| 19 | + | |
| 20 | +namespace br | |
| 21 | +{ | |
| 22 | + | |
| 23 | +/*! | |
| 24 | + * \ingroup transforms | |
| 25 | + * \brief For each rectangle bounding box in src, the mat is cropped and appended | |
| 26 | + * the the template's list of mats. | |
| 27 | + * \author Brendan Klare \cite bklare | |
| 28 | + */ | |
| 29 | +class RectsToMatsTransform : public UntrainableTransform | |
| 30 | +{ | |
| 31 | + Q_OBJECT | |
| 32 | + | |
| 33 | +private: | |
| 34 | + void project(const Template &src, Template &dst) const | |
| 35 | + { | |
| 36 | + for (int i = 0; i < src.file.rects().size(); i++) | |
| 37 | + dst += cv::Mat(src, OpenCVUtils::toRect(src.file.rects()[i])); | |
| 38 | + } | |
| 39 | +}; | |
| 40 | + | |
| 41 | +BR_REGISTER(Transform, RectsToMatsTransform) | |
| 42 | + | |
| 43 | +} // namespace br | |
| 44 | + | |
| 45 | +#include "metadata/rectstomats.moc" | ... | ... |
openbr/plugins/metadata/rectstotemplates.cpp
| 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 | 1 | #include <openbr/plugins/openbr_internal.h> |
| 18 | 2 | #include <openbr/core/opencvutils.h> |
| 19 | 3 | ... | ... |