/// <summary>
 /// Retourne le poids du classificateur si celui-ci vérifie
 /// la fenêtre, 0 sinon.
 /// </summary>
 public double GetValue(Window Win, IntegralImage Image)
 {
     if (this.Check(Win, Image))
         return this.Alpha;
     else
         return 0;
 }
        /// <summary>
        /// Retourne true si le classificateur vérifie la fenêtre.
        /// </summary>
        public bool Check(Window Win, IntegralImage Image)
        {
            var featureValue = this.Feature.ComputeValue(Win.TopLeft, Win.SizeRatio, Image);
            var sizedValue = (int) (featureValue / (Win.SizeRatio * Win.SizeRatio));
            var normalizedValue	= Features.NormalizeFeature(sizedValue, Win.Deviation);

            return this.Parity * normalizedValue < this.Parity * this.Threshold;
        }
Example #3
0
        public Window(Point TopLeft, float SizeRatio, IntegralImage Image, IntegralImage SquaredImage)
        {
            this.TopLeft = TopLeft;

            this.SizeRatio = SizeRatio;

            this.Deviation = 0;
            this.Deviation = this.GetDeviation(Image, SquaredImage);
        }
Example #4
0
        public TestImage(GreyPixbuf Image, double Weight, bool Valid)
        {
            this.Image = new IntegralImage(Image);

            this.Derivation = this.Image.GetDeviation();

            this.Weight = Weight;
            this.Valid = Valid;
        }
        public int ComputeValue(Point WinTopLeft, float SizeRatio, IntegralImage Image)
        {
            /*
             * a ------- b ------- c
             * -         -         -
             * -   R1    -    R2   -
             * -         -         -
             * d ------- e ------- f
             * -         -         -
             * -   R3    -    R4   -
             * -         -         -
             * g ------- h ------- i
             * S(R1) = e - (b + d) + a
             * S(R2) = f - (c + e) + b
             * S(R3) = h - (e + g) + d
             * S(R4) = i - (f + h) + e
             */

            var scaledFrame = this.Frame.Scale(SizeRatio);
            var topLeft = scaledFrame.TopLeft.NestedPoint(WinTopLeft);
            var rectsWidth = scaledFrame.Width / 2;
            var rectsHeight = scaledFrame.Height / 2;

            var aCoords = topLeft;
            var bCoords = aCoords.Translate(rectsWidth, 0);
            var cCoords = bCoords.Translate(rectsWidth, 0);

            var dCoords = aCoords.Translate(0, rectsHeight);
            var eCoords = dCoords.Translate(rectsWidth, 0);
            var fCoords = eCoords.Translate(rectsWidth, 0);

            var gCoords = dCoords.Translate(0, rectsHeight);
            var hCoords = gCoords.Translate(rectsWidth, 0);
            var iCoords = hCoords.Translate(rectsWidth, 0);

            var a = Image.GetValue(aCoords);
            var b = Image.GetValue(bCoords);
            var c = Image.GetValue(cCoords);
            var d = Image.GetValue(dCoords);
            var e = Image.GetValue(eCoords);
            var f = Image.GetValue(fCoords);
            var g = Image.GetValue(gCoords);
            var h = Image.GetValue(hCoords);
            var i = Image.GetValue(iCoords);

            var sumR1 = e - (b + d) + a;
            var sumR2 = f - (c + e) + b;
            var sumR3 = h - (e + g) + d;
            var sumR4 = i - (f + h) + e;

            return (int) (sumR1 - sumR2 - sumR3 + sumR4);
        }
        public int ComputeValue(Point WinTopLeft, float SizeRatio, IntegralImage Image)
        {
            /*
             * a ------- b
             * -         -
             * -   R1    -
             * -         -
             * c ------- d
             * -         -
             * -   R2    -
             * -         -
             * e ------- f
             * S(R1) = d - (b + c) + a
             * S(R2) = f - (d + e) + c
             */

            var scaledFrame = this.Frame.Scale(SizeRatio);
            var topLeft = scaledFrame.TopLeft.NestedPoint(WinTopLeft);
            var rectsWidth = scaledFrame.Width;
            var rectsHeight = scaledFrame.Height / 2;

            var aCoords = topLeft;
            var bCoords = aCoords.Translate(rectsWidth, 0);

            var cCoords = aCoords.Translate(0, rectsHeight);
            var dCoords = cCoords.Translate(rectsWidth, 0);

            var eCoords = cCoords.Translate(0, rectsHeight);
            var fCoords = eCoords.Translate(rectsWidth, 0);

            var a = Image.GetValue(aCoords);
            var b = Image.GetValue(bCoords);
            var c = Image.GetValue(cCoords);
            var d = Image.GetValue(dCoords);
            var e = Image.GetValue(eCoords);
            var f = Image.GetValue(fCoords);

            var sumR1 = d - (b + c) + a;
            var sumR2 = f - (d + e) + c;

            return (int) (sumR2 - sumR1);
        }
