Example #1
0
        private void showMatch()
        {
            ArkOCR.letterMatch(ocrLetterEditRecognized.LetterArray, ocrLetterEditTemplate.LetterArray, out float match, out int offset);
            ocrLetterEditTemplate.recognizedOffset = offset;

            labelMatching.Text = $"matching: {Math.Round(match * 100, 1)} %";
        }
Example #2
0
        /// <summary>
        /// Redraws the screenshot
        /// </summary>
        /// <param name="hightlightIndex">which of the labels should be highlighted</param>
        /// <param name="showLabels">show labels</param>
        /// <param name="whiteThreshold">preview of white-Threshold. -1 to disable</param>
        private void RedrawScreenshot(int hightlightIndex, bool showLabels = true, int whiteThreshold = -1)
        {
            if (OCRDebugLayoutPanel.Controls.Count <= 0 ||
                !(OCRDebugLayoutPanel.Controls[OCRDebugLayoutPanel.Controls.Count - 1] is PictureBox) ||
                _screenshot == null)
            {
                return;
            }

            PictureBox p = (PictureBox)OCRDebugLayoutPanel.Controls[OCRDebugLayoutPanel.Controls.Count - 1];
            Bitmap     b = new Bitmap((whiteThreshold >= 0 ? ArkOCR.removePixelsUnderThreshold(ArkOCR.GetGreyScale(_screenshot), whiteThreshold, true) : _screenshot));

            using (Graphics g = Graphics.FromImage(b))
            {
                if (showLabels)
                {
                    using (Pen penW = new Pen(Color.White, 2))
                        using (Pen penY = new Pen(Color.Yellow, 2))
                            using (Pen penB = new Pen(Color.Black, 2))
                            {
                                penW.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
                                penY.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
                                penB.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
                                for (int r = 0; r < ArkOCR.OCR.ocrConfig.labelRectangles.Count; r++)
                                {
                                    Rectangle rec = ArkOCR.OCR.ocrConfig.labelRectangles[r];
                                    if (r == hightlightIndex)
                                    {
                                        rec.Inflate(2, 2);
                                        g.DrawRectangle(penY, rec);
                                        rec.Inflate(2, 2);
                                        g.DrawRectangle(penB, rec);
                                    }
                                    else
                                    {
                                        rec.Inflate(2, 2);
                                        g.DrawRectangle(penW, rec);
                                        rec.Inflate(2, 2);
                                        g.DrawRectangle(penB, rec);
                                    }
                                }
                            }
                }
            }
            Bitmap disp = (Bitmap)p.Image; // take pointer to old image to dispose it soon

            p.Image = b;
            if (disp != null && disp != _screenshot)
            {
                disp.Dispose();
            }
        }