public void ParseTest()
{
StringReader stringReader = new StringReader(Properties.Resources.haarcascade_frontalface_alt);
HaarCascade cascade1 = HaarCascade.FromXml(stringReader);
Assert.AreEqual(22, cascade1.Stages.Length);
Assert.AreEqual(3, cascade1.Stages[0].Trees.Length);
Assert.AreEqual(1, cascade1.Stages[0].Trees[0].Length);
Assert.AreEqual(false, cascade1.HasTiltedFeatures);
// Load the hard coded version of the classifier
HaarCascade cascade2 = new FaceHaarCascade();
Assert.AreEqual(cascade1.Stages.Length, cascade2.Stages.Length);
Assert.AreEqual(cascade1.Height, cascade2.Height);
Assert.AreEqual(cascade1.Width, cascade2.Width);
for (int i = 0; i < 3; i++)
{
HaarCascadeStage stage1 = cascade1.Stages[i];
HaarCascadeStage stage2 = cascade2.Stages[i];
//Assert.AreEqual(stage1.NextIndex, stage2.NextIndex);
//Assert.AreEqual(stage1.ParentIndex, stage2.ParentIndex);
Assert.AreEqual(stage1.Threshold, stage2.Threshold);
Assert.AreEqual(stage1.Trees.Length, stage2.Trees.Length);
for (int j = 0; j < stage1.Trees.Length && j < stage2.Trees.Length; j++)
{
HaarFeatureNode[] tree1 = stage1.Trees[j];
HaarFeatureNode[] tree2 = stage2.Trees[j];
Assert.AreEqual(tree1.Length, tree2.Length);
for (int k = 0; k < tree1.Length; k++)
{
HaarFeatureNode node1 = tree1[k];
HaarFeatureNode node2 = tree2[k];
Assert.AreEqual(node1.LeftNodeIndex, node2.LeftNodeIndex);
Assert.AreEqual(node1.RightNodeIndex, node2.RightNodeIndex);
Assert.AreEqual(node1.LeftValue, node2.LeftValue);
Assert.AreEqual(node1.RightValue, node2.RightValue);
Assert.AreEqual(node1.Feature.Tilted, node2.Feature.Tilted);
Assert.AreEqual(node1.Threshold, node2.Threshold, 0.000000001);
}
}
}
}