Commit 6ddf62678800a9f749e2ba26a08fe543905076d3

Authored by KeyurPatel
1 parent 4255592f

Introduced a new transform that checks for bad rects. Removed fixrects transform…

… as this transform incorporates fixrects functionality.
openbr/plugins/metadata/fixrects.cpp renamed to openbr/plugins/metadata/checkrects.cpp
  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 +
1 17 #include <openbr/plugins/openbr_internal.h>
2 18  
3 19 namespace br
4 20 {
5 21  
6   -class FixRectsTransform : public UntrainableTransform
7   -{
8   - Q_OBJECT
9   -
10   - void project(const Template &src, Template &dst) const
11   - {
12   - dst = src;
13   - dst.file.clearRects();
14   - QList<QRectF> rects = src.file.rects();
15   - for (int i=0; i<rects.size(); i++) {
16   - QRectF r = rects[i];
17   - if (r.left() < 0) r.setLeft(0);
18   - if (r.right() > src.m().cols-1) r.setRight(src.m().cols-1);
19   - if (r.top() < 0) r.setTop(0);
20   - if (r.bottom() > src.m().rows-1) r.setBottom(src.m().rows-1);
21   - dst.file.appendRect(r);
22   - }
23   - }
24   -};
25   -
26   -BR_REGISTER(Transform, FixRectsTransform)
27   -
28   -
29 22 /*!
30 23 * \ingroup transforms
31   - * \brief Checks the rects in a template for invalid values
  24 + * \brief Checks the rects in a template for invalid values. The user can specify to fix the rects or remove them.
32 25 * \author Keyur Patel \cite kpatel
33 26 */
34 27  
35 28 class CheckRectsTransform : public UntrainableTransform
36 29 {
37 30 Q_OBJECT
  31 + Q_PROPERTY(bool fixRects READ get_fixRects WRITE set_fixRects RESET reset_fixRects STORED false)
38 32 Q_PROPERTY(bool removeBadRect READ get_removeBadRect WRITE set_removeBadRect RESET reset_removeBadRect STORED false)
  33 + BR_PROPERTY(bool, fixRects, false)
39 34 BR_PROPERTY(bool, removeBadRect, true)
40 35  
41 36 void project(const Template &src, Template &dst) const
... ... @@ -43,24 +38,36 @@ class CheckRectsTransform : public UntrainableTransform
43 38 dst = src;
44 39 dst.file.clearRects();
45 40 QList<QRectF> rects = src.file.rects();
46   - foreach (QRectF r, rects){
47   - if ((r.left() < 0) || (r.right() > src.m().cols-1) || (r.top() < 0) || (r.bottom() > src.m().rows-1)){
48   - if (removeBadRect){
49   - rects.removeOne(r);
50   - }
51   - else {
52   - dst.file.fte = true;
53   - break;
  41 +
  42 + if (fixRects){
  43 + for (int i=0; i<rects.size(); i++) {
  44 + QRectF r = rects[i];
  45 + if (r.left() < 0) r.setLeft(0);
  46 + if (r.right() > src.m().cols-1) r.setRight(src.m().cols-1);
  47 + if (r.top() < 0) r.setTop(0);
  48 + if (r.bottom() > src.m().rows-1) r.setBottom(src.m().rows-1);
  49 + dst.file.appendRect(r);
  50 + }
  51 + } else {
  52 + foreach (QRectF r, rects){
  53 + if ((r.left() < 0) || (r.right() > src.m().cols-1) || (r.top() < 0) || (r.bottom() > src.m().rows-1)){
  54 + if (removeBadRect){
  55 + rects.removeOne(r);
  56 + }
  57 + else {
  58 + dst.file.fte = true;
  59 + break;
  60 + }
54 61 }
55 62 }
  63 + dst.file.setRects(rects);
56 64 }
57   - dst.file.setRects(rects);
58 65 }
59 66 };
60 67  
61 68 BR_REGISTER(Transform, CheckRectsTransform)
62 69  
63   -
64 70 } // namespace br
65 71  
66   -#include "metadata/fixrects.moc"
  72 +#include "metadata/checkrects.moc"
  73 +
... ...