Help With OCR

I'm using TesseractDotNet: http://ift.tt/1KGkNzE

I'm getting a strange error: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

 private void readTimer_Tick(object sender, EventArgs e) { Bitmap map = new Bitmap(ScreenshotToDisk()); lastRead = ImageToText(map, 0, 0, 1920, 1080); //823, 511, 149, 23); } Bitmap ScreenshotToDisk() { string path = @"D:\temp\image.png"; Bitmap bitmap = new Bitmap(1920, 1080, PixelFormat.Format32bppRgb); Graphics graphics = Graphics.FromImage(bitmap); graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy); if (File.Exists(path)) File.Delete(path); bitmap.Save(path, ImageFormat.Png); graphics.Dispose(); return bitmap; } string ImageToText(Bitmap bitmap, int x, int y, int width, int height) { string text = ""; TesseractProcessor ocr = new TesseractProcessor(); ocr.Init(@"D:\TEMP\tesseract-ocr\tessdata", "eng", (int)eOcrEngineMode.OEM_DEFAULT); text = ocr.Recognize(bitmap); ocr.Dispose(); return text; } 

by DeathTBO via /r/csharp

Leave a Reply