Beispiel #1
0
        private static string TextOcrE(Bitmap image)
        {
            string plainText = "";

            using (var bmp = image)
            {
                plainText = mBidApi.GetTextFromImage(bmp);
            }

            return(plainText.Trim());
        }
Beispiel #2
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 "";
        }
Beispiel #3
0
        private int GetNumber(Point pos, Size size, Func <Bitmap, Bitmap> cut)
        {
            var bitmap = Screenshot.GetRelativeScreenshot(pos, size, _pokerHandle);

            try
            {
                bitmap = cut(bitmap);
            }
            catch (ArgumentOutOfRangeException)
            {
                return(0);
            }

            string d = _api.GetTextFromImage(bitmap);

            var regex       = new Regex(@"(\d)+((\.)(\d)+)*");
            var match       = regex.Match(d);
            var matchString = match.Value;

            matchString = matchString.Replace(".", "");

            return(int.Parse(matchString));
        }