Пример #1
0
        private void buttonOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                Bitmap bmp = new Bitmap(ofd.FileName);
                pictureBoxFilled.Image = bmp;
                pictureBoxInput.Image  = (Bitmap)bmp.Clone();
                List <Color> lst = new List <Color>();
                Color        c;
                for (int x = 2; x < bmp.Width; x++)
                {
                    c = bmp.GetPixel(x, 2);
                    if (!lst.Contains(c))
                    {
                        lst.Add(c);
                    }
                    c = bmp.GetPixel(x, bmp.Height - 3);
                    if (!lst.Contains(c))
                    {
                        lst.Add(c);
                    }
                }
                for (int y = 0; y < bmp.Height; y++)
                {
                    c = bmp.GetPixel(2, y);
                    if (!lst.Contains(c))
                    {
                        lst.Add(c);
                    }
                    c = bmp.GetPixel(31, y);
                    if (!lst.Contains(c))
                    {
                        lst.Add(c);
                    }
                    c = bmp.GetPixel(90, y);
                    if (!lst.Contains(c))
                    {
                        lst.Add(c);
                    }
                    c = bmp.GetPixel(bmp.Width - 3, y);
                    if (!lst.Contains(c))
                    {
                        lst.Add(c);
                    }
                }
                for (int x = 0; x < bmp.Width; x++)
                {
                    for (int y = 0; y < bmp.Height; y++)
                    {
                        c = bmp.GetPixel(x, y);
                        if (lst.Contains(c))
                        {
                            if (c != Color.White)
                            {
                                FloodFill(bmp, x, y, Color.White);
                            }
                        }
                    }
                }

                Ocr ocr = new Ocr();

                //Input
                tessnet2.Tesseract tessocr = new tessnet2.Tesseract();
                tessocr.SetVariable("tessedit_char_whitelist", "0123456789*+-=");
                tessocr.Init(null, "eng", false);
                pictureBoxInputLib.Image = tessocr.GetThresholdedImage((Bitmap)pictureBoxInput.Image, Rectangle.Empty);
                List <tessnet2.Word> text = ocr.DoOCRNormal((Bitmap)pictureBoxInput.Image, "eng");
                textBoxInput.Text = text[0].Text;

                //Filled
                tessocr = new tessnet2.Tesseract();
                tessocr.SetVariable("tessedit_char_whitelist", "0123456789*+-=");
                tessocr.Init(null, "eng", false);
                pictureBoxFilledLib.Image = tessocr.GetThresholdedImage((Bitmap)pictureBoxFilled.Image, Rectangle.Empty);
                text = ocr.DoOCRNormal((Bitmap)pictureBoxFilled.Image, "eng");
                textBoxFilled.Text = text[0].Text;
            }
        }
Пример #2
0
        // Initialization main func

        public void Func1(Bitmap bmp)
        {
            pictureBoxFilled.Image = bmp;
            pictureBoxInput.Image  = (Bitmap)bmp.Clone();
            List <Color> lst = new List <Color>();
            Color        c;

            for (int x = 2; x < bmp.Width; x++)
            {
                c = bmp.GetPixel(x, 2);
                if (!lst.Contains(c))
                {
                    lst.Add(c);
                }
                c = bmp.GetPixel(x, bmp.Height - 3);
                if (!lst.Contains(c))
                {
                    lst.Add(c);
                }
            }
            for (int y = 0; y < bmp.Height; y++)
            {
                c = bmp.GetPixel(2, y);
                if (!lst.Contains(c))
                {
                    lst.Add(c);
                }
                c = bmp.GetPixel(31, y);
                if (!lst.Contains(c))
                {
                    lst.Add(c);
                }
                c = bmp.GetPixel(90, y);
                if (!lst.Contains(c))
                {
                    lst.Add(c);
                }
                c = bmp.GetPixel(bmp.Width - 3, y);
                if (!lst.Contains(c))
                {
                    lst.Add(c);
                }
            }
            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    c = bmp.GetPixel(x, y);
                    if (lst.Contains(c))
                    {
                        if (c != Color.White)
                        {
                            FloodFill(bmp, x, y, Color.White);
                        }
                    }
                }
            }

            Ocr ocr = new Ocr();

            //Input
            tessnet2.Tesseract tessocr = new tessnet2.Tesseract();
            tessocr.SetVariable("tessedit_char_whitelist", "0123456789*+-=");
            tessocr.Init(null, "eng", false);
            pictureBoxInputLib.Image = tessocr.GetThresholdedImage((Bitmap)pictureBoxInput.Image, Rectangle.Empty);
            List <tessnet2.Word> text = ocr.DoOCRNormal((Bitmap)pictureBoxInput.Image, "eng");

            textBoxInput.Text = text[0].Text;

            //Filled
            tessocr = new tessnet2.Tesseract();
            tessocr.SetVariable("tessedit_char_whitelist", "0123456789*+-=");
            tessocr.Init(null, "eng", false);
            pictureBoxFilledLib.Image = tessocr.GetThresholdedImage((Bitmap)pictureBoxFilled.Image, Rectangle.Empty);
            text = ocr.DoOCRNormal((Bitmap)pictureBoxFilled.Image, "eng");
            textBoxFilled.Text = text[0].Text;
        }