Commit 4904f6e0d4a6ad77a3bf0ef545a86042b9c9091e

Authored by Brendan Klare
1 parent 9d0e789a

Final crop region from mask code

openbr/plugins/imgproc/threshold.cpp
... ... @@ -51,6 +51,8 @@ BR_REGISTER(Transform, ThresholdTransform)
51 51 class CropFromMaskTransform : public UntrainableTransform
52 52 {
53 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)
54 56  
55 57 private:
56 58  
... ... @@ -80,7 +82,22 @@ private:
80 82 }
81 83 }
82 84 }
83   -qDebug() << left << right << top << bottom;
  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));
84 101  
85 102 }
86 103 };
... ...