簡體   English   中英

cascadeClassifier.detectMultiScale 得到錯誤:OutOfMemoryError 中的 memory 不足

[英]cascadeClassifier.detectMultiScale get error: Insufficient memory in OutOfMemoryError

大家好我有以下代碼:

public boolean isContainsFace(String path){
        Mat matImage = Imgcodecs.imread(path);

        MatOfRect faceDetections = new MatOfRect();
        cascadeClassifier.detectMultiScale(matImage, faceDetections);

        return !faceDetections.empty();
    }

我用它來檢查照片中是否有面孔。 那是當我嘗試一張比平常大的照片時,出現以下錯誤:

E/cv::error(): OpenCV(4.6.0-dev) Error: Insufficient memory (Failed to allocate 1281229312 bytes) in OutOfMemoryError, file E:/OpenCV/opencv/modules/core/src/alloc.cpp, line 73
E/org.opencv.objdetect: objdetect::detectMultiScale_15() caught cv::Exception: OpenCV(4.6.0-dev) E:/OpenCV/opencv/modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 1281229312 bytes in function 'OutOfMemoryError'
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.findyourselfinthephoto, PID: 25403
    CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.6.0-dev) E:/OpenCV/opencv/modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 1281229312 bytes in function 'OutOfMemoryError'
    ]
        at org.opencv.objdetect.CascadeClassifier.detectMultiScale_5(Native Method)
        at org.opencv.objdetect.CascadeClassifier.detectMultiScale(CascadeClassifier.java:195)
        at com.example.findyourselfinthephoto.Helpers.PhotoHelper.isContainsFace(PhotoHelper.java:41)
        at com.example.findyourselfinthephoto.Fragments.Home.onRequestHandlePathOz(Home.java:164)
        at br.com.onimur.handlepathoz.utils.HandlePathOzUtils$getRealPath$1.invokeSuspend(HandlePathOzUtils.kt:107)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:33)
        at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
        Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@e6b34af, Dispatchers.Main]

我應該怎么做才能解決這個問題?

嘗試將AndroidManifest.xml文件中的memory設置android:largeHeap屬性設置為true

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM