c# - 我应该如何修复 Tesseract .GetCharacters() throws protected memory 错误

标签 c# .net emgucv

我对 Emgu.CV Tesseract 有疑问。我正在使用提供的代码处理 OCR。

_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   
    }
}

收到以下异常消息:

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>

堆栈跟踪:

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

最佳答案

您可以尝试传递位图数据的副本,而不是直接传递位图。

imgOCR = new Image<Bgr, byte>(panelStream.Image.Bitmap).Copy();

关于c# - 我应该如何修复 Tesseract .GetCharacters() throws protected memory 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54289562/

相关文章:

c# - 桌面屏幕覆盖 - 新窗体闪烁问题

c# - 确定 Windows 8 应用程序何时通过通知启动

c# - CLR 类型的 Object.Equals(objA, objB)、objA.Equals(objB) 和 objA == objB 之间的区别?

.net - Entity Framework 和 .NET 4.0 的 LINQ to SQL 之间有什么区别?

c# - EmguCV 旋转算法不起作用

opencv - 检测图像问题

c# - 在哪里记录异常?

c# - 为什么不允许条件属性方法返回 void 以外的值

c# - EmguCV 的 solvePnPRansac 期望哪些参数类型(明确的,而不是接口(interface))?

c# - 如何在样式中放置 MouseDown 事件?