In the OpenCV source code, you will find cvhaar.cpp , which gives some insight into how the Haar cascade works. Unfortunately, this is essentially not a comment, and the documentation does not help. Here is my understanding of how this works.
In the icvEvalHidHaarClassifier() function, the sum is calculated for functions of one CvHidHaarTreeNode .
If this amount is less than the threshold, you should follow the "left" node, and the process repeats. Otherwise, the "right" node is executed, repeating itself again. This is reflected in the following statement:
idx = sum < t ? node->left : node->right;
The loop is interrupted when the "left" or "right" node is a negative value. In this case, the sum is no longer calculated for this function, but the threshold value for this function is returned as a result of the classifier.
I put “left” and “right” in quotation marks because, as you say, they have nothing to do with the position of the function. Instead, they reflect how the cascade “falls”: below the threshold, the cascade falls to the left, above the threshold it falls.
Let us return to the presentation of these nodes. In XML, you will see the representation of nodes not as indexes, but as values:
<left_val>0.0337941907346249</left_val> <right_val>0.8378106951713562</right_val>
These numbers are actually node names that are looked up with cvGetFileNodeByName() . I don’t know exactly how this works in OpenCV, but now I hope you at least better understand how the cascade works.
Paul lammertsma
source share