Exemplo n.º 1
0
        private void UpdateSize()
        {
            var oldRows    = _pixels.GetLength(0);
            var oldColumns = _pixels.GetLength(1);

            var newPixels = new Pixel[_rows, _columns];

            for (int i = 0; i < _rows; ++i)
            {
                for (int j = 0; j < _columns; ++j)
                {
                    if (i < oldRows && j < oldColumns)
                    {
                        newPixels[i, j] = _pixels[i, j];
                    }
                    else
                    {
                        newPixels[i, j] = new Pixel();
                    }
                }
            }

            _pixels = newPixels;
            Pixels  = _pixels.Cast <Pixel>().ToArray();
        }
Exemplo n.º 2
0
        public bool IsPresenceDetected()
        {
            var redPixels          = _pixels.Cast <Pixel>().Count(IsRedPixel);
            var isPresenceDetected = redPixels > 350;

            //Console.WriteLine(isPresenceDetected ? "Presence detected, Number of red pixels: " + redPixels : "No presence detected, Number of red pixels: " + redPixels);
            Console.WriteLine(isPresenceDetected ? "Presence detected" : "No presence detected");
            return(isPresenceDetected);
        }
Exemplo n.º 3
0
        protected override Pixel ProcessMatrix(Pixel[,] matrix, int height, int width)
        {
            Pixel[] flatMatrix = matrix.Cast <Pixel>().ToArray();
            int[]   reds       = flatMatrix.Select(pixel => pixel.Red).ToArray();
            int[]   greens     = flatMatrix.Select(pixel => pixel.Green).ToArray();
            int[]   blues      = flatMatrix.Select(pixel => pixel.Blue).ToArray();

            Array.Sort(reds);
            Array.Sort(greens);
            Array.Sort(blues);

            int center = height * width / 2;

            return(new Pixel(reds[center], greens[center], blues[center]));
        }
Exemplo n.º 4
0
        private void Clear()
        {
            var newPixels = new Pixel[_rows, _columns];

            for (int i = 0; i < _rows; ++i)
            {
                for (int j = 0; j < _columns; ++j)
                {
                    newPixels[i, j] = new Pixel();
                }
            }

            _pixels = newPixels;
            Pixels  = _pixels.Cast <Pixel>().ToArray();
        }