/// <summary>
        /// Создание экземпляра класса <see cref="DefaultFragmentAnalyzer"/>.
        /// </summary>
        public DefaultFragmentAnalyzer(EulerContainer container, IEulerComparer comparer)
        {
            _comparer      = comparer;
            _minimalHeight =
                container.Languages.SelectMany(
                    language => language.Chars.SelectMany(chr => chr.Codes.Select(code => code.Height))).Min();

            var allSymbols = container.Languages.SelectMany(language => language.Chars).ToList();

            _knownSymbols = new ReadOnlyCollection <Symbol>(allSymbols);
        }
Beispiel #2
0
        public void ActualDataSerializationTest()
        {
            var language = new Language
            {
                LocalizationName = "RU-ru",
                FontFamilyNames  = new List <string>()
                {
                    "SomeFont"
                },
                Chars = new List <Symbol>
                {
                    new Symbol
                    {
                        Chr   = 'Б',
                        Codes = new HashSet <SymbolCode>(
                            new[]
                        {
                            new SymbolCode(10, new EulerMonomap2D(EulerValue))
                        })
                    }
                }
            };

            var eulerContainer = new EulerContainer()
            {
                Languages = new List <Language>()
                {
                    language
                },
                SpecialChars = new List <Symbol>()
                {
                    new Symbol()
                    {
                        Chr = 'Ж'
                    }
                }
            };

            using (var compressed = CompressionUtils.Compress(eulerContainer))
            {
                CompressionUtils.Decompress <EulerContainer>(compressed);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Создание экземпляра класса <see cref="TextRecognizer"/>.
        /// </summary>
        public TextRecognizer(
            IApproximator approximator,
            EulerContainer container,
            IFragmentAnalyzer analyzer,
            IScanner scanner)
        {
            if (approximator == null)
            {
                throw new ArgumentNullException(nameof(approximator));
            }

            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            _approximator = approximator;
            _analyzer     = analyzer ?? new DefaultFragmentAnalyzer(container);
            _scanner      = scanner ?? new DefaultScanner();
        }
Beispiel #4
0
 /// <summary>
 /// Создание экземпляра класса <see cref="TextRecognizer"/>.
 /// </summary>
 public TextRecognizer(EulerContainer container, IApproximator approximator)
     : this(approximator, container, null, null)
 {
 }
Beispiel #5
0
 /// <summary>
 /// Создание экземпляра класса <see cref="TextRecognizer"/>.
 /// </summary>
 public TextRecognizer(EulerContainer container)
     : this(new LuminosityApproximator(), container, null, null)
 {
 }
        private async void OnStartClick(object sender, RoutedEventArgs e)
        {
            const string DefaultDictionaries = "../../Qocr.Dics";

            if (!Directory.Exists(DefaultDictionaries))
            {
                MessageBox.Show("Check \"Qocr.Dics\" Folder existence");
                return;
            }

            this.IsEnabled  = false;
            _genImageNumber = 0;

            if (IsPrintDebug.IsChecked.GetValueOrDefault())
            {
                RecreateTestDir();
            }

            DateTime dNow = DateTime.Now;

            var container    = new EulerContainer();
            var fontFamilies = GetFileFonts().ToArray();

            if (IsPrintDebug.IsChecked.GetValueOrDefault())
            {
                _generator.BitmapCreated += GeneratorOnBitmapCreated;
            }

            var lang = await GenerateLanguage(
                SelectedLanguage.Name,
                int.Parse(SelectedLanguage.MinFont),
                int.Parse(SelectedLanguage.MaxFont),
                SelectedLanguage.MinChar,
                SelectedLanguage.MaxChar,
                fontFamilies);

            var specialChars = new[]
            {
                '0',
                '1',
                '2',
                '3',
                '4',
                '5',
                '6',
                '7',
                '8',
                '9',
                '@',
                '$',
                '#',
                '&',
                '(',
                ')',
                '*',
                '/',
                '\\'
            };

            var specialCharsResult = await _generator.GenerateSpecialChars(
                specialChars,
                int.Parse(SelectedLanguage.MinFont),
                int.Parse(SelectedLanguage.MaxFont),
                fontFamilies);

            lang.FontFamilyNames = fontFamilies.Select(font => font.Name).ToList();

            container.Languages.Add(lang);
            container.SpecialChars = specialCharsResult;

            var compression = CompressionUtils.Compress(container);

            using (FileStream fileStream = new FileStream(Path.Combine(DefaultDictionaries, $"{SelectedLanguage.Name}.bin"), FileMode.Create))
            {
                compression.Position = 0;
                compression.CopyTo(fileStream);
            }

            MessageBox.Show($"Время создания {DateTime.Now - dNow}");
            IsEnabled = true;
        }
 /// <summary>
 /// Создание экземпляра класса <see cref="DefaultFragmentAnalyzer"/>.
 /// </summary>
 public DefaultFragmentAnalyzer(EulerContainer container)
     : this(container, new DefaultEulerComparer())
 {
 }