/// <summary> /// Sets the scale and weight of a Haar-like rectangular feature container. /// </summary> /// public void SetScaleAndWeight(float scale, float weight) { // Manual loop unfolding if (Rectangles.Length == 2) { HaarRectangle a = Rectangles[0]; HaarRectangle b = Rectangles[1]; b.ScaleRectangle(scale); b.ScaleWeight(weight); a.ScaleRectangle(scale); a.ScaledWeight = -(b.Area * b.ScaledWeight) / a.Area; } else // rectangles.Length == 3 { HaarRectangle a = Rectangles[0]; HaarRectangle b = Rectangles[1]; HaarRectangle c = Rectangles[2]; c.ScaleRectangle(scale); c.ScaleWeight(weight); b.ScaleRectangle(scale); b.ScaleWeight(weight); a.ScaleRectangle(scale); a.ScaledWeight = -(b.Area * b.ScaledWeight + c.Area * c.ScaledWeight) / (a.Area); } }
void IXmlSerializable.ReadXml(XmlReader reader) { reader.ReadStartElement("feature"); reader.ReadToFollowing("rects"); reader.ReadToFollowing("_"); var rec = new List <HaarRectangle>(); while (reader.Name == "_") { string str = reader.ReadElementContentAsString(); rec.Add(HaarRectangle.Parse(str)); while (reader.Name != "_" && reader.Name != "tilted" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); } } Rectangles = rec.ToArray(); reader.ReadToFollowing("tilted", reader.BaseURI); Tilted = reader.ReadElementContentAsInt() == 1; reader.ReadEndElement(); }
private void writeRectangle(HaarRectangle rectangle) { writer.Write("new int[] {{ {0}, {1}, {2}, {3}, {4} }}", rectangle.X.ToString(NumberFormatInfo.InvariantInfo), rectangle.Y.ToString(NumberFormatInfo.InvariantInfo), rectangle.Width.ToString(NumberFormatInfo.InvariantInfo), rectangle.Height.ToString(NumberFormatInfo.InvariantInfo), rectangle.Weight.ToString("R", NumberFormatInfo.InvariantInfo)); }
/// <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() { HaarRectangle[] newRectangles = new HaarRectangle[this.Rectangles.Length]; for (int i = 0; i < newRectangles.Length; i++) { HaarRectangle rect = Rectangles[i]; newRectangles[i] = new HaarRectangle(rect.X, rect.Y, rect.Width, rect.Height, rect.Weight); } return(new HaarFeature { Rectangles = newRectangles, Tilted = this.Tilted }); }
/// <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() { HaarRectangle r = new HaarRectangle { Height = this.Height, ScaledHeight = this.ScaledHeight, ScaledWeight = this.ScaledWeight, ScaledWidth = this.ScaledWidth, ScaledX = this.ScaledX, ScaledY = this.ScaledY, Weight = this.Weight, Width = this.Width, X = this.X, Y = this.Y }; return(r); }
/// <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() { HaarRectangle[] newRectangles = new HaarRectangle[this.Rectangles.Length]; for (int i = 0; i < newRectangles.Length; i++) { HaarRectangle rect = Rectangles[i]; newRectangles[i] = new HaarRectangle(rect.X, rect.Y, rect.Width, rect.Height, rect.Weight); } return new HaarFeature { Rectangles = newRectangles, Tilted = this.Tilted }; }
/// <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() { HaarRectangle r = new HaarRectangle { Height = this.Height, ScaledHeight = this.ScaledHeight, ScaledWeight = this.ScaledWeight, ScaledWidth = this.ScaledWidth, ScaledX = this.ScaledX, ScaledY = this.ScaledY, Weight = this.Weight, Width = this.Width, X = this.X, Y = this.Y }; return r; }