Exemplo n.º 1
0
        public List <tessnet2.Word> DoOCRNormal(Bitmap image, string lang)
        {
            tessnet2.Tesseract ocr = new tessnet2.Tesseract();
            ocr.Init(null, lang, false);
            List <tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty);

            return(result);
        }
        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;
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
        public string AnalyzeDocument(string path)
        {
            var langDir = Directory.GetParent(Environment.CurrentDirectory);
            var sb      = new StringBuilder();
            var image   = new Bitmap(path);
            var ocr     = new tessnet2.Tesseract();

            var tessdata = (langDir + @"\tessdata").Trim();

            ocr.Init(tessdata, "eng", false);
            List <Word> result = ocr.DoOCR(image, Rectangle.Empty);

            ocr.GetThresholdedImage(image, Rectangle.Empty);
            result.ForEach(word =>
            {
                sb.Append(word.Text + " ");
            });
            return(sb.ToString().Trim());
        }
Exemplo n.º 5
0
        public static string OCRImageRegion(string img, Rectangle rect)
        {
            try {
                using (Bitmap image = (Bitmap)Utilities.ConversionUtilities.NonLockingOpen(img))
                {
                    Bitmap binarized = OCR_Preprocessing.PreprocessOCR(image, rect);

                    tessnet2.Tesseract ocr = new tessnet2.Tesseract();


                    ocr.Init(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "eng", false);
                    //	            ocr.Init(@"C:\Documents and Settings\BENITO\Mis documentos\SharpDevelop Projects\tessnet2\bin\Debug", "eng", false);
                    //	            ocr.SetVariable("tessedit_char_whitelist", "0123456789.-"); // If digit only
                    List <tessnet2.Word> result = ocr.DoOCR(binarized, Rectangle.Empty);       // Rectangle.Empty);


                    return(result[0].Text);
                }
            } catch (Exception ex) {
                throw ex;
            }
        }
Exemplo n.º 6
0
		public static string OCRImageRegion(string img, Rectangle rect)
		{
			try {
				using (Bitmap image = (Bitmap)Utilities.ConversionUtilities.NonLockingOpen(img))
	            {            	
	
					Bitmap binarized = OCR_Preprocessing.PreprocessOCR(image,rect);
					
		            tessnet2.Tesseract ocr = new tessnet2.Tesseract();
		            
		            
		            ocr.Init(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "eng", false);
	//	            ocr.Init(@"C:\Documents and Settings\BENITO\Mis documentos\SharpDevelop Projects\tessnet2\bin\Debug", "eng", false);
	//	            ocr.SetVariable("tessedit_char_whitelist", "0123456789.-"); // If digit only
		            List<tessnet2.Word> result = ocr.DoOCR(binarized, Rectangle.Empty);// Rectangle.Empty);
		            
		           
		            return result[0].Text;
				}
			} catch (Exception ex) {
				throw ex;
			}

        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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;
        }