示例#1
0
文件: Form1.cs 项目: chuixue/Gamer
 public Form1()
 {
     InitializeComponent();
     this.PSN = new Person();
     this.imagePath = Application.StartupPath + "/image";
     if (Directory.Exists(this.imagePath) == false) Directory.CreateDirectory(this.imagePath);
     this.imagePath += "/";
     Init();
     this.F = new mPublic();
     this.CFG = new Config();
     this.MAPP = new Mapping();
     this.RMap = CFG.rect_map_now;
     this.thKill = new Thread(new ThreadStart(AutoKill));
     this.stopKill = true;
     this.ocrNumber = new OCR();
     /*
     //初始化数字识别引擎
     ocrNumber = new TesseractProcessor();
     bInitN = ocrNumber.Init(@".\", "chi_sim", 3);
     if (!bInitN) { MessageBox.Show("智能识别引擎初始化失败!"); return; }
     ocrNumber.SetVariable("tessedit_char_whitelist", ".,2134567890 ");
      * */
     //初始化汉字引擎
     ocrText = new TesseractProcessor();
     bInitT = ocrText.Init(@".\", "chi_sim", 3);
     if (!bInitT) { MessageBox.Show("智能识别引擎初始化失败!"); return; }
     ocrText.SetVariable("tessedit_char_blacklist", "fi蜘fi'£郜QWERTYUIOPASDFGHJKLZXCVBNM1234567890μqwertyuiopasdfghjklzxcvbnm"); 
     
     
 }
示例#2
0
 public Form1()
 {
     InitializeComponent();
     m_tesseract = new TesseractProcessor();
     m_tesseract.Init(m_path, m_lang, (int)TesseractEngineMode.DEFAULT);
     m_tesseract.SetVariable("tessedit_pageseg_mode", TesseractPageSegMode.PSM_AUTO.ToString());
 }
示例#3
0
        private static void AnalyseLayout()
        {
            string imageFile = @"D:\Self-Study\OpenSources\Tesseract\original\phototest.tif";
            //imageFile = @"D:\Self-Study\OpenSources\Tesseract\original\eurotext.tif";

            TesseractProcessor processor = new TesseractProcessor();

            processor.InitForAnalysePage();
            processor.SetPageSegMode(ePageSegMode.PSM_AUTO);

            using (Bitmap bmp = Bitmap.FromFile(imageFile) as Bitmap)
            {
                DocumentLayout doc = processor.AnalyseLayout(bmp);
                Console.WriteLine(doc.ToString());

                using (Image tmp = new Bitmap(bmp.Width, bmp.Height)) // prevents one-byte index format
                {
                    using (Graphics grph = Graphics.FromImage(tmp))
                    {
                        Rectangle rect = new Rectangle(0, 0, tmp.Width, tmp.Height);

                        grph.DrawImage(bmp, rect, rect, GraphicsUnit.Pixel);

                        grph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                        foreach (Block block in doc.Blocks)
                        {
                            DrawBlock(grph, block);
                        }
                    }

                    tmp.Save(@"D:\temp\page_layout_test2.bmp");
                }
            }
        }
示例#4
0
文件: http.cs 项目: antaluqi/web
        private const string m_lang = "eng";      // 识别的语言文件名称

        public string read2dig(Image image)
        {
            TesseractProcessor m_tesseract = new TesseractProcessor();

            ;
            bool succeed = m_tesseract.Init(m_path, m_lang, (int)TesseractEngineMode.DEFAULT);

            if (!succeed)
            {
                return("tesseract初始化失败");
            }
            m_tesseract.SetVariable("tessedit_char_whitelist", "0123456789"); //设置识别变量,当前只能识别数字。

            image.Save("./img/原图.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
            Bitmap bmp = ToGray(image);

            bmp.Save("./img/灰度图.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
            bmp = ConvertTo1Bpp1(bmp, 110);
            bmp.Save("./img/二值图.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
            bmp = Zoom(bmp, 0.25);
            bmp.Save("./img/放大缩小后.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
            m_tesseract.Clear();
            m_tesseract.ClearAdaptiveClassifier();
            return(m_tesseract.Apply(bmp));
        }
示例#5
0
        private static void AnalyseLayout()
        {
            string imageFile = @"D:\Self-Study\OpenSources\Tesseract\original\phototest.tif";
            //imageFile = @"D:\Self-Study\OpenSources\Tesseract\original\eurotext.tif";

            TesseractProcessor processor = new TesseractProcessor();
            processor.InitForAnalysePage();
            processor.SetPageSegMode(ePageSegMode.PSM_AUTO);

            using (Bitmap bmp = Bitmap.FromFile(imageFile) as Bitmap)
            {
                DocumentLayout doc = processor.AnalyseLayout(bmp);
                Console.WriteLine(doc.ToString());

                using (Image tmp = new Bitmap(bmp.Width, bmp.Height)) // prevents one-byte index format
                {
                    using (Graphics grph = Graphics.FromImage(tmp))
                    {
                        Rectangle rect = new Rectangle(0, 0, tmp.Width, tmp.Height);

                        grph.DrawImage(bmp, rect, rect, GraphicsUnit.Pixel);

                        grph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                        foreach (Block block in doc.Blocks)
                        {
                            DrawBlock(grph, block);
                        }
                    }

                    tmp.Save(@"D:\temp\page_layout_test2.bmp");
                }
            }
        }
示例#6
0
        private void button1_Click(object sender, EventArgs e)
        {
            Image mg = Image.FromFile(Application.StartupPath + "\\1.jpg");

            ////Image mg = Image.FromFile("e:\\test24.tif");
            imageViewer1.Initialize(new OCRRenderingData(), new OCRAnalysisRender(imageViewer1));
            imageViewer1.Image = mg;

            TesseractProcessor _ocrProcessor = null;

            _ocrProcessor = new TesseractProcessor();

            //string _tessData = "E:\\tesseract\\tesseract-ocr-dotnet-3.01\\tessdata\\";
            string _tessData      = Application.StartupPath + "\\tessdata\\";
            string _lang          = "eng";
            int    _ocrEngineMode = 3;

            bool status = _ocrProcessor.Init(_tessData, _lang, _ocrEngineMode);

            _ocrProcessor.ROI    = imageViewer1.RectA;
            _ocrProcessor.UseROI = true;

            string text = _ocrProcessor.Recognize(mg);

            //string text1 = text.Replace(" ", "");
            MessageBox.Show(text);
        }
示例#7
0
        public static void Main(string[] args)
        {
            const string language  = "eng";
            string       imageFile = args[0];

            TesseractProcessor processor = new TesseractProcessor();

            using (Bitmap bmp = Bitmap.FromFile(imageFile) as Bitmap)
            {
                var success = processor.Init(TessractData, language, (int)eOcrEngineMode.OEM_DEFAULT);
                if (!success)
                {
                    Console.WriteLine("Failed to initialize tesseract.");
                }
                else
                {
                    // use thresholder
                    processor.UseThresholder();

                    string text = processor.Recognize(bmp);
                    Console.WriteLine("Text:");
                    Console.WriteLine("*****************************");
                    Console.WriteLine(text);
                    Console.WriteLine("*****************************");
                }
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
        public static void Main(string[] args)
        {
            const string language = "eng";
            string imageFile = args[0];

            TesseractProcessor processor = new TesseractProcessor();

            using (Bitmap bmp = Bitmap.FromFile(imageFile) as Bitmap)
            {
                var success = processor.Init(TessractData, language, (int)eOcrEngineMode.OEM_DEFAULT);
                if (!success) {
                    Console.WriteLine("Failed to initialize tesseract.");
                } else {
                    // use thresholder
                    processor.UseThresholder();

                    string text = processor.Recognize(bmp);
                    Console.WriteLine("Text:");
                    Console.WriteLine("*****************************");
                    Console.WriteLine(text);
                    Console.WriteLine("*****************************");
                }
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
示例#9
0
        public override string RecognizeText(IList <Image> images, string lang)
        {
            string             tessdata  = Path.Combine(basedir, TESSDATA);
            TesseractProcessor processor = new TesseractProcessor();

            processor.Init(tessdata, lang, oem);
            processor.SetPageSegMode((ePageSegMode)Enum.Parse(typeof(ePageSegMode), PSM));

            StringBuilder strB = new StringBuilder();

            foreach (Image image in images)
            {
                //if (rect != Rectangle.Empty)
                //{
                //    processor.UseROI = true;
                //    processor.ROI = rect;
                //}
                string text = processor.Recognize(image);

                if (text == null)
                {
                    return(String.Empty);
                }
                strB.Append(text);
            }

            return(strB.ToString().Replace("\n", Environment.NewLine));
        }
示例#10
0
        public static void Recognize()
        {
            int n_images = Workspace.Images.Length;
            int i_image = n_images - 1;
            //i_image = 0;
            i_image = 2;
            string fileName = Workspace.Images[i_image];

            string imageFile = Path.Combine(Workspace.InputFolder, fileName);

            string language = "eng";
            int oem = (int)eOcrEngineMode.OEM_DEFAULT;

            string name = Path.GetFileNameWithoutExtension(imageFile);
            {
                using (Bitmap bmp = Bitmap.FromFile(imageFile) as Bitmap)
                {
                    using (GreyImage greyImage = GreyImage.FromImage(bmp))
                    {

                        ImageThresholder thresholder = new AdaptiveThresholder();
                        using (BinaryImage binImage = thresholder.Threshold(greyImage))
                        {
                            DateTime started = DateTime.Now;
                            DateTime ended = DateTime.Now;

                            Rectangle[] rois = new Rectangle[] { 
                                Rectangle.FromLTRB(807, 43, 1351, 613),
                                Rectangle.FromLTRB(4, 604, binImage.Width - 15, binImage.Height-35)
                            };

                            int nROIs = rois.Length;

                            string[] texts = new string[nROIs];
#if PARALLEL
                            Parallel.For(0, nROIs, delegate(int iROI) 
#else
                            using (TesseractProcessor processor = new TesseractProcessor())
                            for (int iROI = 0; iROI < nROIs; iROI++)
#endif
                            {
#if PARALLEL
                                using (TesseractProcessor processor = new TesseractProcessor())
#endif
                                {
                                    Rectangle roi = rois[iROI];
                                    {                                    
                                        //oem = (int)eOcrEngineMode.OEM_TESSERACT_CUBE_COMBINED;
                                        processor.Init(Workspace.TessdataFolder, language, oem);
                                        processor.UseROI = true;
                                        processor.ROI = roi;
                                        unsafe
                                        {                                            
                                            texts[iROI] = processor.RecognizeBinaryImage(
                                               binImage.BinaryData, binImage.Width, binImage.Height);
                                        }
                                    }
                                }
                            }
示例#11
0
 private void End()
 {
     if (_ocrProcessor != null)
     {
         _ocrProcessor.End();
         _ocrProcessor = null;
     }
 }
示例#12
0
        public static string Recognize(string url)
        {
            WebRequest  request  = WebRequest.Create(url);
            WebResponse response = request.GetResponse();
            Stream      st       = response.GetResponseStream();

            if (st == null)
            {
                return(string.Empty);
            }

            try
            {
                Bitmap bitmap = ((Bitmap)Bitmap.FromStream(st)).toGray().biLinear(2);
                //var newBitmap= KiCut(bitmap, 12, 22, bitmap.Width - 12, 22);
                string tessdata = Environment.CurrentDirectory + "\\tessdata\\";
                string language = "eng";//设置训练文件的名称,后缀traineddata之前的名称
                int    oem      = 3;
                // http://www.lixin.me/blog/2012/05/26/29536 训练
                using (TesseractProcessor processor = new TesseractProcessor())
                {
                    //初始化
                    bool initFlage = processor.Init(tessdata, language, oem);
                    //processor.GetTesseractEngineVersion();//获取版本号

                    /*
                     * Set the current page segmentation mode. Defaults to PSM_SINGLE_BLOCK.
                     * The mode is stored as an IntParam so it can also be modified by ReadConfigFile or SetVariable("tessedit_pageseg_mode", mode as string). */
                    //processor.SetPageSegMode(ePageSegMode.PSM_SINGLE_BLOCK);

                    //设置ROI(图像的感兴趣区域)
                    processor.UseROI = true;
                    processor.ROI    = new Rectangle(24, 0, bitmap.Width - 24, bitmap.Height);

                    //设置识别的变量 如果是自定义培训的文件 可以不用设置
                    //必须在初始化后调用
                    processor.SetVariable("tessedit_char_whitelist", "0123456789.");
                    //processor.SetVariable("tessedit_thresholding_method", "1"); //图像处理阀值是否打开
                    //processor.SetVariable("save_best_choices", "T");
                    using (Bitmap bmp = bitmap)
                    {
                        int i = 3;
                        oem = i;
                        string text        = processor.Recognize(bmp);
                        char[] charsToTrim = { '\\', 'n', '\\', 'n' };
                        return(text.TrimEnd(charsToTrim));
                        //Console.WriteLine(
                        //    string.Format(
                        //        "RecognizeMode: {1}\nText:\n{0}\n++++++\n", text, ((eOcrEngineMode)oem).ToString()));
                    }
                }
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
示例#13
0
    static oTesseractRequest __ocrExecute2(oTesseractRequest req, Bitmap bitmap)
    {
        using (TesseractProcessor processor = new TesseractProcessor())
        {
            processor.InitForAnalysePage();
            using (GreyImage greyImage = GreyImage.FromImage(bitmap))
            {
                //greyImage.Save(ImageFormat.Bmp, outFile2);

                ImageThresholder thresholder = new AdaptiveThresholder();
                using (BinaryImage binImage = thresholder.Threshold(greyImage))
                {
                    DocumentLayout doc = null;
                    switch (req.command)
                    {
                    case TESSERACT_COMMAND.GET_TEXT:
                        //string s = tes.GetText().Trim();
                        //req.output_text = s;
                        //req.output_count = s.Length;
                        req.ok = 1;
                        break;

                    default:
                        unsafe
                        {
                            doc = processor.AnalyseLayoutBinaryImage(
                                binImage.BinaryData, greyImage.Width, greyImage.Height);
                        }
                        if (doc != null)
                        {
                            var bs = new List <string>();
                            if (doc.Blocks.Count > 0)
                            {
                                for (int i = 0; i < doc.Blocks.Count; i++)
                                {
                                    for (int j = 0; j < doc.Blocks[i].Paragraphs.Count; j++)
                                    {
                                        bs.AddRange(doc.Blocks[j].Paragraphs[j].Lines
                                                    .Select(x => string.Format(
                                                                "{0}_{1}_{2}_{3}", x.Left, x.Top, x.Right, x.Bottom)));
                                    }
                                }
                            }
                            req.output_format = "left_top_right_bottom";
                            req.output_text   = string.Join("|", bs.ToArray());
                            req.output_count  = bs.Count;
                            req.ok            = 1;
                        }
                        break;
                    }
                }
            }
        }

        return(req);
    }
示例#14
0
        public TesseractOCREngine(Image image)
        {
            this.image  = image;
            m_tesseract = new TesseractProcessor();
            bool succeed = m_tesseract.Init(m_path, m_lang, (int)TesseractEngineMode.DEFAULT);

            m_tesseract.SetVariable("tessedit_char_whitelist", "0123456789-.eExXpP/\\");
            m_tesseract.SetVariable("tessedit_pageseg_mode", ((int)TesseractPageSegMode.PSM_SINGLE_LINE).ToString());
            System.Environment.CurrentDirectory = System.IO.Path.GetFullPath(m_path);
        }
示例#15
0
        private void ProcessFrame(bool instant)
        {
            if (!btnScreenshot.Enabled)
            {
                return;
            }
            if (!File.Exists(openFileDialogTesseract.FileName))
            {
                MessageBox.Show(this, "Tesseract-OCR path not configured!", "Screenulate",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            tesseractProgress.Style = ProgressBarStyle.Marquee;
            btnScreenshot.Enabled   = false;

            var screenshotForm = new ScreenshotForm {
                Rectangle = _lastScreenshotRect
            };

            if (instant)
            {
                screenshotForm.CaptureImage(_lastScreenshotRect);
            }
            else
            {
                screenshotForm.ShowDialog(this);
            }

            if (screenshotForm.Bitmap == null)
            {
                tesseractProgress.Style = ProgressBarStyle.Blocks;
                btnScreenshot.Enabled   = true;
                return;
            }

            _lastScreenshotRect = screenshotForm.Rectangle;

            IImage oldImage = previewBox.Image;

            previewBox.Image = new Image <Bgr, byte>(screenshotForm.Bitmap);
            oldImage?.Dispose();
            var processor = new TesseractProcessor(openFileDialogTesseract.FileName, previewBox.DisplayedImage);

            processor.Process();

            processor.Completed += TesseractProcessor_Completed;
            processor.Finished  += TesseractProcessor_Finished;
            processor.Error     += (sender, args) =>
            {
                MessageBox.Show($@"{args.GetException().Message}", "Screenulate", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            };
        }
示例#16
0
        private void button1_Click(object sender, EventArgs e)
        {
            string d = textBox_Path.Text;

            if (!Directory.Exists(d))
            {
                MessageBox.Show("目录" + d + "不存在");
                return;
            }
            if (!d.EndsWith("\\"))
            {
                d += "\\";
            }
            string d1 = d + "new\\";

            if (!Directory.Exists(d1))
            {
                Directory.CreateDirectory(d1);
            }
            Regex reg = new Regex(@"\d+\.\d\d", RegexOptions.Compiled);

            foreach (string f in Directory.GetFiles(textBox_Path.Text))
            {
                if (!f.ToLower().EndsWith(".png") && !f.ToLower().EndsWith(".jpg") && !f.ToLower().EndsWith(".bmp"))
                {
                    continue;
                }
                Bitmap             bmp     = new Bitmap(f);
                TesseractProcessor process = new TesseractProcessor();
                process.SetPageSegMode(ePageSegMode.PSM_SINGLE_LINE);
                process.Init(System.Environment.CurrentDirectory + "\\", "chi_sim", (int)eOcrEngineMode.OEM_DEFAULT);
                try
                {
                    string result = process.Recognize(bmp);
                    Match  m      = reg.Match(result);
                    if (m.Success)
                    {
                        string amount = m.ToString();
                        File.Copy(f, d1 + amount + Path.GetExtension(f), true);
                    }
                    else
                    {
                        File.Copy(f, d1 + Path.GetFileName(f), true);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("识别文件出错:" + f);
                    File.Copy(f, d1 + Path.GetFileName(f), true);
                }
                bmp.Dispose();
            }
            System.Diagnostics.Process.Start(d1);
        }
        static void Simple2_Recognize()
        {
            int n_images = Images.Length;
            int i_image = n_images - 1;
            //i_image = 0;
            string fileName = Images[i_image];

            string imageFile = Path.Combine(InputFolder, fileName);

            string language = "eng";
            int oem = (int)eOcrEngineMode.OEM_DEFAULT;

            using (TesseractProcessor processor = new TesseractProcessor())
            {
                using (Bitmap bmp = Bitmap.FromFile(imageFile) as Bitmap)
                {
                    using (GreyImage greyImage = GreyImage.FromImage(bmp))
                    {

                        ImageThresholder thresholder = new AdaptiveThresholder();
                        using (BinaryImage binImage = thresholder.Threshold(greyImage))
                        {
                            DateTime started = DateTime.Now;
                            DateTime ended = DateTime.Now;

                            int i = 3;
                            //for (i = 0; i < 4; i++)
                            //for (i = 3; i < 4; i++)
                            {
                                oem = i;
                                processor.Init(TessdataFolder, language, oem);

                                string text = "";
                                unsafe
                                {
                                    started = DateTime.Now;

                                    text = processor.RecognizeBinaryImage(
                                        binImage.BinaryData, greyImage.Width, greyImage.Height);

                                    ended = DateTime.Now;

                                    Console.WriteLine("Duration recognition: {0} ms\n\n", (ended - started).TotalMilliseconds);
                                }

                                Console.WriteLine(
                                    string.Format("RecognizeMode: {1}\nRecognized Text:\n{0}\n++++++++++++++++++++++++++++++++\n", text, ((eOcrEngineMode)oem).ToString()));
                            }
                        }
                    }
                }
            }
        }
        public static void Recognize()
        {
            int n_images = Workspace.Images.Length;
            int i_image  = n_images - 1;

            i_image = 0;
            string fileName = Workspace.Images[i_image];

            string imageFile = Path.Combine(Workspace.InputFolder, fileName);

            string language = "eng";
            int    oem      = 3;

            TesseractProcessor processor = new TesseractProcessor();

            using (Bitmap bmp = Bitmap.FromFile(imageFile) as Bitmap)
            {
                GreyImage greyImage = GreyImage.FromImage(bmp);

                DateTime            started     = DateTime.Now;
                AdaptiveThresholder thresholder = new AdaptiveThresholder();
                BinaryImage         binImage    = thresholder.Threshold(greyImage);
                DateTime            ended       = DateTime.Now;
                Console.WriteLine("Duration thresholding: {0} ms", (ended - started).TotalMilliseconds);

                binImage.Invert();

                //for (int i = 0; i < 4; i++)
                for (int i = 3; i < 4; i++)
                {
                    oem = i;
                    oem = (int)eOcrEngineMode.OEM_TESSERACT_CUBE_COMBINED;
                    processor.Init(Workspace.TessdataFolder, language, oem);

                    string text = "";
                    unsafe
                    {
                        started = DateTime.Now;

                        //string text = processor.Recognize(bmp);
                        text = processor.RecognizeBinaryImage(
                            binImage.BinaryData, binImage.Width, binImage.Height);

                        ended = DateTime.Now;
                        Console.WriteLine("Duration recognition: {0} ms\n\n", (ended - started).TotalMilliseconds);
                    }

                    Console.WriteLine(
                        string.Format("RecognizeMode: {1}\nText:\n{0}\n++++++++++++++++++++++++++++++++\n", text, ((eOcrEngineMode)oem).ToString()));
                }
            }
        }
示例#19
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.LoadGeneralSettings();

            _ocrProcessor           = new TesseractProcessor();
            _ocrProcessor.DoMonitor = true;

            bool status = _ocrProcessor.Init(_tessData, _lang, _ocrEngineMode);

            Console.WriteLine(string.Format("[DEBUG] Init status: {0}", status));
        }
示例#20
0
        private void button1_Click(object sender, EventArgs e)
        {
            Image mg = Image.FromFile(Application.StartupPath + "\\1.jpg");

            ////Image mg = Image.FromFile("e:\\test24.tif");
            templateViewer1.Initialize(new OCRRenderingData(), new OCRAnalysisRender(templateViewer1));
            templateViewer1.Image = mg;

            TesseractProcessor _ocrProcessor = null;

            _ocrProcessor = new TesseractProcessor();

            string _tessData      = Application.StartupPath + "\\tessdata\\";
            string _lang          = "eng";
            int    _ocrEngineMode = 3;

            bool status = _ocrProcessor.Init(_tessData, _lang, _ocrEngineMode);

            _ocrProcessor.ROI = templateViewer1.RectA;
            rec += templateViewer1.RectA.X + ";" + templateViewer1.RectA.Y + ";" + templateViewer1.RectA.Width + ";" + templateViewer1.RectA.Height + "|";
            _ocrProcessor.UseROI = true;

            string text = _ocrProcessor.Recognize(mg);

            _ocrProcessor.ROI = templateViewer1.RectB;
            rec += templateViewer1.RectB.X + ";" + templateViewer1.RectB.Y + ";" + templateViewer1.RectB.Width + ";" + templateViewer1.RectB.Height + "|";
            _ocrProcessor.UseROI = true;

            text += _ocrProcessor.Recognize(mg);

            _ocrProcessor.ROI = templateViewer1.RectC;
            rec += templateViewer1.RectC.X + ";" + templateViewer1.RectC.Y + ";" + templateViewer1.RectC.Width + ";" + templateViewer1.RectC.Height + "|";
            _ocrProcessor.UseROI = true;

            text += _ocrProcessor.Recognize(mg);

            _ocrProcessor.ROI = templateViewer1.RectD;
            rec += templateViewer1.RectD.X + ";" + templateViewer1.RectD.Y + ";" + templateViewer1.RectD.Width + ";" + templateViewer1.RectD.Height + "|";
            _ocrProcessor.UseROI = true;

            text += _ocrProcessor.Recognize(mg);

            _ocrProcessor.ROI = templateViewer1.RectE;
            rec += templateViewer1.RectE.X + ";" + templateViewer1.RectE.Y + ";" + templateViewer1.RectE.Width + ";" + templateViewer1.RectE.Height;
            _ocrProcessor.UseROI = true;

            text += _ocrProcessor.Recognize(mg);

            MessageBox.Show(text);
            MessageBox.Show(rec);
        }
示例#21
0
        private void OCR_Load(object sender, EventArgs e)
        {
            m_tesseract = new TesseractProcessor();
            bool succeed = m_tesseract.Init(m_path, m_lang, 3);

            if (!succeed)
            {
                MessageBox.Show("Tesseract initialization failed. The application will exit.");
                Application.Exit();
            }
            m_tesseract.SetVariable("tessedit_char_whitelist", "ABCDEFHKLMNPQRSTUVXYZ-.1234567890").ToString(); //Training Sets //abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ-.1234567890

            System.Environment.CurrentDirectory = System.IO.Path.GetFullPath(m_path);
        }
示例#22
0
文件: Form1.cs 项目: WeAre0ne/PRRR
        public void StartOCR(Bitmap theBitmap)
        {
            string language = "eng";
            string languageData = Application.StartupPath + @"\tessdata\";
            using (TesseractProcessor processor = new TesseractProcessor())
            {
                if (processor.Init(languageData, language, (int)eOcrEngineMode.OEM_DEFAULT))
                {
                    string text = processor.Recognize(theBitmap);
                    richTextBox1.AppendText(text + "\n");
                }

            }
        }
		public TesseractEngine(string langFilesPath, string lang)
		{
			this.tp = new TesseractProcessor();
			this.lang = lang;
			this.langFilesPath = langFilesPath;
			if (this.langFilesPath.get_Length() == 0)
			{
				this.langFilesPath = string.Concat(Application.get_StartupPath(), "\\tessdata\\");
			}
			if (!this.langFilesPath.EndsWith("\\"))
			{
				TesseractEngine tesseractEngine = this;
				tesseractEngine.langFilesPath = string.Concat(tesseractEngine.langFilesPath, "\\");
			}
		}
示例#24
0
        void CheckInPage_Loaded(object sender, RoutedEventArgs e)
        {
            full_tesseract = new TesseractProcessor();
            bool succeed = full_tesseract.Init(m_path, m_lang, 3);

            if (!succeed)
            {
                System.Windows.MessageBox.Show("Lỗi thư viện Tesseract. Chương trình cần kết thúc.");
            }
            full_tesseract.SetVariable("tessedit_char_whitelist", "ACDFHKLMNPRSTVXY1234567890").ToString();

            ch_tesseract = new TesseractProcessor();
            succeed      = ch_tesseract.Init(m_path, m_lang, 3);
            if (!succeed)
            {
                System.Windows.MessageBox.Show("Lỗi thư viện Tesseract. Chương trình cần kết thúc.");
            }
            ch_tesseract.SetVariable("tessedit_char_whitelist", "ACDEFHKLMNPRSTUVXY").ToString();

            num_tesseract = new TesseractProcessor();
            succeed       = num_tesseract.Init(m_path, m_lang, 3);
            if (!succeed)
            {
                System.Windows.MessageBox.Show("Lỗi thư viện Tesseract. Chương trình cần kết thúc.");
            }
            num_tesseract.SetVariable("tessedit_char_whitelist", "1234567890").ToString();

            System.Environment.CurrentDirectory = System.IO.Path.GetFullPath(m_path);
            for (int i = 0; i < box.Length; i++)
            {
                box[i] = new PictureBox();
            }
            string folder = System.AppDomain.CurrentDomain.BaseDirectory + "\\ImageTest";

            foreach (string fileName in Directory.GetFiles(folder, "*.bmp", SearchOption.TopDirectoryOnly))
            {
                lstimages.Add(System.IO.Path.GetFullPath(fileName));
            }
            foreach (string fileName in Directory.GetFiles(folder, "*.jpg", SearchOption.TopDirectoryOnly))
            {
                lstimages.Add(System.IO.Path.GetFullPath(fileName));
            }

            pic1 = (hostPic1.Child as System.Windows.Forms.PictureBox);
            pic2 = (hostPic2.Child as System.Windows.Forms.PictureBox);
            img1 = (hostImg1.Child as Emgu.CV.UI.ImageBox);
        }
示例#25
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            int soluong;
            int tong;

            tong                     = int.Parse(txt_tong.Text);
            soluong                  = int.Parse(bss.so_luong_xe());
            txt_conlai.Text          = (tong - soluong).ToString();
            dataGridView1.DataSource = bss.Danhsachxe();
            capture                  = new Emgu.CV.Capture();
            timer1.Enabled           = true;
            full_tesseract           = new TesseractProcessor();
            bool succeed = full_tesseract.Init(m_path, m_lang, 3);

            if (!succeed)
            {
                MessageBox.Show("Tesseract initialization failed. The application will exit.");
                Application.Exit();
            }
            full_tesseract.SetVariable("tessedit_char_whitelist", "ABCDEFHKLMNPRSTVXY1234567890").ToString();

            ch_tesseract = new TesseractProcessor();
            succeed      = ch_tesseract.Init(m_path, m_lang, 3);
            if (!succeed)
            {
                MessageBox.Show("Tesseract initialization failed. The application will exit.");
                Application.Exit();
            }
            ch_tesseract.SetVariable("tessedit_char_whitelist", "ABCDEFHKLMNPRSTUVXY").ToString();

            num_tesseract = new TesseractProcessor();
            succeed       = num_tesseract.Init(m_path, m_lang, 3);
            if (!succeed)
            {
                MessageBox.Show("Tesseract initialization failed. The application will exit.");
                Application.Exit();
            }
            num_tesseract.SetVariable("tessedit_char_whitelist", "1234567890").ToString();


            m_path = System.Environment.CurrentDirectory + "\\";
            string[] ports = SerialPort.GetPortNames();
            for (int i = 0; i < box.Length; i++)
            {
                box[i] = new PictureBox();
            }
        }
示例#26
0
        //private string _Caption = "http://www.laptrinhvb.net";
        #endregion

        private void FrmMain_Load(object sender, EventArgs e)
        {
            full_tesseract = new TesseractProcessor();
            bool succeed = full_tesseract.Init(m_path, m_lang, 3);

            if (!succeed)
            {
                MessageBox.Show("Lỗi thư viện Tesseract. Chương trình cần kết thúc.");
                Application.Exit();
            }
            full_tesseract.SetVariable("tessedit_char_whitelist", "ACDFHKLMNPRSTVXY1234567890").ToString();

            ch_tesseract = new TesseractProcessor();
            succeed      = ch_tesseract.Init(m_path, m_lang, 3);
            if (!succeed)
            {
                MessageBox.Show("Lỗi thư viện Tesseract. Chương trình cần kết thúc.");
                Application.Exit();
            }
            ch_tesseract.SetVariable("tessedit_char_whitelist", "ACDEFHKLMNPRSTUVXY").ToString();

            num_tesseract = new TesseractProcessor();
            succeed       = num_tesseract.Init(m_path, m_lang, 3);
            if (!succeed)
            {
                MessageBox.Show("Lỗi thư viện Tesseract. Chương trình cần kết thúc.");
                Application.Exit();
            }
            num_tesseract.SetVariable("tessedit_char_whitelist", "1234567890").ToString();

            System.Environment.CurrentDirectory = System.IO.Path.GetFullPath(m_path);
            for (int i = 0; i < box.Length; i++)
            {
                box[i] = new PictureBox();
            }
            string folder = Application.StartupPath + "\\ImageTest";

            foreach (string fileName in Directory.GetFiles(folder, "*.bmp", SearchOption.TopDirectoryOnly))
            {
                lstimages.Add(Path.GetFullPath(fileName));
            }
            foreach (string fileName in Directory.GetFiles(folder, "*.jpg", SearchOption.TopDirectoryOnly))
            {
                lstimages.Add(Path.GetFullPath(fileName));
            }
        }
示例#27
0
        /*   private void button3_Click(object sender, EventArgs e)
         * {
         *     if (capture != null)
         *     {
         *         timer1.Enabled = false;
         *         pictureBox_XeRA.Image = null;
         *         IF.pictureBox2.Image = null;
         *         capture.QueryFrame().Save("aa.bmp");
         *         FileStream fs = new FileStream(m_path + "aa.bmp", FileMode.Open, FileAccess.Read);
         *         Image temp = Image.FromStream(fs);
         *         fs.Close();
         *         pictureBox_XeRA.Image = temp;
         *         IF.pictureBox2.Image = temp;
         *         pictureBox_XeRA.Update();
         *         IF.pictureBox2.Update();
         *         Image temp1;
         *         string temp2, temp3;
         *         /*Reconize(m_path + "aa.bmp", out temp1, out temp2, out temp3);
         *         pictureBox_XeVAO.Image = temp1;
         *         if(temp3 == "")
         *             text_BiensoVAO.Text = "ko nhận dạng dc biển số";
         *         else
         *             text_BiensoVAO.Text = temp3;
         *
         *         timer1.Enabled = true;
         *     }
         *
         * }*/

        private void MainForm_Load_1(object sender, EventArgs e)
        {
            capture        = new Emgu.CV.Capture();
            timer2.Enabled = true;
            timer4.Start();

            IF = new ImageForm();

            full_tesseract = new TesseractProcessor();
            bool succeed = full_tesseract.Init(m_path, m_lang, 3);

            if (!succeed)
            {
                MessageBox.Show("Tesseract initialization failed. The application will exit.");
                Application.Exit();
            }
            full_tesseract.SetVariable("tessedit_char_whitelist", "ABCDEFHKLMNPRSTVXY1234567890").ToString();

            ch_tesseract = new TesseractProcessor();
            succeed      = ch_tesseract.Init(m_path, m_lang, 3);
            if (!succeed)
            {
                MessageBox.Show("Tesseract initialization failed. The application will exit.");
                Application.Exit();
            }
            ch_tesseract.SetVariable("tessedit_char_whitelist", "ABCDEFHKLMNPRSTUVXY").ToString();

            num_tesseract = new TesseractProcessor();
            succeed       = num_tesseract.Init(m_path, m_lang, 3);
            if (!succeed)
            {
                MessageBox.Show("Tesseract initialization failed. The application will exit.");
                Application.Exit();
            }
            num_tesseract.SetVariable("tessedit_char_whitelist", "1234567890").ToString();


            m_path = System.Environment.CurrentDirectory + "\\";
            string[] ports = SerialPort.GetPortNames();
            for (int i = 0; i < box.Length; i++)
            {
                box[i] = new PictureBox();
            }
        }
        public static void Recognize()
        {
            int n_images = Workspace.Images.Length;
            int i_image  = n_images - 1;

            i_image = 0;
            string fileName = Workspace.Images[i_image];

            string imageFile = Path.Combine(Workspace.InputFolder, fileName);

            string language = "eng";
            int    oem      = (int)eOcrEngineMode.OEM_DEFAULT;

            using (TesseractProcessor processor = new TesseractProcessor())
            {
                using (Bitmap bmp = Bitmap.FromFile(imageFile) as Bitmap)
                {
                    DateTime started = DateTime.Now;
                    DateTime ended   = DateTime.Now;

                    for (int i = 0; i < 4; i++)
                    //for (int i = 3; i < 4; i++)
                    {
                        oem = i;
                        processor.Init(Workspace.TessdataFolder, language, oem);

                        string text = "";
                        unsafe
                        {
                            started = DateTime.Now;

                            text = processor.Recognize(bmp);

                            ended = DateTime.Now;

                            Console.WriteLine("Duration recognition: {0} ms\n\n", (ended - started).TotalMilliseconds);
                        }

                        Console.WriteLine(
                            string.Format("RecognizeMode: {1}\nRecognized Text:\n{0}\n++++++++++++++++++++++++++++++++\n", text, ((eOcrEngineMode)oem).ToString()));
                    }
                }
            }
        }
示例#29
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var image = System.Drawing.Image.FromFile(@"D:\Image\Capture1T.tif");


        m_tesseract = new TesseractProcessor();
        bool succeed = m_tesseract.Init(m_path, m_lang, (int)TesseractEngineMode.DEFAULT);

        if (!succeed)
        {
        }

        m_tesseract.SetVariable("tessedit_pageseg_mode", ((int)TesseractPageSegMode.PSM_SINGLE_LINE).ToString());
        m_tesseract.Clear();
        m_tesseract.ClearAdaptiveClassifier();
        string outValue = m_tesseract.Apply(image);

        Response.Write(outValue);
    }
示例#30
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            IOcrProcessor ocrProcessor = new TesseractProcessor();

            IBlobDim gameBlobDef = new GameBlobDef
            {
                MinWidth  = 42,
                MaxWidth  = 170,
                MinHeight = 11,
                MaxHeight = 13
            };

            IBlobCounter blobCounter = new AccordCounter();

            blobCounter.SetBlobDim(gameBlobDef);

            Application.Run(new Form1(ocrProcessor, blobCounter));
        }
        static void Simple1_Recognize()
        {
            using (TesseractProcessor processor = new TesseractProcessor())
            {
                using (Bitmap bmp = Bitmap.FromFile("phototest.tif") as Bitmap)
                {
                    DateTime started = DateTime.Now;
                    DateTime ended = DateTime.Now;

                    int oem = 0;
                    for (int i = 0; i < 4; i++)
                    //for (int i = 3; i < 4; i++)
                    {
                        oem = i;
                        bool ok = processor.Init(TessdataFolder, "eng", i);
                        if (ok)
                        {
                            string text = "";
                            unsafe
                            {
                                started = DateTime.Now;

                                text = processor.Recognize(bmp);

                                ended = DateTime.Now;

                                Console.WriteLine("Duration recognition: {0} ms\n\n", (ended - started).TotalMilliseconds);
                            }

                            Console.WriteLine(
                                string.Format("RecognizeMode: {1}\nRecognized Text:\n{0}\n++++++++++++++++++++++++++++++++\n", text, ((eOcrEngineMode)oem).ToString()));
                        }
                        else
                        {
                            Console.WriteLine("FAIL " + i.ToString());
                        }
                    }
                }
            }
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            const string language = "eng";
            const string TessractData = @"C:\Users\Salman\Documents\GitHub\project-pinnacle\Research\Salman\OCRTest\tessdata\";
            const string Path = @"C:\Users\Salman\NUS\EE4001\Research\trial.tif";

            TesseractProcessor processor = new TesseractProcessor();
            processor.DoMonitor = true;

            System.Drawing.Image bmp = System.Drawing.Image.FromFile(Path);

            bool x = processor.Init(TessractData, language, (int)eOcrEngineMode.TESSERACT_CUBE_COMBINED);

            processor.Clear();
            processor.ClearAdaptiveClassifier();
            string result = processor.Apply(bmp);
            List<Word> detectedWords = processor.RetriveResultDetail();
            int a = 2;
            //this.UpdateImageViewer(detectedWords);

            //using (var bmp = Bitmap.FromFile(Path) as Bitmap)
            //{
            //    var success = processor.Init(TessractData, language, (int)eOcrEngineMode.DEFAULT);
            //    if (!success)
            //    {
            //        Console.WriteLine("Failed to initialize tesseract.");
            //    }
            //    else
            //    {
            //        string text = processor.Recognize(bmp);
            //        Console.WriteLine("Text:");
            //        Console.WriteLine("*****************************");
            //        Console.WriteLine(text);
            //        Console.WriteLine("*****************************");
            //    }
            //}

            //Console.WriteLine("Press any key to exit.");
            //Console.ReadKey();
        }
示例#33
0
        private static void Recognize()
        {
            string imageFile = @"D:\Self-Study\OpenSources\Tesseract\original\phototest.tif";

            imageFile = @"D:\Self-Study\OpenSources\Tesseract\original\eurotext.tif";


            string tessdata = @"D:\Self-Study\OpenSources\Tesseract\original\tessdata\";
            string language = "eng";
            int    oem      = 3;

            TesseractProcessor processor = new TesseractProcessor();

            processor.Init(tessdata, language, oem);

            using (Bitmap bmp = Bitmap.FromFile(imageFile) as Bitmap)
            {
                string text = processor.Recognize(bmp);
                Console.WriteLine(
                    string.Format("Text:\n{0}\n", text));
            }
        }
示例#34
0
        public override string RecognizeText(IList <Image> images, string lang)
        {
            string             tessdata  = Path.Combine(basedir, TESSDATA);
            TesseractProcessor processor = new TesseractProcessor();

            processor.Init(tessdata, lang, oem);

            StringBuilder strB = new StringBuilder();

            foreach (Image image in images)
            {
                string text = processor.Recognize(image, rect);

                if (text == null)
                {
                    return(String.Empty);
                }
                strB.Append(text);
            }

            return(strB.ToString().Replace("\n", Environment.NewLine));
        }
示例#35
0
        public static string Ocr(Bitmap image_s, bool isFull, TesseractProcessor full_tesseract, TesseractProcessor num_tesseract, TesseractProcessor ch_tesseract, bool isNum = false)
        {
            Image <Gray, byte> image = new Image <Gray, byte>(image_s);

            while (true)
            {
                if ((double)CvInvoke.cvCountNonZero((IntPtr)((UnmanagedObject)image)) / (double)(image.Width * image.Height) <= 0.5)
                {
                    image = image.Dilate(2);
                }
                else
                {
                    break;
                }
            }
            Bitmap             bitmap             = image.ToBitmap();
            TesseractProcessor tesseractProcessor = !isFull ? (!isNum ? ch_tesseract : num_tesseract) : full_tesseract;
            int num = 0;

            tesseractProcessor.Clear();
            tesseractProcessor.ClearAdaptiveClassifier();
            string str = tesseractProcessor.Apply((Image)bitmap);

            while (str.Length > 3)
            {
                bitmap = new Image <Gray, byte>(bitmap).Erode(2).ToBitmap();
                tesseractProcessor.Clear();
                tesseractProcessor.ClearAdaptiveClassifier();
                str = tesseractProcessor.Apply((Image)bitmap);
                ++num;
                if (num > 10)
                {
                    str = "";
                    break;
                }
            }
            return(str);
        }
        public static string Recognize(string url,Rectangle rectangle)
        {
            WebRequest request = WebRequest.Create(url);
            WebResponse response = request.GetResponse();
            Stream st = response.GetResponseStream();
            if (st == null)
            {
                return string.Empty;
            }

            Bitmap bitmap = ((Bitmap)Bitmap.FromStream(st)).toGray().biLinear(2);
            //var newBitmap= KiCut(bitmap, 12, 22, bitmap.Width - 12, 22);
            string tessdata = Environment.CurrentDirectory + "\\tessdata\\";
            string language = "eng";//设置训练文件的名称,后缀traineddata之前的名称
            int oem = 3;
            // http://www.lixin.me/blog/2012/05/26/29536 训练
            using (TesseractProcessor processor = new TesseractProcessor())
            {
                //初始化
                bool initFlage = processor.Init(tessdata, language, oem);
                //processor.GetTesseractEngineVersion();//获取版本号

                /*
                 Set the current page segmentation mode. Defaults to PSM_SINGLE_BLOCK.
                The mode is stored as an IntParam so it can also be modified by ReadConfigFile or SetVariable("tessedit_pageseg_mode", mode as string). */
                //processor.SetPageSegMode(ePageSegMode.PSM_SINGLE_BLOCK);

                //设置ROI(图像的感兴趣区域)
                if (rectangle != null)
                {
                    processor.UseROI = true;
                    processor.ROI = rectangle;
                }

                //设置识别的变量 如果是自定义培训的文件 可以不用设置
                //必须在初始化后调用
                processor.SetVariable("tessedit_char_whitelist", "0123456789.");
                //processor.SetVariable("tessedit_thresholding_method", "1"); //图像处理阀值是否打开
                //processor.SetVariable("save_best_choices", "T");
                using (Bitmap bmp = bitmap)
                {
                    string text = processor.Recognize(bmp);
                    char[] charsToTrim = { '\\', 'n', '\\', 'n' };
                    return text.TrimEnd(charsToTrim);
                }
            }
        }
示例#37
0
        /// <summary>
        /// Search a string into an image
        /// </summary>
        /// <param name="image">the image</param>
        /// <param name="inputString">the string to search</param>
        /// <returns>return true if the string was found</returns>
        private static bool checkStringByOCR(Bitmap image, string inputString)
        {
            Stopwatch a = new Stopwatch();
            a.Start();

            using (var bmp = image)
            {
                try
                {
                    //init the OCR engine, I use tessaract as OCR engine.
                    TesseractProcessor processor = new TesseractProcessor();
                    //verify if tessaract has been successfully loaded
                    var success = processor.Init(_ocrLangData, _ocrLanguageSelected, (int)eOcrEngineMode.OEM_DEFAULT);
                    if (!success)
                    {
                        //if tessaract has not been successfully loaded then write the error
                        LogUtils.Write(new StackFrame(0, true), LogUtils.ErrorLevel.Error, "Failed to start OCR engine");
                        Program.Finish(true);
                        return false;
                    }
                    else
                    {
                        //extract the string from the image
                        string textInImage = processor.Recognize(bmp);
                        //textInImage = textInImage.Replace('\n', ' ');
                        //textInImage = textInImage.Replace('\r', ' ');

                        //write a debug message
                        if (_debugLogLevel)
                            LogUtils.Write(new StackFrame(0, true), LogUtils.ErrorLevel.Debug, "text found: " + textInImage);

                        //check if the string extracted from the image is equal to the string that we want to find.
                        //NOTE that tesseract occasionally swaps a letter with another. For example, it may change
                        //an "m" with two letters "rm" or an "l" with a "|" and so on. So i try to solve some of these errors.
                        //You can set a debug level on the log option and search into the log file the string "text found: " and
                        //then see text that tesseract has found
                        if (Regex.IsMatch(textInImage, inputString) ||
                            Regex.IsMatch(textInImage.Replace("m", "rn"), inputString) || Regex.IsMatch(textInImage.Replace("rn", "m"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("l", "1"), inputString) || Regex.IsMatch(textInImage.Replace("1", "l"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("l", "i"), inputString) || Regex.IsMatch(textInImage.Replace("i", "l"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("t", "l"), inputString) || Regex.IsMatch(textInImage.Replace("l", "t"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("1", "i"), inputString) || Regex.IsMatch(textInImage.Replace("i", "1"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("I", "l"), inputString) || Regex.IsMatch(textInImage.Replace("l", "I"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("I", "1"), inputString) || Regex.IsMatch(textInImage.Replace("1", "I"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("I", "t"), inputString) || Regex.IsMatch(textInImage.Replace("t", "I"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("0", "o"), inputString) || Regex.IsMatch(textInImage.Replace("o", "0"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("0", "O"), inputString) || Regex.IsMatch(textInImage.Replace("O", "0"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("l", "|"), inputString) || Regex.IsMatch(textInImage.Replace("|", "l"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("I", "|"), inputString) || Regex.IsMatch(textInImage.Replace("|", "I"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("t", "|"), inputString) || Regex.IsMatch(textInImage.Replace("|", "t"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("i", "|"), inputString) || Regex.IsMatch(textInImage.Replace("|", "i"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("M", "II"), inputString) || Regex.IsMatch(textInImage.Replace("II", "M"), inputString) ||
                            Regex.IsMatch(textInImage.Replace("ni", "m"), inputString) || Regex.IsMatch(textInImage.Replace("m", "ni"), inputString))
                        {

                            a.Stop();
                            return true;
                        }
                        else
                            return false;
                    }
                }
                catch (Exception ex)
                {
                    //write the error
                    LogUtils.Write(ex);
                    Program.Finish(true);
                    return false;
                }

            }
        }
示例#38
0
        public parser(Image img, Form1 call)
        {
            baseIMG = img;
            caller = call;
            ocr = new TesseractProcessor();
            ocr.DoMonitor = true;

            //MessageBox.Show(Application.StartupPath+@"\");
            ocr.Init(Application.StartupPath + @"\tessdata", "deu", 0);
        }
示例#39
0
        private static void Recognize()
        {
            string imageFile = @"D:\Self-Study\OpenSources\Tesseract\original\phototest.tif";
            imageFile = @"D:\Self-Study\OpenSources\Tesseract\original\eurotext.tif";

            string tessdata = @"D:\Self-Study\OpenSources\Tesseract\original\tessdata\";
            string language = "eng";
            int oem = 3;

            TesseractProcessor processor = new TesseractProcessor();
            processor.Init(tessdata, language, oem);

            using (Bitmap bmp = Bitmap.FromFile(imageFile) as Bitmap)
            {
                string text = processor.Recognize(bmp);
                Console.WriteLine(
                    string.Format("Text:\n{0}\n", text));
            }
        }
示例#40
0
 private void End()
 {
     if (_ocrProcessor != null)
     {
         _ocrProcessor.End();
         _ocrProcessor = null;
     }
 }
示例#41
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.LoadGeneralSettings();

            _ocrProcessor = new TesseractProcessor();
            _ocrProcessor.DoMonitor = true;

            bool status = _ocrProcessor.Init(_tessData, _lang, _ocrEngineMode);
            Console.WriteLine(string.Format("[DEBUG] Init status: {0}", status));
        }
示例#42
0
        public string UseTesseract(string imgFile)
        {
            this.ErrMsg = string.Empty;
            string defLang = "eng";

            string strResult = string.Empty;
            try
            {
                using (TesseractProcessor processor = new TesseractProcessor())
                {
                    processor.Init(this.TESSDATA, defLang, this.oem);
                    processor.SetPageSegMode((ePageSegMode)Enum.Parse(typeof(ePageSegMode), this.pageSegMode));

            #if DEBUG
                    System.Diagnostics.Debug.WriteLine("processor:");
                    System.Diagnostics.Debug.WriteLine(processor.GetTesseractEngineVersion());
            #endif

                    string strIndicate = Path.GetFileNameWithoutExtension(imgFile);

                    strResult = processor.Recognize(imgFile);
                    if (!string.IsNullOrEmpty(strResult))
                    {
                        // correct common errors caused by OCR
                        strResult = this.CorrectOCRErrors(strResult);
                        // correct letter cases
                        strResult = this.CorrectLetterCases(strResult);
                    }
                }

                strResult = strResult.Replace("\n", Environment.NewLine);
            }
            catch (Exception ex)
            {
                this.ErrMsg = ex.ToString();
                strResult = string.Empty;
            }

            return strResult;
        }
示例#43
0
文件: Form1.cs 项目: chuixue/Gamer
 /*
 private string GetNumber(Bitmap image)
 {
     UnCodebase ud = new UnCodebase(image);
     ud.DealMap2();
     image = ud.bmpobj;
     pictureBox1.Image = image;
     if (!bInitT)
     {
         ocrNumber = new TesseractProcessor();
         bool inited = ocrNumber.Init(@".\", "chi_sim", 3);
         if (!inited) { MessageBox.Show("智能识别引擎初始化失败!"); return ""; }
         ocrNumber.SetVariable("tessedit_char_whitelist", ".,3214567890 ");
     }
     ocrNumber.Clear();
     ocrNumber.ClearAdaptiveClassifier();
     string result = ocrNumber.Recognize(image);
     return result;
 }
  * */
 private string GetChiSim(Bitmap image)
 {
     UnCodebase ud = new UnCodebase(image); 
     ud.DealText();
     image = ud.image;
     //pictureBox1.Image = image; textBox3.Text = ud.txt;
     if (!bInitT)
     {
         ocrText = new TesseractProcessor();
         bInitT = ocrText.Init(@".\", "chi_sim", 3);
         if (!bInitT) { MessageBox.Show("智能识别引擎初始化失败!"); return ""; }
         ocrText.SetVariable("tessedit_char_blacklist", "1234567890μqwertyuiopasdfghjklzxcvbnm'I flU]M.H flO");
     }
     ocrText.Clear();
     ocrText.ClearAdaptiveClassifier();
     string result = ocrText.Recognize(image);
     return result;
 }