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();
        }
Example #2
0
        private void DoOCR(IImage image)
        {
            ClearRenderingData();

            string variable  = "tessedit_pageseg_mode";
            int    storedOSD = 0;

            _ocrProcessor.GetIntVariable(variable, ref storedOSD);
            try
            {
                // Fully automatic page segmentation
                int fully_psm_auto = 3;
                _ocrProcessor.SetVariable(variable, fully_psm_auto.ToString());



                ///// DEMO ONLY
                using (Image bitmap = ToImage(image))
                {
                    ///// DEMO ONLY
                    _ocrProcessor.Clear();
                    _ocrProcessor.ClearAdaptiveClassifier();
                    BlockList blocks = _ocrProcessor.DetectBlocks(bitmap);
                    this.UpdateImageViewer(blocks);


                    ///// DEMO ONLY
                    _ocrProcessor.Clear();
                    _ocrProcessor.ClearAdaptiveClassifier();
                    string      result        = _ocrProcessor.Apply(bitmap);
                    List <Word> detectedWords = _ocrProcessor.RetriveResultDetail();
                    this.UpdateImageViewer(detectedWords);

                    if (!string.IsNullOrEmpty(result))
                    {
                        MessageBox.Show(result);
                    }
                }
            }
            catch
            {
            }
            finally
            {
                _ocrProcessor.SetVariable(variable, storedOSD.ToString());
            }


            //_ocrProcessor.Clear();
            //_ocrProcessor.ClearAdaptiveClassifier();

            //using (Image bitmap = ToImage(image))
            //{
            //    //string result = _ocrProcessor.Apply(_fileName);
            //    string result = _ocrProcessor.Apply(bitmap);

            //    List<Word> detectedWords = _ocrProcessor.RetriveResultDetail();
            //    this.UpdateImageViewer(detectedWords);

            //    if (!string.IsNullOrEmpty(result))
            //        MessageBox.Show(result);
            //}
        }
Example #3
0
        private void button2_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();
            _ocrProcessor.UseROI = false;
            imageViewer1.RectA   = new Rectangle(0, 0, 0, 0);

            //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);

            Console.WriteLine(string.Format("[DEBUG] Init status: {0}", status));

            //string text = _ocrProcessor.Recognize(mg);
            //MessageBox.Show(text);

            ////**************************************************** converts 1bpp to 24bpp
            //Bitmap image = new Bitmap(@"e:\\test11.tif");
            //Bitmap bitmap = new Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            //for (int i = 0; i < image.Width; i++)
            //{
            //    for (int j = 0; j < image.Height; j++)
            //    {
            //        Color temp = image.GetPixel(i, j);
            //        bitmap.SetPixel(i, j, temp);
            //    }
            //}
            //bitmap.Save(@"e:\\test24.tif", System.Drawing.Imaging.ImageFormat.Bmp);
            //Image mg1 = Image.FromFile("e:\\test24.tif");
            ////******************************************************************************************************


            string variable = "tessedit_pageseg_mode";

            // Fully automatic page segmentation
            int fully_psm_auto = 3;

            _ocrProcessor.SetVariable(variable, fully_psm_auto.ToString());

            ///// DEMO ONLY
            //_ocrProcessor.Clear();
            //_ocrProcessor.ClearAdaptiveClassifier();

            //BlockList blocks = _ocrProcessor.DetectBlocks(mg);
            //this.UpdateImageViewer(blocks);

            _ocrProcessor.Clear();
            _ocrProcessor.ClearAdaptiveClassifier();

            string      result        = _ocrProcessor.Apply(mg);
            List <Word> detectedWords = _ocrProcessor.RetriveResultDetail();

            this.UpdateImageViewer(detectedWords);

            //MessageBox.Show(result);
            button3.Enabled = true;
            button4.Enabled = true;
        }