/// <summary>
        /// Calculates and displays the match between the recognized and template pattern.
        /// </summary>
        private void ShowMatch()
        {
            RecognitionPatterns.PatternMatch(ocrLetterEditTemplate.PatternDisplay.Data, ocrLetterEditRecognized.PatternDisplay?.Data, out float match, out int offset);
            ocrLetterEditTemplate.RecognizedOffset = offset;

            labelMatching.Text = $"matching: {Math.Round(match * 100, 1)} %";
        }
        /// <summary>
        /// Displays all patterns of the selected text. If selectedIndex is -1, the best match will be selected.
        /// </summary>
        /// <param name="selectedIndex"></param>
        private void ListPatternsOfText(int selectedIndex = -1)
        {
            ListBoxPatternsOfString.Items.Clear();

            if (_selectedTextData == null)
            {
                return;
            }
            int patternCount = _selectedTextData.Patterns.Count;

            if (patternCount == 0)
            {
                return;
            }

            var   matches        = new string[patternCount];
            int   bestMatchIndex = 0;
            float bestMatchValue = 0;

            for (int i = 0; i < patternCount; i++)
            {
                RecognitionPatterns.PatternMatch(_selectedTextData.Patterns[i].Data, ocrLetterEditRecognized.PatternDisplay?.Data, out float match, out _);
                matches[i] = $"{Math.Round(match * 100, 1)}";
                if (match > bestMatchValue)
                {
                    bestMatchValue = match;
                    bestMatchIndex = i;
                }
            }
            ListBoxPatternsOfString.Items.AddRange(matches);

            ListBoxPatternsOfString.SelectedIndex = selectedIndex == -1 ? bestMatchIndex : selectedIndex;
        }
Exemple #3
0
        public void InitializeOcrTemplate()
        {
            if (RecognitionPatterns == null)
            {
                RecognitionPatterns = new RecognitionPatterns();
            }
            if (labelRectangles == null)
            {
                labelRectangles = new Rectangle[Enum.GetValues(typeof(OcrLabels)).Length];
            }

            var currentVersion = new Version(CurrentVersion);

            if (Version == null || Version.Major < currentVersion.Major)
            {
                MessageBoxes.ShowMessageBox("The version of this OCR config file is not supported.\nLoad a config file with a supported format.", icon: MessageBoxIcon.Error);
                Version = currentVersion;
            }
            RecognitionPatterns.Save += Save;
        }
Exemple #4
0
        public void InitializeOcrTemplate()
        {
            if (RecognitionPatterns == null)
            {
                RecognitionPatterns = new RecognitionPatterns();
            }
            if (labelRectangles == null)
            {
                labelRectangles = new Rectangle[13];                          // TODO use const
            }
            var currentVersion = new Version(CurrentVersion);

            if (Version == null || Version.Major < currentVersion.Major)
            {
                MessageBoxes.ShowMessageBox("The version of this OCR-config file is not supported.\nThe config data needs to be created again.", icon: MessageBoxIcon.Error);
                Version = currentVersion;
            }
            InitializeLabelNames();
            RecognitionPatterns.Save += Save;
        }