From 4904f6e0d4a6ad77a3bf0ef545a86042b9c9091e Mon Sep 17 00:00:00 2001 From: Brendan Klare Date: Mon, 2 Mar 2015 21:53:04 -0500 Subject: [PATCH] Final crop region from mask code --- openbr/plugins/imgproc/threshold.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/openbr/plugins/imgproc/threshold.cpp b/openbr/plugins/imgproc/threshold.cpp index c7a6dfd..cd5b6ad 100644 --- a/openbr/plugins/imgproc/threshold.cpp +++ b/openbr/plugins/imgproc/threshold.cpp @@ -51,6 +51,8 @@ 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: @@ -80,7 +82,22 @@ private: } } } -qDebug() << left << right << top << bottom; + + 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)); } }; -- libgit2 0.21.4