コード例 #1
0
        public Rectangle this[RaidImageFragmentType fragmentType]
        {
            get
            {
                switch (fragmentType)
                {
                case RaidImageFragmentType.EggLevel:
                    return(EggLevelPosition);

                case RaidImageFragmentType.EggTimer:
                    return(EggTimerPosition);

                case RaidImageFragmentType.GymName:
                    return(GymNamePosition);

                case RaidImageFragmentType.PokemonName:
                    return(PokemonNamePosition);

                case RaidImageFragmentType.PokemonCp:
                    return(PokemonCpPosition);

                case RaidImageFragmentType.RaidTimer:
                    return(RaidTimerPosition);
                }
                throw new ArgumentException();
            }
        }
コード例 #2
0
        private Image <Rgba32> PreProcessPokemonInfo(Image <Rgba32> imageFragment, RaidImageFragmentType imageFragmentType)
        {
            const byte floodFillLetterTolerance = 10;
            var        floodFillLetters         = new QueueLinearFloodFiller
            {
                Bitmap    = imageFragment,
                FillColor = Rgba32.Black,
                Tolerance =
                {
                    [0] = floodFillLetterTolerance,
                    [1] = floodFillLetterTolerance,
                    [2] = floodFillLetterTolerance
                }
            };
            var borderColor = PokemonNameBorderColor;

            foreach (var encapsulatedPixel in GetEncapsulatedPixels(imageFragment, TextColor, borderColor, 30))
            {
                floodFillLetters.FloodFill(encapsulatedPixel);
            }

            if (SaveDebugImages)
            {
                imageFragment.Save($"_{imageFragmentType}_Step1_FloodFillLetters.png");
            }

            imageFragment.Mutate(m => m.BinaryThreshold(0.01f).Invert());

            if (SaveDebugImages)
            {
                imageFragment.Save($"_{imageFragmentType}_Step2_Binary.png");
            }

            const byte floodFillBorderTolerance = 1;
            var        floodFillBorders         = new QueueLinearFloodFiller
            {
                Bitmap    = imageFragment,
                FillColor = Rgba32.Black,
                Tolerance =
                {
                    [0] = floodFillBorderTolerance,
                    [1] = floodFillBorderTolerance,
                    [2] = floodFillBorderTolerance
                }
            };

            foreach (var point in PixelsWithColorAtBorder(imageFragment, TextColor))
            {
                floodFillBorders.FloodFill(point);
            }

            imageFragment.Mutate(m => m.Invert());

            if (SaveDebugImages)
            {
                imageFragment.Save($"_{imageFragmentType}_Step3_BlackBorderEntriesRemoved.png");
            }

            return(imageFragment);
        }
コード例 #3
0
        public Image <Rgba32> PreProcessTimerFragment(Image <Rgba32> imageFragment, RaidImageFragmentType imageFragmentType)
        {
            imageFragment.Mutate(m => m.Invert().BinaryThreshold(0.1f));
            if (SaveDebugImages)
            {
                imageFragment.Save($"_{imageFragmentType}_Step1_Binary.png");
            }

            return(imageFragment);
        }
コード例 #4
0
ファイル: OcrService.cs プロジェクト: versx/RaidBot
        private async Task <TimeSpan> GetTimerValue(Image <Rgba32> imageFragment, RaidImageFragmentType imageFragmentType)
        {
            imageFragment = _imageConfiguration.PreProcessTimerFragment(imageFragment, imageFragmentType);
            var result = await GetOcrResultAsync(imageFragment);

            if (!string.IsNullOrEmpty(result) && TimeSpan.TryParse(result, out TimeSpan timeSpan))
            {
                return(timeSpan);
            }

            return(Timeout.InfiniteTimeSpan);
        }
コード例 #5
0
        private async Task <OcrResult <TimeSpan> > GetTimerValue(Image <Rgba32> imageFragment, RaidImageConfiguration imageConfiguration, RaidImageFragmentType imageFragmentType)
        {
            imageFragment = imageConfiguration.PreProcessTimerFragment(imageFragment, imageFragmentType);
            var result = await GetOcrResultAsync(imageFragment);

            if (result.Value > 0 && TimeSpan.TryParse(result.Key, out TimeSpan timeSpan))
            {
                return(new OcrResult <TimeSpan>(true, result.Key,
                                                new[] { new KeyValuePair <TimeSpan, double>(timeSpan, result.Value) }));
            }
            return(new OcrResult <TimeSpan>(false, result.Key));
        }
コード例 #6
0
        private async Task <OcrResult <TimeSpan> > GetTimerValue(Image <Rgba32> imageFragment, RaidImageConfiguration imageConfiguration, RaidImageFragmentType imageFragmentType)
        {
            imageFragment = imageConfiguration.PreProcessTimerFragment(imageFragment, imageFragmentType);
            var result = await GetOcrResultAsync(imageFragment);

            // Remove all characters which can not be part of a timespan
            var arr = result.Key.ToCharArray();

            arr = Array.FindAll(arr, (c => (char.IsDigit(c) || c == ':')));
            var stringCleaned = new string(arr);

            if (result.Value > 0 && TimeSpan.TryParse(stringCleaned, out TimeSpan timeSpan))
            {
                return(new OcrResult <TimeSpan>(true, stringCleaned,
                                                new[] { new KeyValuePair <TimeSpan, double>(timeSpan, result.Value) }));
            }
            return(new OcrResult <TimeSpan>(false, result.Key));
        }