I have problem with Emgu.CV Tesseract. I am working on an OCR using the provided code.
_ocr = new Tesseract();
_ocr.SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZ-1234567890");
_ocr.Init(@"./tessdata", "eng", OcrEngineMode.TesseractLstmCombined);
using (imgOCR = new Image<Bgr, byte>(panelStream.Image.Bitmap))
{
using (_ocr)
{
var ocr = _ocr.Recognize();
var characters = _ocr.GetCharacters();
foreach (Tesseract.Character c in characters)
{
CvInvoke.Rectangle(imgOCR, c.Region, new MCvScalar(255, 0, 0));
}
//String messageOcr = _ocr.GetText().TrimEnd('\n', '\r'); // remove end of line from ocr-ed text
}
}
Getting the following exception message:
System.AccessViolationException HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an
indication that other memory is corrupt. Source=<Cannot evaluate the
exception source> StackTrace: <Cannot evaluate the exception stack
trace>
Stack Trace:
at Emgu.CV.OCR.OcrInvoke.TessBaseAPIExtractResult(IntPtr ocr, IntPtr charSeq, IntPtr resultSeq)
at Emgu.CV.OCR.Tesseract.GetCharacters()
at scenarioA.Form1.ocReader() in E:\\Semester1\\Image Processing\\Assig2\\scenarioA\\scenarioA\\Form1.cs:line >177
at scenarioA.Form1.ProcessFrame(Object sender, EventArgs e) in E:\\Semester1\\Image Processing\\Assig2\\scenarioA\\scenarioA\\Form1.cs:line 84
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 >reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at >System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form >mainForm)
at scenarioA.Program.Main() in E:\\Semester1\\Image Processing\\Assig2\\scenarioA\\scenarioA\\Program.cs:line 19
Instead of directly passing you bitmap you can try to pass a copy of the bitmap data.
imgOCR = new Image<Bgr, byte>(panelStream.Image.Bitmap).Copy();
User contributions licensed under CC BY-SA 3.0