Commit f5a73fe4628c9de09d27d8d9b4498b5bac22c9ae

Authored by Brendan Klare
1 parent 4904f6e0

Moved to new file

openbr/plugins/imgproc/cropfrommask.cpp 0 → 100644
  1 +#include <openbr/plugins/openbr_internal.h>
  2 +
  3 +using namespace cv;
  4 +
  5 +namespace br
  6 +{
  7 +
  8 +/*!
  9 + * \ingroup transforms
  10 + * \brief Crops image based on mask metadata
  11 + * \author Brendan Klare \cite bklare
  12 + */
  13 +class CropFromMaskTransform : public UntrainableTransform
  14 +{
  15 + Q_OBJECT
  16 + Q_PROPERTY(bool fixedAspectRatio READ get_fixedAspectRatio WRITE set_fixedAspectRatio RESET reset_fixedAspectRatio STORED false)
  17 + BR_PROPERTY(bool, fixedAspectRatio, true)
  18 +
  19 +private:
  20 +
  21 + void project(const Template &src, Template &dst) const
  22 + {
  23 + dst = src;
  24 +
  25 + Mat mask = dst.file.get<Mat>("Mask");
  26 +
  27 + int w = mask.rows;
  28 + int h = mask.cols;
  29 + int left = w;
  30 + int right = 0;
  31 + int top = h;
  32 + int bottom = 0;
  33 + for (int i = 0 ; i < w; i++) {
  34 + for (int j = 0 ; j < h; j++) {
  35 + if (mask.at<unsigned char>(i,j)) {
  36 + if (i < left)
  37 + left = i;
  38 + if (i > right)
  39 + right = i;
  40 + if (j < top)
  41 + top = j;
  42 + if (j > bottom)
  43 + bottom = j;
  44 + }
  45 + }
  46 + }
  47 +
  48 + if (fixedAspectRatio) {
  49 + h = bottom - top + 1;
  50 + w = right - left + 1;
  51 + if (h > w) {
  52 + int h2 = (h - w) / 2;
  53 + right += h2;
  54 + left -= h2;
  55 + } else {
  56 + int w2 = (w - h) / 2;
  57 + bottom += w2;
  58 + top -= w2;
  59 + }
  60 + }
  61 +
  62 + dst.m() = Mat(src.m(), Rect(top, left, bottom - top + 1, right - left + 1));
  63 +
  64 + }
  65 +};
  66 +
  67 +BR_REGISTER(Transform, CropFromMaskTransform)
  68 +
  69 +} // namespace br
  70 +
  71 +#include "imgproc/threshold.moc"
... ...
openbr/plugins/imgproc/threshold.cpp
... ... @@ -48,62 +48,6 @@ private:
48 48  
49 49 BR_REGISTER(Transform, ThresholdTransform)
50 50  
51   -class CropFromMaskTransform : public UntrainableTransform
52   -{
53   - Q_OBJECT
54   - Q_PROPERTY(bool fixedAspectRatio READ get_fixedAspectRatio WRITE set_fixedAspectRatio RESET reset_fixedAspectRatio STORED false)
55   - BR_PROPERTY(bool, fixedAspectRatio, true)
56   -
57   -private:
58   -
59   - void project(const Template &src, Template &dst) const
60   - {
61   - dst = src;
62   -
63   - Mat mask = dst.file.get<Mat>("Mask");
64   -
65   - int w = mask.rows;
66   - int h = mask.cols;
67   - int left = w;
68   - int right = 0;
69   - int top = h;
70   - int bottom = 0;
71   - for (int i = 0 ; i < w; i++) {
72   - for (int j = 0 ; j < h; j++) {
73   - if (mask.at<unsigned char>(i,j)) {
74   - if (i < left)
75   - left = i;
76   - if (i > right)
77   - right = i;
78   - if (j < top)
79   - top = j;
80   - if (j > bottom)
81   - bottom = j;
82   - }
83   - }
84   - }
85   -
86   - if (fixedAspectRatio) {
87   - h = bottom - top + 1;
88   - w = right - left + 1;
89   - if (h > w) {
90   - int h2 = (h - w) / 2;
91   - right += h2;
92   - left -= h2;
93   - } else {
94   - int w2 = (w - h) / 2;
95   - bottom += w2;
96   - top -= w2;
97   - }
98   - }
99   -
100   - dst.m() = Mat(src.m(), Rect(top, left, bottom - top + 1, right - left + 1));
101   -
102   - }
103   -};
104   -
105   -BR_REGISTER(Transform, CropFromMaskTransform)
106   -
107 51 } // namespace br
108 52  
109 53 #include "imgproc/threshold.moc"
... ...