HaarCascade Xml
的程式碼當中, 最主要的參數是去讀取 haarcascade_frontalface_alt.xml1 2 3 4 5 6 7 8 9 | int main(int argc, char** argv) { // Load preconstructed classifier face_cascade.load("data/haarcascade_frontalface_alt.xml"); Mat inputImage = imread(argv[1]); detectFaces(inputImage); waitKey(0); return 0; } |
這邊開始, 喵要詳細的解構這xml檔案
一開始的對於整個cascade的參數
<opencv_storage>
<cascade type_id="opencv-cascade-classifier"><stageType>BOOST</stageType>
<featureType>HAAR</featureType>
<height>20</height>
<width>20</width>
<stageParams>
<maxWeakCount>213</maxWeakCount></stageParams>
<featureParams>
<maxCatCount>0</maxCatCount></featureParams>
<stageNum>22</stageNum>
FeatureType: HAAR / LBP / HOG
Height: Mask 高度
Widht: Mask 寬度
stageParams --> maxWeakCount: 最多有幾個weak nodes in a classifier
maxCatCount: 最多串幾個 nodes (設定為0, 代表沒有使用串接)
stageNum: 共有多少個 Stage
從Stage往下細分可以簡易的分成幾個項目
先從第一個stage開始看起
<_>
<maxWeakCount>3</maxWeakCount>
<stageThreshold>8.2268941402435303e-01</stageThreshold>
<weakClassifiers>
<_>
<internalNodes>
0 -1 0 4.0141958743333817e-03</internalNodes>
<leafValues>
3.3794190734624863e-02 8.3781069517135620e-01</leafValues></_>
<_>
<internalNodes>
0 -1 1 1.5151339583098888e-02</internalNodes>
<leafValues>
1.5141320228576660e-01 7.4888122081756592e-01</leafValues></_>
<_>
<internalNodes>
0 -1 2 4.2109931819140911e-03</internalNodes>
<leafValues>
9.0049281716346741e-02 6.3748198747634888e-01</leafValues></_></weakClassifiers></_>
<_>
跟stage相關的設定是
maxWeakCount: 內含三個weakCount
stageThreshold: 定義的閥值, 超過了則判定有效
接著往下看 nodes
internalNodes: 一共四個數字, 分別是 left, right, featureIndex, threshold
leafValues: 代表left and right value
(featureIndex: 所帶的index則是在xml的下半部 rect中可以依序找到)
internalNodes 的 left 值是 0, 代表還要往下一個internalNodes判斷, right值是 -1, 則代表沒有下一個node了
判斷的方式是
1. 根據 featureIndex取出feature mask, 計算圖片得到 value
2. 判斷value 是否超過自帶的 threshold
3. 超過的話則取 right的 value, 沒有的話則是取left value, 如果nodes有下一階, 則往下一階進行
4. 將每一階段的 value相加, 看是否有超過stage的 threshold, 有則判斷有效
上述圖型是簡單的解釋 stage 1 當中三個 internalNodes 的流程
這xml其實也沒有很難吼 喵~
那這個xml怎麼產生出來的呢?
請期待下一個文章
FaceDectection - (四) 模型訓練
沒有留言:
張貼留言