limitsize.cpp
909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <opencv2/imgproc/imgproc.hpp>
#include <openbr/plugins/openbr_internal.h>
using namespace cv;
namespace br
{
/*!
* \ingroup transforms
* \brief Limit the size of the template
* \author Josh Klontz \cite jklontz
*/
class LimitSizeTransform : public UntrainableTransform
{
Q_OBJECT
Q_PROPERTY(int max READ get_max WRITE set_max RESET reset_max STORED false)
BR_PROPERTY(int, max, -1)
void project(const Template &src, Template &dst) const
{
const Mat &m = src;
if (m.rows > m.cols)
if (m.rows > max) resize(m, dst, Size(std::max(1, m.cols * max / m.rows), max));
else dst = m;
else
if (m.cols > max) resize(m, dst, Size(max, std::max(1, m.rows * max / m.cols)));
else dst = m;
}
};
BR_REGISTER(Transform, LimitSizeTransform)
} // namespace br
#include "limitsize.moc"