From f5a73fe4628c9de09d27d8d9b4498b5bac22c9ae Mon Sep 17 00:00:00 2001 From: Brendan Klare Date: Mon, 2 Mar 2015 22:02:33 -0500 Subject: [PATCH] Moved to new file --- openbr/plugins/imgproc/cropfrommask.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ openbr/plugins/imgproc/threshold.cpp | 56 -------------------------------------------------------- 2 files changed, 71 insertions(+), 56 deletions(-) create mode 100644 openbr/plugins/imgproc/cropfrommask.cpp diff --git a/openbr/plugins/imgproc/cropfrommask.cpp b/openbr/plugins/imgproc/cropfrommask.cpp new file mode 100644 index 0000000..3898172 --- /dev/null +++ b/openbr/plugins/imgproc/cropfrommask.cpp @@ -0,0 +1,71 @@ +#include + +using namespace cv; + +namespace br +{ + +/*! + * \ingroup transforms + * \brief Crops image based on mask metadata + * \author Brendan Klare \cite bklare + */ +class CropFromMaskTransform : public UntrainableTransform +{ + Q_OBJECT + Q_PROPERTY(bool fixedAspectRatio READ get_fixedAspectRatio WRITE set_fixedAspectRatio RESET reset_fixedAspectRatio STORED false) + BR_PROPERTY(bool, fixedAspectRatio, true) + +private: + + void project(const Template &src, Template &dst) const + { + dst = src; + + Mat mask = dst.file.get("Mask"); + + int w = mask.rows; + int h = mask.cols; + int left = w; + int right = 0; + int top = h; + int bottom = 0; + for (int i = 0 ; i < w; i++) { + for (int j = 0 ; j < h; j++) { + if (mask.at(i,j)) { + if (i < left) + left = i; + if (i > right) + right = i; + if (j < top) + top = j; + if (j > bottom) + bottom = j; + } + } + } + + if (fixedAspectRatio) { + h = bottom - top + 1; + w = right - left + 1; + if (h > w) { + int h2 = (h - w) / 2; + right += h2; + left -= h2; + } else { + int w2 = (w - h) / 2; + bottom += w2; + top -= w2; + } + } + + dst.m() = Mat(src.m(), Rect(top, left, bottom - top + 1, right - left + 1)); + + } +}; + +BR_REGISTER(Transform, CropFromMaskTransform) + +} // namespace br + +#include "imgproc/threshold.moc" diff --git a/openbr/plugins/imgproc/threshold.cpp b/openbr/plugins/imgproc/threshold.cpp index cd5b6ad..1e4f53f 100644 --- a/openbr/plugins/imgproc/threshold.cpp +++ b/openbr/plugins/imgproc/threshold.cpp @@ -48,62 +48,6 @@ private: BR_REGISTER(Transform, ThresholdTransform) -class CropFromMaskTransform : public UntrainableTransform -{ - Q_OBJECT - Q_PROPERTY(bool fixedAspectRatio READ get_fixedAspectRatio WRITE set_fixedAspectRatio RESET reset_fixedAspectRatio STORED false) - BR_PROPERTY(bool, fixedAspectRatio, true) - -private: - - void project(const Template &src, Template &dst) const - { - dst = src; - - Mat mask = dst.file.get("Mask"); - - int w = mask.rows; - int h = mask.cols; - int left = w; - int right = 0; - int top = h; - int bottom = 0; - for (int i = 0 ; i < w; i++) { - for (int j = 0 ; j < h; j++) { - if (mask.at(i,j)) { - if (i < left) - left = i; - if (i > right) - right = i; - if (j < top) - top = j; - if (j > bottom) - bottom = j; - } - } - } - - if (fixedAspectRatio) { - h = bottom - top + 1; - w = right - left + 1; - if (h > w) { - int h2 = (h - w) / 2; - right += h2; - left -= h2; - } else { - int w2 = (w - h) / 2; - bottom += w2; - top -= w2; - } - } - - dst.m() = Mat(src.m(), Rect(top, left, bottom - top + 1, right - left + 1)); - - } -}; - -BR_REGISTER(Transform, CropFromMaskTransform) - } // namespace br #include "imgproc/threshold.moc" -- libgit2 0.21.4