Exemple #1
0
        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();
        }
Exemple #2
0
        /// <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);
            }
        }
Exemple #3
0
 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));
 }
Exemple #4
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()
        {
            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);
        }
Exemple #5
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()
        {
            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);
        }