Exemple #1
0
        private string GetOCR(Bitmap big, Imaging.ImageRange range, bool flag = true)
        {
            Point p      = new Point();
            int   width  = 0;
            int   height = 0;

            p.X    = range.loc.X;
            p.Y    = range.loc.Y;
            width  = range.width;
            height = range.height;

            big = Imaging.CropImage(big, p, width, height);
            big = Imaging.ConvertFormat(big, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
            if (!flag)
            {
                big = Imaging.MakeGrayscale3(big);
            }
            //;
            else
            {
                big = grayscale(big);
            }

            //tessnet2.Tesseract api = new tessnet2.Tesseract();

            //api.Init()
            OcrApi.PathToEngine = Environment.CurrentDirectory + @"\tesseract.dll";
            OcrApi api = OcrApi.Create();

            Languages[] lang = { Languages.English };
            api.Init(lang, null, OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED);
            api.SetVariable("tessedit_char_whitelist", "0123456789");

            string plainText = api.GetTextFromImage(big);

            ////Console.WriteLine(plainText);
            ////this.Invoke(new MethodInvoker(delegate() { txtLog.AppendText(plainText + Environment.NewLine); }));
            api.Dispose();
            api = null;
            System.GC.Collect(0, GCCollectionMode.Forced);
            System.GC.WaitForPendingFinalizers();

            return(plainText);
            //return "";
        }