Commit 9d0e789a5535a6260aef70959672dd22e5e04894

Authored by Brendan Klare
1 parent 5bc956a5

Initial transform

openbr/plugins/imgproc/threshold.cpp
@@ -48,6 +48,45 @@ private: @@ -48,6 +48,45 @@ private:
48 48
49 BR_REGISTER(Transform, ThresholdTransform) 49 BR_REGISTER(Transform, ThresholdTransform)
50 50
  51 +class CropFromMaskTransform : public UntrainableTransform
  52 +{
  53 + Q_OBJECT
  54 +
  55 +private:
  56 +
  57 + void project(const Template &src, Template &dst) const
  58 + {
  59 + dst = src;
  60 +
  61 + Mat mask = dst.file.get<Mat>("Mask");
  62 +
  63 + int w = mask.rows;
  64 + int h = mask.cols;
  65 + int left = w;
  66 + int right = 0;
  67 + int top = h;
  68 + int bottom = 0;
  69 + for (int i = 0 ; i < w; i++) {
  70 + for (int j = 0 ; j < h; j++) {
  71 + if (mask.at<unsigned char>(i,j)) {
  72 + if (i < left)
  73 + left = i;
  74 + if (i > right)
  75 + right = i;
  76 + if (j < top)
  77 + top = j;
  78 + if (j > bottom)
  79 + bottom = j;
  80 + }
  81 + }
  82 + }
  83 +qDebug() << left << right << top << bottom;
  84 +
  85 + }
  86 +};
  87 +
  88 +BR_REGISTER(Transform, CropFromMaskTransform)
  89 +
51 } // namespace br 90 } // namespace br
52 91
53 #include "imgproc/threshold.moc" 92 #include "imgproc/threshold.moc"