Example #7
0
 public Window(Point TopLeft, IntegralImage Image, IntegralImage SquaredImage)
     : this(TopLeft, 1f, Image, SquaredImage)
 {
 }
Example #8
0
        /// <summary>
        /// Retourne la dispertion de la valeur des pixels
        /// contenus dans la fenêtre/
        /// </summary>
        private int GetDeviation(IntegralImage Image, IntegralImage SquaredImage)
        {
            /*
             * a -------- b
             * -          -
             * -  Window  -
             * -          -
             * c -------- d
             *
             * sum = d - (b + c) + a
             * avg = sum / nPixs
             * deriv = sqrt(sum(pixs²) / nPixs - avg(pixs))
             */

            var nPixs = this.Width * this.Height;

            var aCoords = this.TopLeft;
            var bCoords = aCoords.Translate(this.Width, 0);

            var cCoords = aCoords.Translate(0, this.Height);
            var dCoords = cCoords.Translate(this.Width, 0);

            var a = Image.GetValue(aCoords);
            var b = Image.GetValue(bCoords);
            var c = Image.GetValue(cCoords);
            var d = Image.GetValue(dCoords);

            var squaredA = SquaredImage.GetValue(aCoords);
            var squaredB = SquaredImage.GetValue(bCoords);
            var squaredC = SquaredImage.GetValue(cCoords);
            var squaredD = SquaredImage.GetValue(dCoords);

            var sum = d - (b + c) + a;
            var squaredSum = squaredD - (squaredB + squaredC) + squaredA;

            var avg = sum / nPixs;

            var variance = squaredSum / nPixs - avg*avg;

            // Min 1 to remove division by zero
            if (variance > 0)
                return (int) Math.Sqrt(variance);
            else
                return 1;
        }
Example #9
0
        public static IEnumerable<Window> ListWindows(IntegralImage Image, IntegralImage SquaredImage)
        {
            var maxX = Image.Width - Config.WindowWidth;
            var maxY = Image.Height - Config.WindowHeight;

            for (var x = 0; x <= maxX; x += Config.WindowDX) {
                for (var y = 0; y <= maxY; y += Config.WindowDY) {
                    var maxWidth = Image.Width - x;
                    var maxHeight = Image.Height - y;

                    var width = Config.WindowWidth;
                    var height = Config.WindowHeight;
                    var ratio = 1f;

                    while (width <= maxWidth && height <= maxHeight) {
                        yield return new Window(new Point(x, y), ratio, Image, SquaredImage);

                        ratio *= Config.WindowScale;
                        width = (int) (Config.WindowWidth * ratio);
                        height = (int) (Config.WindowHeight * ratio);
                    }
                }
            }
        }
 public int ComputeValue(IntegralImage Image)
 {
     var topLeft = new Point(0, 0);
     return this.ComputeValue(topLeft, 1f, Image);
 }
        /// <summary>
        /// Retourne true si le classificateur vérifie la fenêtre.
        /// La somme des poids des 
        /// </summary>
        public bool Check(Window Win, IntegralImage Image)
        {
            double sumValues = 0.0;
            foreach (var weakClassifier in this.Classifiers)
                sumValues += weakClassifier.GetValue(Win, Image);

            return sumValues >= this.GlobalAlpha / 2.0;
        }
Example #12
0
 public Detector(IntegralImage Image, IntegralImage SquaredImage, StrongClassifier Classifier)
 {
     this.Image = Image;
     this.SquaredImage = SquaredImage;
     this.Classifier = Classifier;
 }