-
Notifications
You must be signed in to change notification settings - Fork 1
/
haartree.h
104 lines (83 loc) · 2.91 KB
/
haartree.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* QtHaar, Viola-Jones implementation in Qt.
* Copyright (C) 2015 Gonzalo Exequiel Pedone
*
* QtHaar is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QtHaar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QtHaar. If not, see <http://www.gnu.org/licenses/>.
*
* Email : hipersayan DOT x AT gmail DOT com
* Web-Site: http://github.com/hipersayanX/QtHaar
*/
#ifndef HAARTREE_H
#define HAARTREE_H
#include "haarfeature.h"
class HaarTree;
typedef QVector<HaarTree> HaarTreeVector;
class HaarTreeHID
{
public:
explicit HaarTreeHID(const HaarTree &tree,
int oWidth,
const quint32 *integral,
const quint32 *tiltedIntegral,
qreal invArea,
qreal scale);
~HaarTreeHID();
int m_count;
HaarFeatureHID **m_features;
inline qreal eval(size_t offset, qreal varianceNormFactor) const
{
int idx = 0;
qreal treeValue;
forever {
const HaarFeatureHID *feature = this->m_features[idx];
if (feature->goLeft(offset, varianceNormFactor)) {
if (feature->m_leftNode < 0) {
treeValue = feature->m_leftVal;
break;
}
else
idx = feature->m_leftNode;
} else {
if (feature->m_rightNode < 0) {
treeValue = feature->m_rightVal;
break;
}
else
idx = feature->m_rightNode;
}
}
return treeValue;
}
};
class HaarTree: public QObject
{
Q_OBJECT
public:
explicit HaarTree(QObject *parent = NULL);
HaarTree(const HaarTree &other);
~HaarTree();
Q_INVOKABLE HaarFeatureVector features() const;
Q_INVOKABLE HaarFeatureVector &features();
HaarTree &operator =(const HaarTree &other);
bool operator ==(const HaarTree &other) const;
bool operator !=(const HaarTree &other) const;
private:
HaarFeatureVector m_features;
signals:
void featuresChanged(const HaarFeatureVector &features);
public slots:
void setFeatures(const HaarFeatureVector &features);
void resetFeatures();
friend class HaarTreeHID;
};
#endif // HAARTREE_H