/// <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(" });"); }
/// <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(); }
/// <summary> /// Constructs a new classifier. /// </summary> /// public HaarClassifier(int baseWidth, int baseHeight, HaarCascadeStage[] stages) : this(new HaarCascade(baseWidth, baseHeight, stages)) { }
/// <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 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(); }
/// <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); }
/// <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; }
/// <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; }