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 HAARSTAGE_H 21 #define HAARSTAGE_H 22 23 #include "haartree.h" 24 25 class HaarStage; 26 27 using HaarStageVector = QVector<HaarStage>; 28 29 class HaarStageHID 30 { 31 public: 32 HaarStageHID(const HaarStage &stage, 33 int oWidth, 34 const quint32 *integral, 35 const quint32 *tiltedIntegral, 36 qreal invArea, 37 qreal scale); 38 HaarStageHID(const HaarStageHID &other) = delete; 39 ~HaarStageHID(); 40 41 int m_count {0}; 42 HaarTreeHID **m_trees {nullptr}; 43 qreal m_threshold {0.0}; 44 HaarStageHID *m_parentStagePtr {nullptr}; 45 HaarStageHID *m_nextStagePtr {nullptr}; 46 HaarStageHID *m_childStagePtr {nullptr}; 47 pass(size_t offset,qreal varianceNormFactor)48 inline bool pass(size_t offset, qreal varianceNormFactor) const 49 { 50 qreal sum = 0; 51 52 for (int i = 0; i < this->m_count; i++) 53 sum += this->m_trees[i]->eval(offset, varianceNormFactor); 54 55 return sum >= this->m_threshold; 56 } 57 }; 58 59 class HaarStagePrivate; 60 61 class HaarStage: public QObject 62 { 63 Q_OBJECT 64 65 public: 66 HaarStage(QObject *parent=nullptr); 67 HaarStage(const HaarStage &other); 68 ~HaarStage(); 69 70 Q_INVOKABLE HaarTreeVector trees() const; 71 Q_INVOKABLE HaarTreeVector &trees(); 72 Q_INVOKABLE qreal threshold() const; 73 Q_INVOKABLE qreal &threshold(); 74 Q_INVOKABLE int parentStage() const; 75 Q_INVOKABLE int &parentStage(); 76 Q_INVOKABLE int nextStage() const; 77 Q_INVOKABLE int &nextStage(); 78 Q_INVOKABLE int childStage() const; 79 Q_INVOKABLE int &childStage(); 80 81 HaarStage &operator =(const HaarStage &other); 82 bool operator ==(const HaarStage &other) const; 83 bool operator !=(const HaarStage &other) const; 84 85 private: 86 HaarStagePrivate *d; 87 88 signals: 89 void treesChanged(const HaarTreeVector &trees); 90 void thresholdChanged(qreal threshold); 91 void parentStageChanged(int parentStage); 92 void nextStageChanged(int nextStage); 93 void childStageChanged(int childStage); 94 95 public slots: 96 void setTrees(const HaarTreeVector &trees); 97 void setThreshold(qreal threshold); 98 void setParentStage(int parentStage); 99 void setNextStage(int nextStage); 100 void setChildStage(int childStage); 101 void resetTrees(); 102 void resetThreshold(); 103 void resetParentStage(); 104 void resetNextStage(); 105 void resetChildStage(); 106 107 friend class HaarStageHID; 108 }; 109 110 #endif // HAARSTAGE_H 111