Exemplo n.º 1
0
        private unsafe bool FindEyes(out EyeData leftEye, out EyeData rightEye)
        {
            const byte DifferenceThreshold = 25;

            int[,] changeCount = new int[workerImageArray[0].Width, workerImageArray[0].Height];

            for (int i = 0; i < workerImageArray.Length - 1; ++i)
            {
                FastBitmap differenceImage = workerImageArray[i].GetDifferenceImage(workerImageArray[i + 1], DifferenceThreshold);
                FastBitmap erosionImage    = differenceImage.ApplyCrossErosionMask();

                ColorARGB *currentPosition = erosionImage.StartingPosition;
                for (int y = 0; y < erosionImage.Height; ++y)
                {
                    for (int x = 0; x < erosionImage.Width; ++x)
                    {
                        if (currentPosition->B == 255)
                        {
                            ++changeCount[x, y];
                        }
                        ++currentPosition;
                    }
                }
                differenceImage.Dispose();
                erosionImage.Dispose();
            }

            FastBitmap finalDifferenceImage = new FastBitmap(workerImageArray[0].Width, workerImageArray[0].Height);

            ColorARGB *currentPositionResult = finalDifferenceImage.StartingPosition;

            for (int y = 0; y < finalDifferenceImage.Height; ++y)
            {
                for (int x = 0; x < finalDifferenceImage.Width; ++x)
                {
                    byte color = 0;

                    if (changeCount[x, y] > 0)
                    {
                        color = 255;
                    }

                    currentPositionResult->A = 255;
                    currentPositionResult->R = color;
                    currentPositionResult->G = color;
                    currentPositionResult->B = color;

                    ++currentPositionResult;
                }
            }

            return(FindEyesFromDifferenceImage(workerImageArray[workerImageArray.Length - 1], finalDifferenceImage, out leftEye, out rightEye));
        }