下面的代码是:
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]
我该怎么做才能解决这个问题?
1条答案
按热度按时间bfnvny8b1#
尝试增加内存量,将AndroidManifest.xml文件中的android:largeHeap属性设置为true