示例#1
0
        public HaarCascade(int baseWidth, int baseHeight, HaarCascadeStage[] stages)
        {
            Width = baseWidth;
            Height = baseHeight;
            Stages = stages;

            HasTiltedFeatures = checkTiltedFeatures(stages);
        }
 public HaarClassifier(int baseWidth, int baseHeight, HaarCascadeStage[] stages)
     : this(new HaarCascade(baseWidth, baseHeight, stages))
 {
 }
示例#3
0
        public object Clone()
        {
            HaarCascadeStage[] newStages = new HaarCascadeStage[Stages.Length];
            for (int i = 0; i < newStages.Length; i++)
                newStages[i] = (HaarCascadeStage)Stages[i].Clone();

            HaarCascade r = new HaarCascade(Width, Height);
            r.HasTiltedFeatures = this.HasTiltedFeatures;
            r.Stages = newStages;

            return r;
        }
示例#4
0
 private static bool checkTiltedFeatures(HaarCascadeStage[] stages)
 {
     foreach (var stage in stages)
         foreach (var tree in stage.Trees)
             foreach (var node in tree)
                 if (node.Feature.Tilted == true)
                     return true;
     return false;
 }
        private void writeStage(int i, HaarCascadeStage stage)
        {
            writer.WriteLine("            #region Stage {0}", i);
            writer.WriteLine("            stage = new HaarCascadeStage({0}, {1}, {2}); nodes = new List<HaarFeatureNode[]>();",
                stage.Threshold.ToString("R", NumberFormatInfo.InvariantInfo),
                stage.ParentIndex, stage.NextIndex);

            // Write stage trees
            for (int j = 0; j < stage.Trees.Length; j++)
                writeTrees(stage, j);

            writer.WriteLine("            stage.Trees = nodes.ToArray(); stages.Add(stage);");
            writer.WriteLine("            #endregion");
            writer.WriteLine();
        }
        private void writeTrees(HaarCascadeStage stage, int j)
        {
            writer.Write("            nodes.Add(new[] { ");

            // Assume trees have single node
            writeFeature(stage.Trees[j][0]);

            writer.WriteLine(" });");
        }
        public object Clone()
        {
            HaarFeatureNode[][] newTrees = new HaarFeatureNode[Trees.Length][];

            for (int i = 0; i < newTrees.Length; i++)
            {
                HaarFeatureNode[] tree = Trees[i];
                HaarFeatureNode[] newTree = newTrees[i] =
                    new HaarFeatureNode[tree.Length];

                for (int j = 0; j < newTree.Length; j++)
                    newTree[j] = (HaarFeatureNode)tree[j].Clone();
            }

            HaarCascadeStage r = new HaarCascadeStage();
            r.NextIndex = NextIndex;
            r.ParentIndex = ParentIndex;
            r.Threshold = Threshold;
            r.Trees = newTrees;

            return r;
        }