private void button3_Click(object sender, EventArgs e)
        {
            //// pictureBox5.Image = img;
            img = new Bitmap(pictureBox5.Image);
            tessnet2.Tesseract orc = new tessnet2.Tesseract();
            orc.SetVariable("tess_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
            orc.Init(Application.StartupPath + @"\tessdata", "eng", false);
            List <tessnet2.Word> result = orc.DoOCR(img, Rectangle.Empty);
            string code = result[0].Text;

            textBox1.Text = code;
        }
Beispiel #2
0
        //string Security_Code;


        private void button3_Click(object sender, EventArgs e)
        {
            //img = new Bitmap(pictureBox6.Image);
            //pictureBox6.Image = img;
            Bitmap bmp = (Bitmap)pictureBox5.Image;

            tessnet2.Tesseract ocr = new tessnet2.Tesseract();//声明一个OCR类
            // ocr.SetVariable("tessedit_char_whitelist", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
            ocr.SetVariable("tessedit_char_whitelist", "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
            ocr.Init(Application.StartupPath + @"\tessdata", "eng", false); //应用当前语言包。
            List <tessnet2.Word> result = ocr.DoOCR(img, Rectangle.Empty);
            //  List<tessnet2.Word> result = ocr.DoOCR(img, Rectangle.Empty);//执行识别操作
            string code = result[0].Text;

            textBox1.Text = code;
        }
Beispiel #3
0
        public static Tuple<int, int, string[]> LoadImage(Bitmap image1)
        {
            Bitmap image = image1;

            //expand
            image=BitmapExtras.ResizeBitmap(image, (int) (image.Width * .7), (int) (image.Height * .7));

            var ocr = new tessnet2.Tesseract();
            ocr.SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
            ocr.Init(null, "eng", false);
            var result = ocr.DoOCR(image, Rectangle.Empty);

            var r1 = new List<Character>();
            foreach (var x in result)
            {
                r1.AddRange(x.CharList);
            }

            return LettersOnLines(r1, image);
        }
Beispiel #4
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;
        }