gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:26:27 30 4
gpt4 key购买 nike

我对 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com