Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explanation of cascade.xml in a haar classifier

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!

like image 740
Yaobin Then Avatar asked Feb 24 '13 16:02

Yaobin Then


People also ask

What is Haar cascade classifier?

Haar Cascade Classifiers : We will implement our use case using the Haar Cascade classifier. Haar Cascade classifier is an effective object detection approach which was proposed by Paul Viola and Michael Jones in their paper, “ Rapid Object Detection using a Boosted Cascade of Simple Features ” in 2001.

What is Haar Cascade image object detection in OpenCV?

If you are familiar with OpenCV library, you know what Haar Cascade image object detection is. By image object detection I mean, like human face detection or something else. I have some Haar Cascade XMLs for face detection, but I don't know how to create my own.

What is a cascade classifier in AI?

Cascade Classifier Architecture A cascade classifier refers to the concatenation of several classifiers arranged in successive order. It makes large numbers of small decisions as to whether its the object or not. The structure of the cascade classifier is of a degenerate decision tree.

Where can Haar Cascades be applied?

Because of the versatility of Haar cascades, they can be applied virtually anywhere. Haar cascades are machine learning object detection algorithms. They use use Haar features to determine the likelihood of a certain point being part of an object.


1 Answers

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.
like image 76
Yaobin Then Avatar answered Oct 14 '22 20:10

Yaobin Then