Commit c1ace94d97d3f5af62e16442e0de4fd273ddf231
1 parent
3ff62749
Transform to sample negative patches
Showing
1 changed file
with
52 additions
and
0 deletions
openbr/plugins/metadata/randomrects.cpp
0 → 100644
| 1 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
| 2 | + * Copyright 2015 Rank One Computing Corporation * | |
| 3 | + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
| 4 | + | |
| 5 | +#include <openbr/plugins/openbr_internal.h> | |
| 6 | +#include <openbr/core/opencvutils.h> | |
| 7 | + | |
| 8 | +namespace br | |
| 9 | +{ | |
| 10 | + | |
| 11 | +/*! | |
| 12 | + * \ingroup transforms | |
| 13 | + * \brief Creates random rectangles within an image. Used for creating negative samples. | |
| 14 | + * \author Brendan Klare \cite bklare | |
| 15 | + */ | |
| 16 | +class RandomRectsTransform : public UntrainableMetaTransform | |
| 17 | +{ | |
| 18 | + Q_OBJECT | |
| 19 | + Q_PROPERTY(int numRects READ get_numRects WRITE set_numRects RESET reset_numRects STORED false) | |
| 20 | + Q_PROPERTY(int minSize READ get_minSize WRITE set_minSize RESET reset_minSize STORED false) | |
| 21 | + BR_PROPERTY(int, numRects, 135) | |
| 22 | + BR_PROPERTY(int, minSize, 24) | |
| 23 | + | |
| 24 | + void project(const Template &src, Template &dst) const | |
| 25 | + { | |
| 26 | + qFatal("NOT SUPPORTED"); | |
| 27 | + } | |
| 28 | + | |
| 29 | + void project(const TemplateList &src, TemplateList &dst) const | |
| 30 | + { | |
| 31 | + foreach (const Template &t, src) { | |
| 32 | + int maxSize = std::min(t.m().rows, t.m().cols); | |
| 33 | + for (int i = 0; i < numRects; i++) { | |
| 34 | + int size = (rand() % (maxSize - minSize)) + minSize; | |
| 35 | + int x = rand() % (t.m().cols - size); | |
| 36 | + int y = rand() % (t.m().rows - size); | |
| 37 | + | |
| 38 | + Template out(t.file, t.m()); | |
| 39 | + out.file.clearRects(); | |
| 40 | + out.file.appendRect(QRect(x,y,size,size)); | |
| 41 | + out.file.set("FrontalFace", QRect(x,y,size,size)); | |
| 42 | + dst.append(out); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + } | |
| 46 | +}; | |
| 47 | + | |
| 48 | +BR_REGISTER(Transform, RandomRectsTransform) | |
| 49 | + | |
| 50 | +} // namespace br | |
| 51 | + | |
| 52 | +#include "metadata/randomrects.moc" | ... | ... |