简体   繁体   中英

Haar cascade for face detection xml file code explanation OpenCV

I am performing face detection using opencv haar cascade.

I wanted to know the explanation of the xml code of the haar cascade that I have included in my program. Can someone help me to understand the values presented in the XML file, for instance: weakcount , maxcount , threshold , internal nodes , leaf values etc.

I have made use of the haarcascade_frontalface_alt2.xml file. I have already performed face detection. Currently I am working on counting the number of faces detected.

As I understand, in general you already know about haarcascade structure and OpenCV implementation of it. If no, please first look into OpenCV manual and read something about cascade of boosted trees, for example, Lienhart's paper .

Now about xml structure itself.

<maxWeakCount>3</maxWeakCount>

This parameter describe amount of simple classifiers (trees) at the stage.

<stageThreshold>3.5069230198860168e-01</stageThreshold>

It is stage threshold, ie threshold score for exiting from cascade at the stage. During all stages, we compute final score from trees, and when final score is less then threshold, we exit from entire cascade and consider result as non-object.

<weakClassifiers>

Start of trees parameters in the stage.

<_>
  <internalNodes>
    0 1 0 4.3272329494357109e-03 -1 -2 1 1.3076160103082657e-02
  </internalNodes>
  <leafValues>
    3.8381900638341904e-02 8.9652568101882935e-01 2.6293140649795532e-01
  </leafValues>
</_>

This is tree description. internalNodes parameter contains the following:

  • 0 1 or 1 0 defines leaf index in current node where we should go. In a first case we go to the left if value is below threshold and to the right if above, and in a second case we go to the right leaf if value is above threshold.
  • feature index
  • threshold for choosing leaf
  • there is one more -1 -2 1 ... parameters list - as I see from OpenCV sources, it is just another node with leaf indexes, but negative values are ignored according to evaluation code (also from OpenCV sources).

Consider cascade evaluation code:

do
{
    CascadeClassifierImpl::Data::DTreeNode& node = cascadeNodes[root + idx];
    double val = featureEvaluator(node.featureIdx);
    idx = val < node.threshold ? node.left : node.right;
}
while( idx > 0 );

leafValues contains left value (ie left leaf score), right value (right leaf score) and tree threshold.

<_>
<rects>
  <_>
    6 3 1 9 -1.</_>
  <_>
    6 6 1 3 3.</_></rects></_>
<_>

It is feature description itself according to HAAR paradigm. Feature index from previous section describes index of rects pair.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM