Commit c1535bee409fc5fcf324ca9f1e0d5b09150fa4bb

Authored by Josh Klontz
1 parent fa4eb42f

added reduce transform

Showing 1 changed file with 40 additions and 0 deletions
sdk/plugins/reduce.cpp
@@ -79,6 +79,46 @@ class AndTransform : public UntrainableMetaTransform @@ -79,6 +79,46 @@ class AndTransform : public UntrainableMetaTransform
79 79
80 BR_REGISTER(Transform, AndTransform) 80 BR_REGISTER(Transform, AndTransform)
81 81
  82 +/*!
  83 + * \ingroup transforms
  84 + * \brief Statistics
  85 + * \author Josh Klontz \cite jklontz
  86 + */
  87 +class StatTransform : public UntrainableTransform
  88 +{
  89 + Q_OBJECT
  90 + Q_ENUMS(Statistic)
  91 + Q_PROPERTY(Statistic statistic READ get_statistic WRITE set_statistic RESET reset_statistic STORED false)
  92 +
  93 +public:
  94 + /*!
  95 + * \brief Available statistics
  96 + */
  97 + enum Statistic { Min, Max, Mean, StdDev };
  98 +
  99 +private:
  100 + BR_PROPERTY(Statistic, statistic, Mean)
  101 +
  102 + void project(const Template &src, Template &dst) const
  103 + {
  104 + if (src.m().channels() != 1)
  105 + qFatal("Expected 1 channel matrix.");
  106 + Mat m(1, 1, CV_32FC1);
  107 + if ((statistic == Min) || (statistic == Max)) {
  108 + double min, max;
  109 + minMaxLoc(src, &min, &max);
  110 + m.at<float>(1, 1) = (statistic == Min ? min : max);
  111 + } else {
  112 + Scalar mean, stddev;
  113 + meanStdDev(src, mean, stddev);
  114 + m.at<float>(1,1) = (statistic == Mean ? mean[0] : stddev[0]);
  115 + }
  116 + dst = m;
  117 + }
  118 +};
  119 +
  120 +BR_REGISTER(Transform, StatTransform)
  121 +
82 } // namespace br 122 } // namespace br
83 123
84 #include "reduce.moc" 124 #include "reduce.moc"