Commit 783d281f4fa2b4bf2cba0542f0d1276b8d090d10
Merge pull request #280 from biometrics/read_transform
Added ReadTransform
Showing
1 changed file
with
42 additions
and
0 deletions
openbr/plugins/misc.cpp
| @@ -90,6 +90,48 @@ BR_REGISTER(Transform, DecodeTransform) | @@ -90,6 +90,48 @@ BR_REGISTER(Transform, DecodeTransform) | ||
| 90 | 90 | ||
| 91 | /*! | 91 | /*! |
| 92 | * \ingroup transforms | 92 | * \ingroup transforms |
| 93 | + * \brief Read images | ||
| 94 | + * \author Josh Klontz \cite jklontz | ||
| 95 | + */ | ||
| 96 | +class ReadTransform : public UntrainableMetaTransform | ||
| 97 | +{ | ||
| 98 | + Q_OBJECT | ||
| 99 | + Q_ENUMS(Mode) | ||
| 100 | + Q_PROPERTY(Mode mode READ get_mode WRITE set_mode RESET reset_mode) | ||
| 101 | + | ||
| 102 | +public: | ||
| 103 | + enum Mode | ||
| 104 | + { | ||
| 105 | + Unchanged = IMREAD_UNCHANGED, | ||
| 106 | + Grayscale = IMREAD_GRAYSCALE, | ||
| 107 | + Color = IMREAD_COLOR, | ||
| 108 | + AnyDepth = IMREAD_ANYDEPTH, | ||
| 109 | + AnyColor = IMREAD_ANYCOLOR | ||
| 110 | + }; | ||
| 111 | + | ||
| 112 | +private: | ||
| 113 | + BR_PROPERTY(Mode, mode, Color) | ||
| 114 | + | ||
| 115 | + void project(const Template &src, Template &dst) const | ||
| 116 | + { | ||
| 117 | + dst.file = src.file; | ||
| 118 | + if (src.empty()) { | ||
| 119 | + const Mat img = imread(src.file.resolved().toStdString(), mode); | ||
| 120 | + if (img.data) dst.append(img); | ||
| 121 | + else dst.file.fte = true; | ||
| 122 | + } else { | ||
| 123 | + foreach (const Mat &m, src) { | ||
| 124 | + const Mat img = imdecode(m, mode); | ||
| 125 | + if (img.data) dst.append(img); | ||
| 126 | + else dst.file.fte = true; | ||
| 127 | + } | ||
| 128 | + } | ||
| 129 | + } | ||
| 130 | +}; | ||
| 131 | +BR_REGISTER(Transform, ReadTransform) | ||
| 132 | + | ||
| 133 | +/*! | ||
| 134 | + * \ingroup transforms | ||
| 93 | * \brief Downloads an image from a URL | 135 | * \brief Downloads an image from a URL |
| 94 | * \author Josh Klontz \cite jklontz | 136 | * \author Josh Klontz \cite jklontz |
| 95 | */ | 137 | */ |