Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In the source code of OpenCV, you will find <code>cvhaar.cpp</code> that gives some insight into how Haar cascade works. Unfortunately, this is essentially no commentary, nor does the documentation help much. Here's my understanding of how it works.</p> <p>In the function <code>icvEvalHidHaarClassifier()</code>, the sum is computed for the the features of a single <code>CvHidHaarTreeNode</code>.</p> <p>If this sum is less than the threshold, the "left" node is followed, and the process is repeated. Otherwise, the "right" node is followed, again repeating. This is reflected by the following statement:</p> <pre><code>idx = sum &lt; t ? node-&gt;left : node-&gt;right; </code></pre> <p>The loop is broken when the "left" or "right" node is a negative value. In this case, the sum is no longer computed for this feature, but the threshold value for that feature is returned as the result of the classifier.</p> <p>I put "left" and "right" in quotes because, as you say, they have nothing to do with the feature position. Instead, they reflect which way the cascade "falls": below the threshold, the cascade falls <em>left</em>, above the threshold, it falls <em>right</em>.</p> <p>Let us now step back to the representation of these nodes. In the XML, you will see the representation of the nodes not as indexes, but as values:</p> <pre><code>&lt;left_val&gt;0.0337941907346249&lt;/left_val&gt; &lt;right_val&gt;0.8378106951713562&lt;/right_val&gt; </code></pre> <p>These numbers are in fact node <em>names</em> that are looked up using <code>cvGetFileNodeByName()</code>. I don't know exactly how this works inside OpenCV, but now I hope you at least have a better idea how the cascade works.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload