Commit 3fcbaa1556db562dca5abe042faa7beac2dd28cb
1 parent
88f9cd92
add scale factor option to scaleRects.
Showing
1 changed file
with
15 additions
and
1 deletions
openbr/plugins/metadata/scalerects.cpp
| ... | ... | @@ -24,13 +24,14 @@ namespace br |
| 24 | 24 | |
| 25 | 25 | /*! |
| 26 | 26 | * \ingroup transforms |
| 27 | - * \brief Creates a bounding square around three points (typically the two eyes and the chin). | |
| 27 | + * \brief Scales a rectangle either by pixel value or factor. | |
| 28 | 28 | * \author Scott Klum \cite sklum |
| 29 | 29 | * \br_property int index Index of rect to scale. |
| 30 | 30 | * \br_property int left Number of pixels to scale the left of the rect. |
| 31 | 31 | * \br_property int top Number of pixels to scale the top of the rect. |
| 32 | 32 | * \br_property int right Number of pixels to scale the right of the rect. |
| 33 | 33 | * \br_property int bottom Number of pixels to scale the bottom of the rect. |
| 34 | + * \br_property float factor Scale factor. | |
| 34 | 35 | */ |
| 35 | 36 | class ScaleRectsTransform : public UntrainableTransform |
| 36 | 37 | { |
| ... | ... | @@ -41,15 +42,28 @@ class ScaleRectsTransform : public UntrainableTransform |
| 41 | 42 | Q_PROPERTY(int top READ get_top WRITE set_top RESET reset_top STORED false) |
| 42 | 43 | Q_PROPERTY(int right READ get_right WRITE set_right RESET reset_right STORED false) |
| 43 | 44 | Q_PROPERTY(int bottom READ get_bottom WRITE set_bottom RESET reset_bottom STORED false) |
| 45 | + Q_PROPERTY(float factor READ get_factor WRITE set_factor RESET reset_factor STORED false) | |
| 44 | 46 | BR_PROPERTY(int, index, 0) |
| 45 | 47 | BR_PROPERTY(int, left, -15) |
| 46 | 48 | BR_PROPERTY(int, top, -25) |
| 47 | 49 | BR_PROPERTY(int, right, 15) |
| 48 | 50 | BR_PROPERTY(int, bottom, 5) |
| 51 | + BR_PROPERTY(float, factor, 0) | |
| 49 | 52 | |
| 50 | 53 | void project(const Template &src, Template &dst) const { |
| 51 | 54 | dst = src; |
| 52 | 55 | QList<QRectF> rects = src.file.rects(); |
| 56 | + if (factor) { | |
| 57 | + QRectF orig = rects[index]; | |
| 58 | + float scaledArea = factor*orig.width()*orig.height(); | |
| 59 | + float scaledWidth = sqrt(scaledArea*(orig.width()/orig.height())); | |
| 60 | + QRectF scaled(0, 0, scaledWidth, scaledWidth/(orig.width()/orig.height())); | |
| 61 | + scaled.moveCenter(orig.center()); | |
| 62 | + rects.replace(index, scaled); | |
| 63 | + dst.file.setRects(OpenCVUtils::toRects(rects)); | |
| 64 | + return; | |
| 65 | + } | |
| 66 | + | |
| 53 | 67 | QRectF rect = rects[index].adjusted(left, top, right, bottom); |
| 54 | 68 | rects.replace(index, rect); |
| 55 | 69 | dst.file.setRects(OpenCVUtils::toRects(rects)); | ... | ... |