Ask Your Question
3

Explanation of cascade.xml in a haar classifier

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

ythen gravatar image

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

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

What are the meanings of these values

      <internalNodes>
        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

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

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?

Summary

  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.

Thanks!

edit retag flag offensive close merge delete

Comments

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

Is any documentation now available?

Thanks

PeterBalch gravatar imagePeterBalch ( 2019-06-10 07:01:59 -0600 )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 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
3

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

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

Comments

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.

Example:

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: http://ars.els-cdn.com/content/image/1-s2.0-S1077314211001391-gr6.jpg

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-14 03:35:38 -0600 )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 -0600 )edit
1

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 -0600 )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 -0600 )edit
1

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 -0600 )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 -0600 )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 -0600 )edit
2

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

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

Comments

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 -0600 )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 -0600 )edit
1

@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 -0600 )edit
1

yeah that seems correct

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

@StevenPuttemans thank you!

DerrickB gravatar imageDerrickB ( 2016-11-24 07:45:10 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 7,453 times

Last updated: Apr 11 '13