From 6ddf62678800a9f749e2ba26a08fe543905076d3 Mon Sep 17 00:00:00 2001 From: KeyurPatel Date: Mon, 30 Jan 2017 23:19:48 +0000 Subject: [PATCH] Introduced a new transform that checks for bad rects. Removed fixrects transform as this transform incorporates fixrects functionality. --- openbr/plugins/metadata/checkrects.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ openbr/plugins/metadata/fixrects.cpp | 66 ------------------------------------------------------------------ 2 files changed, 73 insertions(+), 66 deletions(-) create mode 100644 openbr/plugins/metadata/checkrects.cpp delete mode 100644 openbr/plugins/metadata/fixrects.cpp diff --git a/openbr/plugins/metadata/checkrects.cpp b/openbr/plugins/metadata/checkrects.cpp new file mode 100644 index 0000000..c77a940 --- /dev/null +++ b/openbr/plugins/metadata/checkrects.cpp @@ -0,0 +1,73 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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 Checks the rects in a template for invalid values. The user can specify to fix the rects or remove them. + * \author Keyur Patel \cite kpatel + */ + +class CheckRectsTransform : public UntrainableTransform +{ + Q_OBJECT + Q_PROPERTY(bool fixRects READ get_fixRects WRITE set_fixRects RESET reset_fixRects STORED false) + Q_PROPERTY(bool removeBadRect READ get_removeBadRect WRITE set_removeBadRect RESET reset_removeBadRect STORED false) + BR_PROPERTY(bool, fixRects, false) + BR_PROPERTY(bool, removeBadRect, true) + + void project(const Template &src, Template &dst) const + { + dst = src; + dst.file.clearRects(); + QList rects = src.file.rects(); + + if (fixRects){ + for (int i=0; i src.m().cols-1) r.setRight(src.m().cols-1); + if (r.top() < 0) r.setTop(0); + if (r.bottom() > src.m().rows-1) r.setBottom(src.m().rows-1); + dst.file.appendRect(r); + } + } else { + foreach (QRectF r, rects){ + if ((r.left() < 0) || (r.right() > src.m().cols-1) || (r.top() < 0) || (r.bottom() > src.m().rows-1)){ + if (removeBadRect){ + rects.removeOne(r); + } + else { + dst.file.fte = true; + break; + } + } + } + dst.file.setRects(rects); + } + } +}; + +BR_REGISTER(Transform, CheckRectsTransform) + +} // namespace br + +#include "metadata/checkrects.moc" + diff --git a/openbr/plugins/metadata/fixrects.cpp b/openbr/plugins/metadata/fixrects.cpp deleted file mode 100644 index a33d32e..0000000 --- a/openbr/plugins/metadata/fixrects.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include - -namespace br -{ - -class FixRectsTransform : public UntrainableTransform -{ - Q_OBJECT - - void project(const Template &src, Template &dst) const - { - dst = src; - dst.file.clearRects(); - QList rects = src.file.rects(); - for (int i=0; i src.m().cols-1) r.setRight(src.m().cols-1); - if (r.top() < 0) r.setTop(0); - if (r.bottom() > src.m().rows-1) r.setBottom(src.m().rows-1); - dst.file.appendRect(r); - } - } -}; - -BR_REGISTER(Transform, FixRectsTransform) - - -/*! - * \ingroup transforms - * \brief Checks the rects in a template for invalid values - * \author Keyur Patel \cite kpatel - */ - -class CheckRectsTransform : public UntrainableTransform -{ - Q_OBJECT - Q_PROPERTY(bool removeBadRect READ get_removeBadRect WRITE set_removeBadRect RESET reset_removeBadRect STORED false) - BR_PROPERTY(bool, removeBadRect, true) - - void project(const Template &src, Template &dst) const - { - dst = src; - dst.file.clearRects(); - QList rects = src.file.rects(); - foreach (QRectF r, rects){ - if ((r.left() < 0) || (r.right() > src.m().cols-1) || (r.top() < 0) || (r.bottom() > src.m().rows-1)){ - if (removeBadRect){ - rects.removeOne(r); - } - else { - dst.file.fte = true; - break; - } - } - } - dst.file.setRects(rects); - } -}; - -BR_REGISTER(Transform, CheckRectsTransform) - - -} // namespace br - -#include "metadata/fixrects.moc" -- libgit2 0.21.4