Beispiel #1
0
        /// <summary>
        ///   Creates a new object that is a copy of the current instance.
        /// </summary>
        ///
        /// <returns>
        ///   A new object that is a copy of this instance.
        /// </returns>
        ///
        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);
        }
        private void writeTrees(HaarCascadeStage stage, int j)
        {
            writer.Write("            nodes.Add(new[] { ");

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

            writer.WriteLine(" });");
        }
Beispiel #3
0
        /// <summary>
        ///   Creates a new object that is a copy of the current instance.
        /// </summary>
        ///
        /// <returns>
        ///   A new object that is a copy of this instance.
        /// </returns>
        ///
        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);
        }
        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();
        }
Beispiel #5
0
        private void equals(HaarCascadeStage expected, HaarCascadeStage actual)
        {
            Assert.AreNotEqual(expected, actual);

            Assert.AreEqual(expected.NextIndex, actual.NextIndex);
            Assert.AreEqual(expected.ParentIndex, actual.ParentIndex);
            Assert.AreEqual(expected.Threshold, actual.Threshold);

            Assert.AreNotEqual(expected.Trees, actual.Trees);
            Assert.AreEqual(expected.Trees.Length, actual.Trees.Length);

            for (int i = 0; i < expected.Trees.Length; i++)
            {
                Assert.AreNotEqual(expected.Trees[i], actual.Trees[i]);
                Assert.AreEqual(expected.Trees[i].Length, actual.Trees[i].Length);

                for (int j = 0; j < expected.Trees[i].Length; j++)
                    equals(expected.Trees[i][j], actual.Trees[i][j]);
            }
        }
Beispiel #6
0
        /// <summary>
        ///   Creates a new object that is a copy of the current instance.
        /// </summary>
        /// 
        /// <returns>
        ///   A new object that is a copy of this instance.
        /// </returns>
        /// 
        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;
        }
Beispiel #7
0
 /// <summary>
 ///   Checks if the classifier contains tilted (rotated) features
 /// </summary>
 /// 
 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;
 }
Beispiel #8
0
        /// <summary>
        ///   Constructs a new Haar Cascade.
        /// </summary>
        /// 
        /// <param name="baseWidth">Base feature width.</param>
        /// <param name="baseHeight">Base feature height.</param>
        /// <param name="stages">Haar-like features classification stages.</param>
        /// 
        public HaarCascade(int baseWidth, int baseHeight, HaarCascadeStage[] stages)
        {
            Width = baseWidth;
            Height = baseHeight;
            Stages = stages;

            // check if the classifier has tilted features
            HasTiltedFeatures = checkTiltedFeatures(stages);
        }
Beispiel #9
0
 /// <summary>
 ///   Constructs a new classifier.
 /// </summary>
 /// 
 public HaarClassifier(int baseWidth, int baseHeight, HaarCascadeStage[] stages)
     : this(new HaarCascade(baseWidth, baseHeight, stages)) { }
Beispiel #10
0
        private void writeTrees(HaarCascadeStage stage, int j)
        {
            writer.Write("            nodes.Add(new[] { ");

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

            writer.WriteLine(" });");
        }
Beispiel #11
0
        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();
        }
Beispiel #12
0
        /// <summary>
        ///   Creates a new object that is a copy of the current instance.
        /// </summary>
        /// 
        /// <returns>
        ///   A new object that is a copy of this instance.
        /// </returns>
        /// 
        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;
        }