Ejemplo n.º 1
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (_ocr == null)
            {
                try
                {
                    _ocr = new Tesseract(@FTessdata[0], "eng", Tesseract.OcrEngineMode.OEM_TESSERACT_ONLY);
                }
                catch (Exception exception){

                    FLogger.Log(LogType.Debug, exception.Message);
                }
            }

            if (FInit.IsChanged && FInit[0] == true)
            {

                Image<Bgr, byte> My_Image = new Image<Bgr, byte>(@FInput[0]);
                Image<Gray, byte> gray = My_Image.Convert<Gray, Byte>();
                _ocr.Recognize(gray);
                FOutput[0] = _ocr.GetText();
            }

            //FOutput[0] = "hallo";
        }
Ejemplo n.º 2
0
 private void btnAnalyzeImage_Click(object sender, EventArgs e)
 {
     if(picBox.Image == null)
     {
         MessageBox.Show("Load an image first!");
     }
     else
     {
         statusLabelOCR.Text = "Analyzing invoice image...";
         Task.Run(() =>
         {
             using (var img = new Image<Bgr, byte>(path))
             {
                 string tessdata = Environment.GetEnvironmentVariable("EMGU_ROOT") + @"\bin\tessdata";
                 using (var ocrProvider = new Tesseract(tessdata, "eng", OcrEngineMode.TesseractCubeCombined))
                 {
                     ocrProvider.Recognize(img);
                     string text = ocrProvider.GetText().TrimEnd();
                     rtbOcrResult.Invoke((MethodInvoker)delegate
                                        {
                                            statusLabelOCR.Text = "Analysis completed.";
                                            rtbOcrResult.AppendText(text);
                                        });
                     
                 }
             }
         });
         
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 ///   Initialize a new OCR Object.
 /// 
 ///   This object is a wrapper for the Emgu Tesseract Wrapper to give a level of abstraction
 ///   necessary for scanning shreds
 /// </summary>
 /// <param name="accuracy"> Desired Accuracy setting </param>
 /// <param name="language"> Language of text on image used for OCR model </param>
 /// <param name="enableTimer"> Set enable Timer to true to measure scan time for diagnostic purposes </param>
 public OCR(Accuracy accuracy = Accuracy.High, string language = "eng", bool enableTimer = false)
 {
     _timer = new Stopwatch();
     if (enableTimer)
     {
         _timer.Start();
     }
     Tesseract.OcrEngineMode mode = Tesseract.OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED;
     switch (accuracy)
     {
         case Accuracy.Low:
             mode = Tesseract.OcrEngineMode.OEM_TESSERACT_ONLY;
             break;
         case Accuracy.Medium:
             mode = Tesseract.OcrEngineMode.OEM_CUBE_ONLY;
             break;
         case Accuracy.High:
             mode = Tesseract.OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED;
             break;
     }
     _tesseract = new Tesseract("tessdata", language, mode);
     //"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
     _tesseract.SetVariable("tessedit_unrej_any_wd", "T");
     //_tesseract.SetVariable("tessedit_char_whitelist","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWZ0123456789.,");
     _text = null;
     _chars = null;
     _confidence = -1;
 }
Ejemplo n.º 4
0
        private void InitOcr(String path, String lang, OcrEngineMode mode)
        {
            try
            {
                if (_ocr != null)
                {
                    _ocr.Dispose();
                    _ocr = null;
                }

                if (String.IsNullOrEmpty(path))
                {
                    path = ".";
                }

                TesseractDownloadLangFile(path, lang);
                TesseractDownloadLangFile(path, "osd"); //script orientation detection
                String pathFinal = path.Length == 0 ||
                                   path.Substring(path.Length - 1, 1).Equals(Path.DirectorySeparatorChar.ToString())
                    ? path
                    : String.Format("{0}{1}", path, System.IO.Path.DirectorySeparatorChar);

                _ocr = new Emgu.CV.OCR.Tesseract(pathFinal, lang, mode);
            }
            catch (System.Net.WebException e)
            {
                _ocr = null;
                throw new Exception("Unable to download tesseract lang file. Please check internet connection.", e);
            }
            catch (Exception e)
            {
                _ocr = null;
            }
        }
Ejemplo n.º 5
0
 public EmguOcr()
 {
     _tesseract = new Emgu.CV.OCR.Tesseract
                  (
         Environments.AppConfig.TesseractDataPath,
         Environments.AppConfig.OcrLanguage,
         OcrEngineMode.Default);
 }
Ejemplo n.º 6
0
        public Form1()
        {
            InitializeComponent();

            ocr = new Tesseract();
            ocr.SetVariable("tessedit_char_whitelist", "1234567890");
            ocr.Init(@"D:\", "eng", OcrEngineMode.TesseractOnly);
        }
Ejemplo n.º 7
0
 static void Main(string[] args)
 {
     using (var image = new Image<Bgr, byte>(Path.GetFullPath("text.png")))
     {
         using (var tess = new Tesseract("", "eng", OcrEngineMode.TesseractCubeCombined))
         {
             tess.Recognize(image);
             var text = tess.GetText().TrimEnd();
         }
     }
 }
        /// <summary>
        /// Initializes and creates the tessearct engine
        /// </summary>
        public WrapperTesseract(string path, string lng)
        {
            // Variable value is set to parent directory of tessdata
            //string path = AppDomain.CurrentDomain.BaseDirectory;

            //Path should be same as TESSDATA folder
            //Environment.SetEnvironmentVariable("TESSDATA_PREFIX", path); //This path should always end with a "/" or "\", e.g., TESSDATA_PREFIX="/usr/share/tesseract-ocr/"

            _ocr = new Tesseract(path, lng, Tesseract.OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED);
            ///_ocr = new Tesseract(path, "eng", Tesseract.OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED);
        }
Ejemplo n.º 9
0
        public static void test()
        {
            Tesseract _ocr = new Tesseract(@"C:\Users\yaoyichi\Desktop\emgucv-windows-universal-cuda 2.9.0.1922\", "eng", Tesseract.OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED);

            string dir = @"C:\Users\yaoyichi\Desktop\";
            string fn = "100890509_mc1024_k64.png";
            Image<Bgr, Byte> gray = new Image<Bgr, byte>(dir + fn);
            _ocr.Recognize(gray);
            //TextRecognitionWorker trw = new TextRecognitionWorker();
            //trw.ApplyABBYYOCR(dir, fn);
        }
Ejemplo n.º 10
0
        private void TextRecogniser(Image image)
        {
            Emgu.CV.OCR.Tesseract tesseract = new Emgu.CV.OCR.Tesseract
                                                  (@"F:\Working Pack\c#\Scripter\Scripter\Templates\eng.traineddata", "eng",
                                                  OcrEngineMode.TesseractLstmCombined);
            var tempImg = new Bitmap(image).ToImage <Gray, byte>();

            tesseract.SetImage(tempImg);
            tesseract.Recognize();
            string response = tesseract.GetUTF8Text();

            tesseract.Dispose();
        }
Ejemplo n.º 11
0
 public static Tesseract.Charactor[] DoOcr(Image<Gray, byte> img)
 {
     Tesseract.Charactor[] chars;
     string text;
     using (var tesseract = new Tesseract("tessdata", "eng", Tesseract.OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED)
         )
     {
         tesseract.Recognize(img);
         text = tesseract.GetText();
         chars = tesseract.GetCharactors();
     }
     Console.WriteLine(text);
     Console.ReadLine();
     return chars;
 }
Ejemplo n.º 12
0
 /// <summary>
 ///   Calculates the cost by summing the unique cost of each word
 /// </summary>
 /// <param name="chars"> Tesseract OCR Charactor results </param>
 /// <returns> Cost, where zero is perfect and long.MaxValue is worst </returns>
 public static long Cost(Tesseract.Charactor[] chars)
 {
     if (chars.Length < 1)
     {
         return 0;
     }
     long total = 0;
     double current = -1;
     foreach (Tesseract.Charactor charactor in chars)
     {
         if (Math.Abs(current - charactor.Cost) > 0.0001)
         {
             current = charactor.Cost;
             total += (long)current;
         }
     }
     return total;
 }
Ejemplo n.º 13
0
 private void InitOcr(String path, String lang, OcrEngineMode mode)
 {
    try
    {
       if (_ocr != null)
       {
          _ocr.Dispose();
          _ocr = null;
       }
       _ocr = new Tesseract(path, lang, mode);
       languageNameLabel.Text = String.Format("{0} : {1}", lang, mode.ToString());
    }
    catch (Exception e)
    {
       _ocr = null;
       MessageBox.Show(e.Message, "Failed to initialize tesseract OCR engine", MessageBoxButtons.OK);
       languageNameLabel.Text = "Failed to initialize tesseract OCR engine";
    }
 }
Ejemplo n.º 14
0
        public BotCV(IntPtr win, int Hmin, int Smin, int Vmin, int Hmax, int Smax, int Vmax)
        {
            this.Hmin = Hmin;
            this.Hmax = Hmax;
            this.Smin = Smin;
            this.Smax = Smax;
            this.Vmin = Vmin;
            this.Vmax = Vmax;

            sc          = new ScreenCapture();
            winDiscript = win;

            try
            {
                tess = new Emgu.CV.OCR.Tesseract(@"", "eng", OcrEngineMode.TesseractOnly);
                tess.SetVariable("tessedit_char_whitelist", ".0123456789");
            }
            catch (Exception te)
            {
                Console.WriteLine(te.Message);
                tess = null;
            }
        }
Ejemplo n.º 15
0
        private void button5_Click(object sender, EventArgs e)
        {
            var _ocr = new Tesseract(@"D:\", "eng", OcrEngineMode.TesseractCubeCombined);
            _ocr.SetVariable("tessedit_char_whitelist", "1234567890");

            _ocr.Recognize(_inputArray);

            var result = _ocr.GetCharacters().ToList();

            var sb = new StringBuilder();

            result.ForEach(c => sb.Append(c.Text));

            label1.Text = sb.ToString();
        }
Ejemplo n.º 16
0
 public Form1()
 {
     InitializeComponent();
     _ocr = new Tesseract("", "eng", Tesseract.OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Create a license plate detector
 /// </summary>
 public LicensePlateDetector()
 {
     //create OCR engine
     _ocr = new Tesseract("tessdata", "eng", Tesseract.OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED);
     _ocr.SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZ-1234567890");
 }
Ejemplo n.º 18
0
        //główne operacje na obrazie
        public void ocr()
        {
            //otworzenie pliku
            FileStream srcstream = new FileStream(pic_file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            //stworzenie bitmapy
            Bitmap source = new Bitmap(srcstream);
            //zmiana ustawień webform

            Panel1.Visible = false;
            Image1.Dispose();

            Label2.Text = "Processing...";
            Panel3.Visible = true;

            //Preperation code
            Bitmap ext = source;

            //AForge.Imaging.Filters.
            //Przekształcenie obrazu na skalę odcieni szarości - testować dla obrazów o różnej kolorystyce(opracować system wyznaczania parametrów filtru na podstawie RGB zdjęcia)
            AForge.Imaging.Filters.Grayscale grScl = new AForge.Imaging.Filters.Grayscale(0.2125, 0.0154, 0.0721 );
            source = grScl.Apply(source);
            //Zwiększenie kontrastu
            AForge.Imaging.Filters.ContrastStretch conCor = new AForge.Imaging.Filters.ContrastStretch();

            source = conCor.Apply(source);
            //Wyostrzenie
            AForge.Imaging.Filters.Sharpen shp = new AForge.Imaging.Filters.Sharpen();
            source = shp.Apply(source);

            //Segmentation code
            bool procesed = false;
               // Image2.Width = 350;
               // Image2.Height = (int)((source.Height * 200) / source.Width);

            try
            {
                Emgu.CV.Image<Bgr, Byte> to_rec = new Emgu.CV.Image<Bgr, byte>(source);
                Do_ocr = new Tesseract("tessdata", "eng", Tesseract.OcrEngineMode.OEM_DEFAULT);
                try
                {
                    Do_ocr.Recognize<Bgr>(to_rec);
                    //recognizedText.Text = ocr.GetText();
                    PastOCRBox.Text = Do_ocr.GetText();
                   // StatusBox.Text = "Finished! Ready for next one...";
                    Do_ocr.Dispose();
                    to_rec.Dispose();
                }
                catch (Exception exp)
                {
                    Label2.Text = "Recognition error! " + exp.Message;
                    Do_ocr.Dispose();
                    return;
                }
            }
            catch (Exception exp)
            {
                Label2.Text = "OCR engine failed! " + exp.Message;
                return;
            }

            //czyszczenie z plików tymczasowych

              //  source.Save("D:\\test.bmp");
              //  ext.Save("D:\\testcor.bmp");
            source.Dispose();
            srcstream.Close();
            srcstream.Dispose();
            //System.IO.File.Delete(pic_file);
            System.IO.File.Delete(Server.MapPath("~/img/prev.bmp"));
            System.IO.File.Delete(Server.MapPath("~/img/tmp.bmp"));
            //przygotować wygląd strony po rozpoznawaniu
            Panel3.Visible = false;
            Label1.Visible = false;
            Panel0.Visible = false;
            Panel5.Visible = false;

            Panel4.Visible = true;
        }
Ejemplo n.º 19
0
 public ScreenAnalyzer(string languageCode)
 {
     this.language = Language.codeToLanguage(languageCode);
     ocr = new Tesseract("Assets\\", languageCode, language.OcrMode);
     //ocr.SetVariable("tessedit_char_whitelist", language.OcrWhitelist);
 }
Ejemplo n.º 20
0
        private void server()
        {
            int port = 8001;

            IPAddress ipAd = IPAddress.Parse(ip);

            // use local m/c IP address, and
            // use the same in the client
            ASCIIEncoding asen = new ASCIIEncoding();
            /* Initializes the Listener */
            TcpListener myList = new TcpListener(IPAddress.Any, port);

            Console.WriteLine("The server is running at port 8001...");
            Console.WriteLine("The local End point is  :" +
                              myList.LocalEndpoint);
            /* Start Listeneting at the specified port */

            byte[] b = new byte[2000000];
            myList.Start();

            while (!stoped)
            {
                    char[] recived = new char[2000000];
                    Console.WriteLine("Waiting for a connection.....");

                    TcpClient s = myList.AcceptTcpClient();
                    Console.WriteLine("Connection accepted " +s.Client.RemoteEndPoint);
                    NetworkStream stream = s.GetStream();

                    var reader = new StreamReader(stream);

                    var k = stream.Read(b, 0, 2000000);

                    Console.WriteLine("Recieved...");

                    ImageConverter conv = new ImageConverter();
                    Bitmap rec = new Bitmap((Bitmap)conv.ConvertFrom(b));

                    Console.WriteLine("Recognicion...");
                    Tesseract ocr = new Tesseract("tessdata", "pol+eng", Tesseract.OcrEngineMode.OEM_DEFAULT);

                    ocr.Recognize<Bgr>(new Emgu.CV.Image<Bgr, Byte>(rec));

                    string to_send_str = ocr.GetText();
                    ocr.Dispose();
                    Console.Write(to_send_str + "\n");

                    stream.Write(asen.GetBytes(to_send_str),0,to_send_str.Length);

                    Console.WriteLine("\nSent Acknowledgement");
                    /* clean up */
                    s.Close();

               }
            myList.Stop();
            Console.WriteLine("Server stopped");
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            var files = Directory.GetFiles(@"d:\raw\classified\");

            //var img = new Image<Rgb, byte>(files[0]);
            var img = new Image<Emgu.CV.Structure.Gray, byte>(@"d:\raw\classified\test.jpg");

            var _ocr = new Tesseract(@"D:\", "eng", OcrEngineMode.TesseractCubeCombined);
            _ocr.SetVariable("tessedit_char_whitelist", "1234567890");

            _ocr.Recognize(img);

            var result = _ocr.GetCharacters();
        }
Ejemplo n.º 22
0
 public FaceDetection()
 {
     InitializeComponent();
     _ocr = new Tesseract();
 }
Ejemplo n.º 23
0
        private static void Setup()
        {
            if (!_setup)
            {
                _ocr = new Tesseract("", "eng", Tesseract.OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED);

                // If this is not done cost for any letters recognised which are not letters (i.e. false positives) will be zero
                _ocr.Recognize(new Image<Gray, Byte>("tessdata/OCR initialise data.jpg"));

                for (int i = 0; i < _mapHexColours.Length; i++ )
                {
                    _mapColours.Add(ColorTranslator.FromHtml((_mapHexColours[i])));
                }

                _setup = true;
            }
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Create a license plate detector
 /// </summary>
 /// <param name="dataPath">
 /// The datapath must be the name of the parent directory of tessdata and
 /// must end in / . Any name after the last / will be stripped.
 /// </param>
 public LicensePlateDetector(String dataPath)
 {
    //create OCR engine
    _ocr = new Tesseract(dataPath, "eng", OcrEngineMode.TesseractCubeCombined);
    _ocr.SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZ-1234567890");
 }
 //private TesseractEngine engine;
 public TesseractManager()
 {
     engineJpn = new Emgu.CV.OCR.Tesseract(@"./tessdata", "jpn", OcrEngineMode.LstmOnly);
     engineUma = new Emgu.CV.OCR.Tesseract(@"./tessdata", "uma", OcrEngineMode.LstmOnly);
     //engine = new TesseractEngine(@"./tessdata", "jpn", EngineMode.Default);
 }