示例#1
0
        /// <summary>
        ///   Gets the sum of the areas of the rectangular features in an integral image.
        /// </summary>
        ///
        public double GetSum(SIntegralImage image, int x, int y)
        {
            double sum = 0.0;

            if (!Tilted)
            {
                // Compute the sum for a standard feature
                foreach (HaarRectangle rect in Rectangles)
                {
                    sum += image.GetSum(x + rect.ScaledX, y + rect.ScaledY,
                                        rect.ScaledWidth, rect.ScaledHeight) * rect.ScaledWeight;
                }
            }
            else
            {
                // Compute the sum for a rotated feature
                foreach (HaarRectangle rect in Rectangles)
                {
                    sum += image.GetSumT(x + rect.ScaledX, y + rect.ScaledY,
                                         rect.ScaledWidth, rect.ScaledHeight) * rect.ScaledWeight;
                }
            }

            return(sum);
        }
示例#2
0
        /// <summary>
        ///   Detects the presence of an object in a given window.
        /// </summary>
        ///
        public bool Compute(SIntegralImage image, Rectangle rectangle)
        {
            int x = rectangle.X;
            int y = rectangle.Y;
            int w = rectangle.Width;
            int h = rectangle.Height;

            double mean   = image.GetSum(x, y, w, h) * invArea;
            double factor = image.GetSum2(x, y, w, h) * invArea - (mean * mean);

            factor = (factor >= 0) ? Math.Sqrt(factor) : 1;


            // For each classification stage in the cascade
            foreach (HaarCascadeStage stage in cascade.Stages)
            {
                // Check if the stage has rejected the image
                if (stage.Classify(image, x, y, factor) == false)
                {
                    return(false); // The image has been rejected.
                }
            }

            // If the object has gone all stages and has not
            //  been rejected, the object has been detected.

            return(true); // The image has been detected.
        }