示例#1
0
        public static Bitmap[][] GetLetters(Bitmap source, Rectangle textRec, Size letterSize, Size letterBorder)
        {
            int rows = (textRec.Height - letterSize.Height) / (letterSize.Height + letterBorder.Height) + 1;
            int cols = (textRec.Width - letterSize.Width) / (letterSize.Width - letterBorder.Width) + 1;

            Bitmap[][] bitmaps = new Bitmap[rows][];

            int xIndex = 0;
            int yIndex = 0;

            for (int y = 0; y + letterSize.Height <= textRec.Height; y += letterSize.Height + letterBorder.Height)
            {
                bitmaps[yIndex] = new Bitmap[cols];
                xIndex          = 0;

                for (int x = 0; x + letterSize.Width <= textRec.Width; x += letterSize.Width + letterBorder.Width)
                {
                    bitmaps[yIndex][xIndex] = OutputOCR.CropImage(source, new Rectangle(x, y, letterSize.Width, letterSize.Height));
                    xIndex++;
                }
                yIndex++;
            }

            return(bitmaps);
        }
示例#2
0
        private void pbImage_MouseDown(object sender, MouseEventArgs e)
        {
            Bitmap bm = new Bitmap(pbImage.Image);

            nudPixelX.Value   = e.X;
            nudPixelY.Value   = e.Y;
            plColor.BackColor = bm.GetPixel(e.X, e.Y);
            pbPreview.Image   = OutputOCR.CropImage(bm, new Rectangle(e.X - 11, e.Y - 11, 21, 21));

            PreviewColorDif();
        }
示例#3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Rectangle textRec      = new Rectangle((int)nudImageX.Value, (int)nudImageY.Value, (int)nudImageWidth.Value, (int)nudImageHeight.Value);
            Size      letterSize   = new Size((int)nudLetterWidth.Value, (int)nudLetterHeight.Value);
            Size      letterBorder = new Size((int)nudLetterBorderX.Value, (int)nudLetterBorderY.Value);

            OutputOCR = new OutputOCR(textRec, cbImageEditGray.Checked,
                                      (float)nudImageEditContrast.Value, (int)nudImageEditSizeFactor.Value,
                                      cbLetterSpacingActive.Checked, letterSize, letterBorder);

            DialogResult = DialogResult.OK;
        }
示例#4
0
文件: Macro.cs 项目: nordie92/Makru
        private Output ReadJSONOutput(dynamic json)
        {
            if (json.Count == 0)
            {
                return(null);
            }

            Output returnOutput = null;

            switch ((string)json.type)
            {
            case "outputOCR":
                Rectangle textRec      = new Rectangle((int)json.x, (int)json.y, (int)json.width, (int)json.height);
                Size      letterSize   = new Size((int)json.letterWidth, (int)json.letterHeight);
                Size      letterBorder = new Size((int)json.letterBorderX, (int)json.letterBorderY);
                returnOutput = new OutputOCR(textRec, (bool)json.grayscale, (float)json.contrast, (int)json.scale, (bool)json.letterSpacingActive, letterSize, letterBorder);
                break;

            case "outputStaticText":
                returnOutput = new OutputStaticText((string)json.value);
                break;

            case "outputAddition":
                returnOutput = new OutputAddition(ReadJSONOutput(json.output1), ReadJSONOutput(json.output2), this);
                break;

            case "outputSubstract":
                returnOutput = new OutputSubstract(ReadJSONOutput(json.output1), ReadJSONOutput(json.output2), this);
                break;

            case "outputMultiply":
                returnOutput = new OutputMultiply(ReadJSONOutput(json.output1), ReadJSONOutput(json.output2), this);
                break;

            case "outputDivide":
                returnOutput = new OutputDivide(ReadJSONOutput(json.output1), ReadJSONOutput(json.output2), this);
                break;

            case "outputVariable":
                returnOutput = new OutputVariable((string)json.name, this);
                break;
            }

            return(returnOutput);
        }
示例#5
0
        public FormOCRHelper(OutputOCR conditionOCR)
        {
            InitializeComponent();

            OutputOCR = conditionOCR;

            nudImageX.Value              = OutputOCR.TextRectangle.X;
            nudImageY.Value              = OutputOCR.TextRectangle.Y;
            nudImageWidth.Value          = Math.Max(1, OutputOCR.TextRectangle.Width);
            nudImageHeight.Value         = Math.Max(1, OutputOCR.TextRectangle.Height);
            cbImageEditGray2.Checked     = OutputOCR.TextGray;
            nudImageEditContrast.Value   = (decimal)OutputOCR.TextContrast;
            nudImageEditSizeFactor.Value = Math.Max(1, OutputOCR.TextScale);
            rbLettersActive.Checked      = OutputOCR.LetterSpacingActive;
            rbLettersDeavtive.Checked    = !OutputOCR.LetterSpacingActive;
            nudLetterWidth.Value         = Math.Max(1, OutputOCR.LetterSize.Width);
            nudLetterHeight.Value        = Math.Max(1, OutputOCR.LetterSize.Height);
            nudLetterBorderX.Value       = OutputOCR.LetterBorder.Width;
            nudLetterBorderY.Value       = OutputOCR.LetterBorder.Height;
        }
示例#6
0
        private void llOCRHelper_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FormOCRHelper frm = new FormOCRHelper(OutputOCR);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                OutputOCR = frm.OutputOCR;

                nudImageX.Value               = OutputOCR.TextRectangle.X;
                nudImageY.Value               = OutputOCR.TextRectangle.Y;
                nudImageWidth.Value           = OutputOCR.TextRectangle.Width;
                nudImageHeight.Value          = OutputOCR.TextRectangle.Height;
                cbImageEditGray.Checked       = OutputOCR.TextGray;
                nudImageEditContrast.Value    = (decimal)OutputOCR.TextContrast;
                nudImageEditSizeFactor.Value  = OutputOCR.TextScale;
                cbLetterSpacingActive.Checked = OutputOCR.LetterSpacingActive;
                nudLetterWidth.Value          = OutputOCR.LetterSize.Width;
                nudLetterHeight.Value         = OutputOCR.LetterSize.Height;
                nudLetterBorderX.Value        = OutputOCR.LetterBorder.Width;
                nudLetterBorderY.Value        = OutputOCR.LetterBorder.Height;
            }
        }
示例#7
0
        public FormOCR(OutputOCR ocr)
        {
            InitializeComponent();

            m_ocr = new TesseractEngine("./tessdata", "eng", EngineMode.TesseractAndCube);
            m_ocr.SetVariable("tessedit_char_whitelist", "0123456789");

            OutputOCR = ocr;

            nudImageX.Value               = ocr.TextRectangle.X;
            nudImageY.Value               = ocr.TextRectangle.Y;
            nudImageWidth.Value           = Math.Max(ocr.TextRectangle.Width, 1);
            nudImageHeight.Value          = Math.Max(ocr.TextRectangle.Height, 1);
            cbImageEditGray.Checked       = ocr.TextGray;
            nudImageEditContrast.Value    = (decimal)ocr.TextContrast;
            nudImageEditSizeFactor.Value  = Math.Max(ocr.TextScale, 4);
            cbLetterSpacingActive.Checked = ocr.LetterSpacingActive;
            nudLetterWidth.Value          = Math.Max(ocr.LetterSize.Width, 1);
            nudLetterHeight.Value         = Math.Max(ocr.LetterSize.Height, 1);
            nudLetterBorderX.Value        = ocr.LetterBorder.Width;
            nudLetterBorderY.Value        = ocr.LetterBorder.Height;
        }