Commit b290d3f4cba179a3c030c94e71cb37cf444f82a7
1 parent
363e2052
introduced some new transforms
Showing
2 changed files
with
91 additions
and
0 deletions
sdk/plugins/hist.cpp
| ... | ... | @@ -66,6 +66,38 @@ BR_REGISTER(Transform, HistTransform) |
| 66 | 66 | |
| 67 | 67 | /*! |
| 68 | 68 | * \ingroup transforms |
| 69 | + * \brief Quantizes the values into bins. | |
| 70 | + * \author Josh Klontz \cite jklontz | |
| 71 | + */ | |
| 72 | +class BinTransform : public UntrainableTransform | |
| 73 | +{ | |
| 74 | + Q_OBJECT | |
| 75 | + Q_PROPERTY(float min READ get_min WRITE set_min RESET reset_min STORED false) | |
| 76 | + Q_PROPERTY(float max READ get_max WRITE set_max RESET reset_max STORED false) | |
| 77 | + Q_PROPERTY(int bins READ get_bins WRITE set_bins RESET reset_bins STORED false) | |
| 78 | + Q_PROPERTY(bool split READ get_split WRITE set_split RESET reset_split STORED false) | |
| 79 | + BR_PROPERTY(float, min, 0) | |
| 80 | + BR_PROPERTY(float, max, 255) | |
| 81 | + BR_PROPERTY(int, bins, 8) | |
| 82 | + BR_PROPERTY(bool, split, false) | |
| 83 | + | |
| 84 | + void project(const Template &src, Template &dst) const | |
| 85 | + { | |
| 86 | + src.m().convertTo(dst, bins > 256 ? CV_16U : CV_8U, bins/(max-min)); | |
| 87 | + if (!split) return; | |
| 88 | + | |
| 89 | + Mat input = dst; | |
| 90 | + QList<Mat> outputs; outputs.reserve(bins); | |
| 91 | + for (int i=0; i<bins; i++) | |
| 92 | + outputs.append(input == i); | |
| 93 | + dst.clear(); dst.append(outputs); | |
| 94 | + } | |
| 95 | +}; | |
| 96 | + | |
| 97 | +BR_REGISTER(Transform, BinTransform) | |
| 98 | + | |
| 99 | +/*! | |
| 100 | + * \ingroup transforms | |
| 69 | 101 | * \brief Converts each element to its rank-ordered value. |
| 70 | 102 | * \author Josh Klontz \cite jklontz |
| 71 | 103 | */ | ... | ... |
sdk/plugins/integral.cpp
0 → 100644
| 1 | +#include <opencv2/imgproc/imgproc.hpp> | |
| 2 | +#include <openbr_plugin.h> | |
| 3 | + | |
| 4 | +namespace br | |
| 5 | +{ | |
| 6 | + | |
| 7 | +/*! | |
| 8 | + * \ingroup transforms | |
| 9 | + * \brief Computes integral image. | |
| 10 | + * \author Josh Klontz \cite jklontz | |
| 11 | + */ | |
| 12 | +class IntegralTransform : public UntrainableTransform | |
| 13 | +{ | |
| 14 | + Q_OBJECT | |
| 15 | + | |
| 16 | + void project(const Template &src, Template &dst) const | |
| 17 | + { | |
| 18 | + cv::integral(src, dst); | |
| 19 | + } | |
| 20 | +}; | |
| 21 | + | |
| 22 | +BR_REGISTER(Transform, IntegralTransform) | |
| 23 | + | |
| 24 | +/*! | |
| 25 | + * \ingroup transforms | |
| 26 | + * \brief Computes magnitude and/or angle of image. | |
| 27 | + * \author Josh Klontz \cite jklontz | |
| 28 | + */ | |
| 29 | +class GradientTransform : public UntrainableTransform | |
| 30 | +{ | |
| 31 | + Q_OBJECT | |
| 32 | + Q_ENUMS(Channel) | |
| 33 | + Q_PROPERTY(Channel channel READ get_channel WRITE set_channel RESET reset_channel STORED false) | |
| 34 | + | |
| 35 | +public: | |
| 36 | + enum Channel { Magnitude, Angle, MagnitudeAndAngle }; | |
| 37 | + | |
| 38 | +private: | |
| 39 | + BR_PROPERTY(Channel, channel, Angle) | |
| 40 | + | |
| 41 | + void project(const Template &src, Template &dst) const | |
| 42 | + { | |
| 43 | + if (src.m().type() != CV_8UC1) qFatal("Requires CV_8UC1 input."); | |
| 44 | + cv::Mat dx, dy, magnitude, angle; | |
| 45 | + cv::Sobel(src, dx, CV_32F, 1, 0); | |
| 46 | + cv::Sobel(src, dy, CV_32F, 0, 1); | |
| 47 | + cv::cartToPolar(dx, dy, magnitude, angle, true); | |
| 48 | + if ((channel == Magnitude) || (channel == MagnitudeAndAngle)) | |
| 49 | + dst.append(magnitude); | |
| 50 | + if ((channel == Angle) || (channel == MagnitudeAndAngle)) | |
| 51 | + dst.append(angle); | |
| 52 | + } | |
| 53 | +}; | |
| 54 | + | |
| 55 | +BR_REGISTER(Transform, GradientTransform) | |
| 56 | + | |
| 57 | +} // namespace br | |
| 58 | + | |
| 59 | +#include "integral.moc" | ... | ... |