当在Csharp工程中引用方法public OCRResult DetectText(string imagefile),偶尔会提示“引用外部组件错误”,定位出错行语句:int textCount = Detect(Engine, imagefile, out ptrResult)
出错情况重现,使用同步运行结束后,再使用异步委托出现机率就增大,反之也是,请问有遇到过不,有什么解决方法???
追查看来源为以下:
[DllImport("PaddleOCR.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
internal static extern int Detect(IntPtr engine, string imagefile, out IntPtr result);
public OCRResult DetectText(string imagefile)
{
if (!System.IO.File.Exists(imagefile)) throw new Exception($"文件{imagefile}不存在");
IntPtr ptrResult;
int textCount = Detect(Engine, imagefile, out ptrResult);
if (textCount <= 0) return new OCRResult();
if (ptrResult == IntPtr.Zero) return new OCRResult();
OCRResult oCRResult = new OCRResult();
IntPtr ptrFree = ptrResult;
...........