Haar classifier
Hello,
I works on weak classifier and i try to understand the implementation on OpenCV:
template<class feval=""> inline int predictOrdered( CascadeClassifierImpl& cascade, Ptr<featureevaluator> &_featureEvaluator, double& sum ) { int nstages = (int)cascade.data.stages.size(); int nodeOfs = 0, leafOfs = 0; FEval& featureEvaluator = (FEval&)_featureEvaluator; float cascadeLeaves = &cascade.data.leaves[0]; CascadeClassifierImpl::Data::DTreeNode* cascadeNodes = &cascade.data.nodes[0]; CascadeClassifierImpl::Data::DTree* cascadeWeaks = &cascade.data.classifiers[0]; CascadeClassifierImpl::Data::Stage* cascadeStages = &cascade.data.stages[0];
for( int si = 0; si < nstages; si++ )
{
CascadeClassifierImpl::Data::Stage& stage = cascadeStages[si];
int wi, ntrees = stage.ntrees;
sum = 0;
for( wi = 0; wi < ntrees; wi++ )
{
CascadeClassifierImpl::Data::DTree& weak = cascadeWeaks[stage.first + wi];
int idx = 0, root = nodeOfs;
do
{
CascadeClassifierImpl::Data::DTreeNode& node = cascadeNodes[root + idx];
double val = featureEvaluator(node.featureIdx);
idx = val < node.threshold ? node.left : node.right;
}
while( idx > 0 );
sum += cascadeLeaves[leafOfs - idx];
nodeOfs += weak.nodeCount;
leafOfs += weak.nodeCount + 1;
}
if( sum < stage.threshold )
return -si;
}
return 1;
}
Here is haar implémentation for facedetection. For what i understand, there are trees which contain nodes. A node is a part of a kernel which is apply to the image. A kernel ( a list of node ) is contained in a tree. In the previous code the program read all the trees and apply the node to the image. I don't understand why there are left and right part of the node? I try to find the explaination of this algorithm can't someone help me?
Left and right part of each node means you are using binary decision trees. Chapter 5 of OpenCV Blueprints discusses this in quite some detail, maybe you should read it?