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(); }
/// <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); } }
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[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); } HaarFeature r = new HaarFeature(); r.Rectangles = newRectangles; r.Tilted = Tilted; 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 r = new HaarRectangle(); r.Height = Height; r.ScaledHeight = ScaledHeight; r.ScaledWeight = ScaledWeight; r.ScaledWidth = ScaledWidth; r.ScaledX = ScaledX; r.ScaledY = ScaledY; r.Weight = Weight; r.Width = Width; r.X = X; r.Y = 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[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); } HaarFeature r = new HaarFeature(); r.Rectangles = newRectangles; r.Tilted = Tilted; return r; }
private void equals(HaarRectangle expected, HaarRectangle actual) { Assert.AreNotEqual(expected, actual); Assert.AreEqual(expected.X, actual.X); Assert.AreEqual(expected.Y, actual.Y); Assert.AreEqual(expected.Weight, actual.Weight); Assert.AreEqual(expected.Width, actual.Width); Assert.AreEqual(expected.Height, actual.Height); }
/// <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(); r.Height = Height; r.ScaledHeight = ScaledHeight; r.ScaledWeight = ScaledWeight; r.ScaledWidth = ScaledWidth; r.ScaledX = ScaledX; r.ScaledY = ScaledY; r.Weight = Weight; r.Width = Width; r.X = X; r.Y = Y; return r; }