1 /* Webcamoid, webcam capture application. 2 * Copyright (C) 2016 Gonzalo Exequiel Pedone 3 * 4 * Webcamoid is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * Webcamoid is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with Webcamoid. If not, see <http://www.gnu.org/licenses/>. 16 * 17 * Web-Site: http://webcamoid.github.io/ 18 */ 19 20 #ifndef HAARTREE_H 21 #define HAARTREE_H 22 23 #include "haarfeature.h" 24 25 class HaarTree; 26 27 using HaarTreeVector = QVector<HaarTree>; 28 29 class HaarTreeHID 30 { 31 public: 32 HaarTreeHID(const HaarTree &tree, 33 int oWidth, 34 const quint32 *integral, 35 const quint32 *tiltedIntegral, 36 qreal invArea, 37 qreal scale); 38 HaarTreeHID(const HaarTreeHID &other) = delete; 39 ~HaarTreeHID(); 40 41 int m_count; 42 HaarFeatureHID **m_features; 43 eval(size_t offset,qreal varianceNormFactor)44 inline qreal eval(size_t offset, qreal varianceNormFactor) const 45 { 46 int idx = 0; 47 qreal treeValue; 48 49 forever { 50 const HaarFeatureHID *feature = this->m_features[idx]; 51 52 if (feature->goLeft(offset, varianceNormFactor)) { 53 if (feature->m_leftNode < 0) { 54 treeValue = feature->m_leftVal; 55 56 break; 57 } 58 else 59 idx = feature->m_leftNode; 60 } else { 61 if (feature->m_rightNode < 0) { 62 treeValue = feature->m_rightVal; 63 64 break; 65 } 66 else 67 idx = feature->m_rightNode; 68 } 69 } 70 71 return treeValue; 72 } 73 }; 74 75 class HaarTree: public QObject 76 { 77 Q_OBJECT 78 79 public: 80 HaarTree(QObject *parent=nullptr); 81 HaarTree(const HaarTree &other); 82 ~HaarTree() = default; 83 84 Q_INVOKABLE HaarFeatureVector features() const; 85 Q_INVOKABLE HaarFeatureVector &features(); 86 87 HaarTree &operator =(const HaarTree &other); 88 bool operator ==(const HaarTree &other) const; 89 bool operator !=(const HaarTree &other) const; 90 91 private: 92 HaarFeatureVector m_features; 93 94 signals: 95 void featuresChanged(const HaarFeatureVector &features); 96 97 public slots: 98 void setFeatures(const HaarFeatureVector &features); 99 void resetFeatures(); 100 101 friend class HaarTreeHID; 102 }; 103 104 #endif // HAARTREE_H 105