jenly1314 / WeChatQRCode

⛄ 基于OpenCV开源的微信二维码引擎移植的二维码扫码识别库
https://jenly1314.github.io/WeChatQRCode/
Apache License 2.0
607 stars 120 forks source link

识别图片二维码崩溃 #34

Closed wangzhan3429 closed 7 months ago

wangzhan3429 commented 1 year ago
CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.6.0) /home/king/work/opencv/opencv-4.6.0/modules/core/src/matrix_wrap.cpp:2039: error: (-215:Assertion failed) this_v.size() == v.size() in function 'assign'
]
    at org.opencv.wechat_qrcode.WeChatQRCode.detectAndDecode_1(Native Method)
    at org.opencv.wechat_qrcode.WeChatQRCode.detectAndDecode(WeChatQRCode.java:124)
    at com.king.wechat.qrcode.WeChatQRCodeDetector.detectAndDecode(WeChatQRCodeDetector.java:150)
    at com.king.wechat.qrcode.WeChatQRCodeDetector.detectAndDecode(WeChatQRCodeDetector.java:123)
    at WeChatQRCodeActivity$initCameraScan$1$1$1$onResourceReady$1$result$1.invokeSuspend(WeChatQRCodeActivity.kt:71)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
    at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
    Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@39b1097, Dispatchers.Main.immediate]
jenly1314 commented 1 year ago

(-215:Assertion failed) this_v.size() == v.size() in function 'assign'

提供的信息能更详细一点吗?比如:设备型号,系统版本,相关日志,触发此场景的方式等等。

wangzhan3429 commented 1 year ago

不是必现的问题,用的手机型号是红米k60,android13

jenly1314 commented 7 months ago

这个问题大概有结论了,原因是:在识别图片二维码时,所使用的Mat对象没有及时释放;从而在OpenCV处理图像时,由于内存分配失败而抛出此异常;所以解决此问题出现的方式就是:在使用完mat对象后,记得调用:mat.release() 进行释放即可。