Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能否用在Unity中呢? #111

Open
PlanesWalkerZXY opened this issue Dec 14, 2024 · 0 comments
Open

能否用在Unity中呢? #111

PlanesWalkerZXY opened this issue Dec 14, 2024 · 0 comments

Comments

@PlanesWalkerZXY
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant