Beispiel #1
0
        public void SetPixel_SetsPixelCorrectly(int x, int y, int blue, int green, int red)
        {
            BgrPixel pixel = new BgrPixel(blue, green, red);

            this.bgrImage.SetPixel(pixel, x, y);
            Assert.True(this.BgrEqualsBgrPixel(this.emguImage[y, x], pixel));
        }
Beispiel #2
0
        public void RedGetter_ConstructedFromColor_ReturnsCorrectRedValue(int blue, int green, int red)
        {
            Color    color    = Color.FromArgb(red, green, blue);
            BgrPixel bgrPixel = new BgrPixel(color);

            Assert.Equal(bgrPixel.Red, red);
        }
        private bool IsBackground(BgrPixel pixel, int x, int y)
        {
            BgrPixel backgroundReferencePixel = this.tuning.HandsBackground.GetPixel(x, y);

            double deltaBlue  = Math.Abs(backgroundReferencePixel.Blue - pixel.Blue);
            double deltaGreen = Math.Abs(backgroundReferencePixel.Green - pixel.Green);
            double deltaRed   = Math.Abs(backgroundReferencePixel.Red - pixel.Red);

            return(deltaBlue <= BACKGROUND_PIXEL_TOLERANCE && deltaGreen <= BACKGROUND_PIXEL_TOLERANCE && deltaRed <= BACKGROUND_PIXEL_TOLERANCE);
        }
Beispiel #4
0
        private ColorMap ExtractColorMap(BgrImage image, List <Point> poi)
        {
            IHistogram blues  = new Histogram(0, 255, 64);
            IHistogram greens = new Histogram(0, 255, 64);
            IHistogram reds   = new Histogram(0, 255, 64);

            foreach (Point point in poi)
            {
                BgrPixel pixel = image.GetPixel(point.X, point.Y);

                blues.Insert(pixel.Blue);
                greens.Insert(pixel.Green);
                reds.Insert(pixel.Red);
            }

            return(new ColorMap(blues, greens, reds));
        }
        private NormalizedHand EvaluatePixels(BgrImage image, int startX, int width, ColorMap colorMap, NormalizedHand neutralHand)
        {
            HandBuilder handBuilder = new HandBuilder();

            for (int y = 0; y < image.Height; y++)
            {
                for (int x = startX; x < startX + width; x++)
                {
                    BgrPixel pixel = image.GetPixel(x, y);

                    if (this.IsBackground(pixel, x, y))
                    {
                        image.SetPixel(this.backgroundPixel, x, y);
                    }
                    else if (!colorMap.Satisfies(pixel))
                    {
                        image.SetPixel(this.unknownPixel, x, y);
                    }
                    else
                    {
                        image.SetPixel(this.skinPixel, x, y);
                        handBuilder.Append(x, y);
                    }
                }
            }

            NormalizedHand detectedHand = new HandNormalizer(image.Width, image.Height).Normalize(handBuilder.Build());

            if (this.Tuned && neutralHand != null && detectedHand.Weight < neutralHand.Weight / DIVISOR_TO_GET_VALID_HAND_WEIGHT_LOWER_BOUND_FROM_NEUTRAL_HAND_WEIGHT)
            {
                // after tuning the neutral hands are cached
                // if the weight of the hand is under a threshold
                // (which probably means that there is no hand on the image but noise)
                // then we're going to use the cached neutral hand instead of the freshly detected (wrong) one
                detectedHand = new NormalizedHand(neutralHand.X, neutralHand.Y, neutralHand.Weight);
            }

            return(detectedHand);
        }
Beispiel #6
0
        public void Satisfies_GeneralCases_ColorMapSatisfiesBgrPixel(int blue, int green, int red)
        {
            BgrPixel bgrPixel = new BgrPixel(blue, green, red);

            Assert.True(this.colorMap.Satisfies(bgrPixel));
        }
Beispiel #7
0
        public void RedGetter_ConstructedFromColorChannels_ReturnsCorrectRedValue(int blue, int green, int red)
        {
            BgrPixel bgrPixel = new BgrPixel(blue, green, red);

            Assert.Equal(bgrPixel.Red, red);
        }
Beispiel #8
0
 private bool AreBgrPixelsTheSame(BgrPixel a, BgrPixel b) =>
 a.Blue == b.Blue &&
 a.Green == b.Green &&
 a.Red == b.Red;
Beispiel #9
0
 private bool BgrEqualsBgrPixel(Bgr emguPixel, BgrPixel bgrPixel) =>
 emguPixel.Blue == bgrPixel.Blue &&
 emguPixel.Green == bgrPixel.Green &&
 emguPixel.Red == bgrPixel.Red;