Commit 0e1d890a0ee8a66d7ec7d7499e4cf68f1ee05a1c
1 parent
425001eb
Transform to randomly sample a gallery
Showing
1 changed file
with
34 additions
and
0 deletions
openbr/plugins/metadata/randomtemplates.cpp
0 → 100644
| 1 | +#include <openbr/plugins/openbr_internal.h> | ||
| 2 | + | ||
| 3 | +namespace br | ||
| 4 | +{ | ||
| 5 | + | ||
| 6 | +/*! | ||
| 7 | + * \ingroup transforms | ||
| 8 | + * \author Brendan Klare \cite bklare | ||
| 9 | + * \brief Randomly sample templates from a gallery | ||
| 10 | + */ | ||
| 11 | +class RandomTemplatesTransform : public UntrainableMetaTransform | ||
| 12 | +{ | ||
| 13 | + Q_OBJECT | ||
| 14 | + Q_PROPERTY(float percent READ get_percent WRITE set_percent RESET reset_percent) | ||
| 15 | + BR_PROPERTY(float, percent, .01) | ||
| 16 | + | ||
| 17 | + void project(const Template &src, Template &dst) const { | ||
| 18 | + qFatal("Not supported in RandomTemplates."); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + void project(const TemplateList &src, TemplateList &dst) const { | ||
| 22 | + for (int i = 0; i < src.size(); i++) { | ||
| 23 | + const float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); | ||
| 24 | + if (r <= percent) | ||
| 25 | + dst.append(src[i]); | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +}; | ||
| 29 | +BR_REGISTER(Transform, RandomTemplatesTransform) | ||
| 30 | + | ||
| 31 | +} // namespace br | ||
| 32 | + | ||
| 33 | +#include "imgproc/randomtemplates.moc" | ||
| 34 | + |