Beispiel #1
0
 public void addTree(Tree t)
 {
     trees.Add(t);
 }
Beispiel #2
0
        /** Detector constructor.
         * Builds, from a XML file, the corresponding Haar cascade.
         * @param filename The XML file (generated by OpenCV) describing the Haar cascade.
         */
        public Detector(String filename)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(filename);
            stages = new List<Stage>();

            XmlNode racine = doc.FirstChild.FirstChild;
            string[] dementions = racine["size"].InnerText.Split(' ');
            size = new Point(int.Parse(dementions[0]), int.Parse(dementions[1]));
            XmlNodeList it = racine["stages"].ChildNodes;
            foreach(XmlNode stage in it)
            {
                float thres = float.Parse(stage["stage_threshold"].InnerText, CultureInfo.InvariantCulture);
                //System.out.println(thres);
                XmlNodeList it2 = stage["trees"].ChildNodes;
                Stage st = new Stage(thres);
                foreach (XmlNode tree in it2)
                {
                    Tree t = new Tree();
                    XmlNodeList it4 = tree.ChildNodes;
                    foreach (XmlNode feature in it4)
                    {
                        float thres2 = float.Parse(feature["threshold"].InnerText, CultureInfo.InvariantCulture);
                        int left_node = -1;
                        float left_val = 0;
                        bool has_left_val = false;
                        int right_node = -1;
                        float right_val = 0;
                        bool has_right_val = false;
                        XmlNode e = feature["left_val"];
                        if (e != null)
                        {
                            left_val = float.Parse(e.InnerText, CultureInfo.InvariantCulture);
                            has_left_val = true;
                        }
                        else
                        {
                            left_node = int.Parse(feature["left_node"].InnerText);
                            has_left_val = false;
                        }
                        e = feature["right_val"];
                        if (e != null)
                        {
                            right_val = float.Parse(e.InnerText, CultureInfo.InvariantCulture);
                            has_right_val = true;
                        }
                        else
                        {
                            right_node = int.Parse(feature["right_node"].InnerText);
                            has_right_val = false;
                        }
                        Feature f = new Feature(thres2, left_val, left_node, has_left_val, right_val, right_node, has_right_val, size);
                        XmlNodeList it3 = feature["feature"]["rects"].ChildNodes;
                        foreach (XmlNode node in it3)
                        {
                            string s = node.InnerText.Trim();
                            //System.out.println(s);
                            Rectangle r = Rectangle.fromString(s);
                            f.add(r);
                        }

                        t.addFeature(f);
                    }
                    st.addTree(t);
                    //System.out.println("Number of nodes in tree "+t.features.size());
                }
                //System.out.println("Number of trees : "+ st.trees.size());
                stages.Add(st);
            }

            //System.out.println(stages.size());
        }