Ask Your Question

Explanation of cascade.xml in a haar classifier

asked 2013-03-04 00:04:05 -0500

ythen gravatar image

It would be best if someone could explain the numbers/values in the cascade.xml entirely. Example in:

<!-- stage 0 -->
        0 -1 66 5.1593100652098656e-003</internalNodes>
        -8.0555558204650879e-001 8.0694979429244995e-001</leafValues></_>
        0 -1 108 1.5044789761304855e-002</internalNodes>
        -6.2940740585327148e-001 7.5122624635696411e-001</leafValues></_>
        0 -1 99 -4.7172707127174363e-005</internalNodes>
        5.5112153291702271e-001 -8.6111217737197876e-001</leafValues></_></weakClassifiers></_>

What are the meanings of these values

        0 -1 99 -4.7172707127174363e-005</internalNodes>

Another question is, how does the program know which feature to use for a particular stage? As far as I know, features are in the form as below

      21 6 3 5 -1.</_>
      22 6 1 5 3.</_></rects>

Whereby it's the coordinates of two rectangles, forming something like below:

=-=    = Black colored rectangle
=-=    - White colored rectangle

What are the values -1. and 3. mean? I know it's weights but how is it used to calculate the feature?


  1. What are the meaning of the values inside <internalNodes>?
  2. How is the feature calculated? How are the weights in <rects> use?
  3. Most importantly, which field denotes that which features are being used in a particular stage/node.


edit retag flag offensive close merge delete


This thread is six years old. The answers above seem rather vague.

Is any documentation now available?


PeterBalch gravatar imagePeterBalch ( 2019-06-10 07:01:59 -0500 )edit

The most recent write up I did on this (since this technique is terribly outdated) is in the OpenCV 3 Blueprints book, which can still be ordered through Packt Publishing.

StevenPuttemans gravatar imageStevenPuttemans ( 2019-06-26 04:31:52 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2013-03-14 02:32:38 -0500

ythen gravatar image

After digging into OpenCV's source code, I finally obtain answers to my own questions.

  • Values enclosed withtin internalNodes tags

node.left node.right node.featureIdx node.threshold

I'm not sure what's node.left and node.right are for as I can't see them being called anywhere.

  • The weights are used to calculate the feature as in below:

float ret = rect[0].weight * CALC_SUM(p[0], _offset) + rect[1].weight * CALC_SUM(p[1], _offset);

  • As mentioned in the first bullet, the node.featureIdx are the index of the feature that's being evaluated at that particular node.
edit flag offensive delete link more


Isn't it possible that left and right are there to actually know based on your threshold, which next node from your xml file you should check? It seems obvious to me if you explain it like that.


A has A1 and A2 as child nodes, based on threshold T1 and feature F1. A1 and A2 are again two new rules, defining T11, T12, F11 and F12. When an image gets in, F1 feature is calculated, then thresholded, defining if we should go to A1 or to A2 for the second step.

However as it is a cascaded structure, mostly A1 will be just to terminate, A2 will be to continue to the next feature stage. This sortlike structure can be seen here:

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-14 03:35:38 -0500 )edit

Thanks for your feedback but I think you are referring to LBP and not HAAR classifier

wytmoon gravatar imagewytmoon ( 2013-03-22 03:18:22 -0500 )edit

The way boosting works is not dependant on the type of feature. LBP and HAAR classifier only differ in the feature calculation, the adaBoost algorithm creates the same structure.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-22 04:03:16 -0500 )edit

I was trying to ask new question "Featur tag is missing in cascade.xml using opencv_traincascade" but forum is pointing me over here!! <br>

I created the cascade successfully, but I was wondering that in xml file there is no feature tag in my xml file, are they generated automatically by opencv_traincascade or we have to write some extra code for that, In my case i have only used opencv_traincascade and created very ugly cascade.

Anshul gravatar imageAnshul ( 2013-08-16 03:44:01 -0500 )edit

If the tags are not there, then the process didn't succeed in creating the correct tags ... which means that the training was probably not successfull.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-16 04:15:44 -0500 )edit

guys, as far as i understand, those internal node values are used as arguments of decision tree build up when adaboost train the feature pool. Correct me if i am wrong.

sodeq gravatar imagesodeq ( 2013-10-22 01:38:31 -0500 )edit

I know it has been quite a long time but I am writing a text and wrapup about the models and came to a partial conclusion on what the node left and node right values are. These are the indexes assigning the node structure. 0 -1 means you have a stump, a single feature decision tree. If you expand this to more than a stump than more values appear like in this model. I will try to see if I can find a meaning behind it.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-31 07:48:39 -0500 )edit

answered 2013-03-04 09:42:21 -0500

The cascade file contains several things

  1. Internalnodes which are stages consisting of weak classifiers used to create a robust classifier. These are stages used in the boosting process used when creating such a model.
  2. The parameters covered there are the SVM parameters needed to divide the data into positive and negative samples, as seen by the weak classifier.
  3. Rectangles are the feature windows used for detection, but you should dig into the original code for creating these files to actually know what the values mean. No clue here.
edit flag offensive delete link more


Hey there Steve, I have a small doubt here. You mentioned that the params cover the SVM parameters. But I am not able to locate any SVM calls in the traincascade app. Can you throw some more light on this thing which i am missing? Thanks.

Prasanna gravatar imagePrasanna ( 2013-06-19 01:55:44 -0500 )edit

I have to adapt my answer basically. I have dig in it some more and I was wrong telling you it are SVM parameters. In fact a cascade file contains only parameters defining the decisions criteria of the weak classifiers created by the boosting process. The weak classifiers are not handled in SVM classification, there I was wrong.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-06-28 02:44:27 -0500 )edit

@StevenPuttemans Is it right to think of it like this: in Stage "n" the Classifier checks the image with Feature 1 and if the Value is bigger/ smaller as the Feature Threshold the first/ second LeafValue is added to the stagevalue. After all Features of the stage the StageValue is compared with the stagethreshold and decided if the stage is passed or not????

DerrickB gravatar imageDerrickB ( 2016-11-24 07:27:47 -0500 )edit

yeah that seems correct

StevenPuttemans gravatar imageStevenPuttemans ( 2016-11-24 07:31:50 -0500 )edit

@StevenPuttemans thank you!

DerrickB gravatar imageDerrickB ( 2016-11-24 07:45:10 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2013-03-04 00:04:05 -0500

Seen: 6,127 times

Last updated: Apr 11 '13