You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
相同的C#代码,在C#中正常运行,但是在Unity中当运行
using (PaddleOcrAll all = new PaddleOcrAll(model, PaddleDevice.Mkldnn())
{
AllowRotateDetection = true, /* 允许识别有角度的文字 /
Enable180Classification = false, / 允许识别旋转角度大于90度的文字 */
})
{
using (Mat src2 = Cv2.ImRead(imagePath))
{
PaddleOcrResult result = all.Run(src2);
Console.WriteLine(result.Text);
}
}
当运行到PaddleOcrResult result = all.Run(src2);这一句时,Unity就会直接崩溃,崩溃的理由常常为:
[13:23:58] NullReferenceException: Object reference not set to an instance of an objectSdcb.Paddlelnference.PaddlePredictor,Dispose () (at :0)
或者
[13:16:04] NullReferenceException: Object reference not set to an instance of an objectSdcb.PaddleOcR.PaddleOcrRecognizer.RunMulti (OpenCvSharp.Matl srcs) (at<188060b8ee2042faa7387d837ea111ad>:0)
Describe the bug
相同的C#代码,在C#中正常运行,但是在Unity中当运行
using (PaddleOcrAll all = new PaddleOcrAll(model, PaddleDevice.Mkldnn())
{
AllowRotateDetection = true, /* 允许识别有角度的文字 /
Enable180Classification = false, / 允许识别旋转角度大于90度的文字 */
})
{
using (Mat src2 = Cv2.ImRead(imagePath))
{
PaddleOcrResult result = all.Run(src2);
Console.WriteLine(result.Text);
}
}
当运行到PaddleOcrResult result = all.Run(src2);这一句时,Unity就会直接崩溃,崩溃的理由常常为:
[13:23:58] NullReferenceException: Object reference not set to an instance of an objectSdcb.Paddlelnference.PaddlePredictor,Dispose () (at :0)
或者
[13:16:04] NullReferenceException: Object reference not set to an instance of an objectSdcb.PaddleOcR.PaddleOcrRecognizer.RunMulti (OpenCvSharp.Matl srcs) (at<188060b8ee2042faa7387d837ea111ad>:0)
我考虑可能是不是
(1)Sdcb.PaddleOCR 可能在内部开启了自己的线程,导致线程资源在 Unity 退出时未正确清理?
(2)Unity 的垃圾回收可能没有及时回收一些临时对象,导致内存泄漏或资源冲突?
因此以此猜想出发,我引入了UnityMainThreadDispatcher这个插件,使代码在Unity主线程中运行,这回大概率可以成功的进行识别(小概率崩溃),而当退出程序后,或者重新打开程序后,就会100%崩溃。
Steps to reproduce the bug
null
Expected behavior
null
Screenshots
null
Release version
No response
IDE
No response
OS version
No response
Additional context
null
The text was updated successfully, but these errors were encountered: