1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
hema sharma
  • 27
  • 1
  • 2

1 Answers1

4

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, i. e. 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. internalNodesparameter 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 (i. e. 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.

avtomaton
  • 4,725
  • 1
  • 38
  • 42
  • If you dont mind can u tell me how can i get the position of the face that is detected? not the position of the rectangle drawn but the position of face detected... Thank you... @avtomaton – hema sharma Feb 21 '17 at 09:15
  • @hemasharma What do you mean as position? Haar cascade can detect bounding rect around face. Potential face rectangles are returned by detector. If you mean face pose - cascade bundled with opencv cannot estimate face pose. – avtomaton Feb 23 '17 at 14:50
  • @avtomanton thanks for your response.. Actually my project aim is to count the number of faces detected... i have achieved it partially... It gives me the count of faces detected per frame.... now i have to give it some time constraints; for example, a face has to be taken into count only if the face is detected for more than three seconds if its not detected for three seconds, the previous count has to be retained.... This is the main aim i have to achieve as of now.... so can u please help me out with this.... – hema sharma Feb 27 '17 at 09:16
  • thanks for your response.. Actually my project aim is to count the number of faces detected... i have achieved it partially... It gives me the count of faces detected per frame.... now i have to give it some time constraints; for example, a face has to be taken into count only if the face is detected for more than three seconds if its not detected for three seconds, the previous count has to be retained.... This is the main aim i have to achieve as of now.... so can u please help me out with this.... @avtomaton – hema sharma Mar 14 '17 at 11:20