상속: ICloneable
예제 #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();
        }
예제 #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);
            }
        }
예제 #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));
 }
예제 #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[] 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);
        }
예제 #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 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);
        }
예제 #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()
        {
            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;
        }
예제 #7
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));
 }
예제 #8
0
 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);
 }
예제 #9
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;
        }