question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InputImage from "fromMediaImage" method will lead Internal error after feed into FaceDetector while "fromBitmap" work as expected

See original GitHub issue

Platform: Android

Error occurs when feed InputImage from Camera2 by using InputImage.fromMediaImage() into FaceDetector.

com.google.mlkit.common.MlKitException: Internal error has occurred when executing ML Kit tasks at com.google.mlkit.common.sdkinternal.ModelResource.zza(com.google.mlkit:common@@16.0.0:28) at com.google.mlkit.common.sdkinternal.zzn.call(Unknown Source:6) at com.google.mlkit.common.sdkinternal.zzm.run(com.google.mlkit:common@@16.0.0:5) at com.google.mlkit.common.sdkinternal.zzq.run(com.google.mlkit:common@@16.0.0:3) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at com.google.android.gms.internal.mlkit_common.zzb.dispatchMessage(com.google.mlkit:common@@16.0.0:6) at android.os.Looper.loop(Looper.java:359) at android.os.HandlerThread.run(HandlerThread.java:67) Caused by: java.lang.IllegalStateException: Image is already closed at android.media.Image.throwISEIfImageIsInvalid(Image.java:72) at android.media.ImageReader$SurfaceImage$SurfacePlane.getBuffer(ImageReader.java:965) at com.google.android.gms.vision.Frame$Builder.setPlanes(com.google.android.gms:play-services-vision-common@@19.1.0:14) at com.google.mlkit.vision.face.internal.zza.zza(com.google.android.gms:play-services-mlkit-face-detection@@16.0.0:56) at com.google.mlkit.vision.face.internal.zza.zza(com.google.android.gms:play-services-mlkit-face-detection@@16.0.0:85) at com.google.mlkit.vision.face.internal.zza.run(com.google.android.gms:play-services-mlkit-face-detection@@16.0.0:164) at com.google.mlkit.vision.common.internal.MobileVisionBase.zza(com.google.mlkit:vision-common@@16.0.0:23) at com.google.mlkit.vision.common.internal.zzb.call(Unknown Source:4) at com.google.mlkit.common.sdkinternal.ModelResource.zza(com.google.mlkit:common@@16.0.0:26) at com.google.mlkit.common.sdkinternal.zzn.call(Unknown Source:6)  at com.google.mlkit.common.sdkinternal.zzm.run(com.google.mlkit:common@@16.0.0:5)  at com.google.mlkit.common.sdkinternal.zzq.run(com.google.mlkit:common@@16.0.0:3)  at android.os.Handler.handleCallback(Handler.java:883)  at android.os.Handler.dispatchMessage(Handler.java:100)  at com.google.android.gms.internal.mlkit_common.zzb.dispatchMessage(com.google.mlkit:common@@16.0.0:6)  at android.os.Looper.loop(Looper.java:359)  at android.os.HandlerThread.run(HandlerThread.java:67) 

In contrast, If convert preview frame to bitmap then create InputImage by using fromBitmap, everything works fine.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
cs-googlercommented, Jan 20, 2021

Hi, the image is used for processing in the ML pipeline. You should close it in the detector’s onComplete() listener instead to make sure the pipeline does not need it anymore.

0reactions
BeastwareBoomcommented, Aug 20, 2020

Hey @calren, I had the same problem. And below is some code snippets. Image image = reader.acquireLatestImage(); InputImage inputImage = InputImage.fromMediaImage(image, 0); image.close(); //handle inputImage here

Read more comments on GitHub >

github_iconTop Results From Across the Web

InputImage | ML Kit - Google Developers
Creates an InputImage from an Image object, e.g., what you obtained from android.
Read more >
inputImage.getByteBuffer() is null when using AndroidX ...
The error.getCause() returns java.lang.NullPointerException: Attempt to invoke virtual method 'java.nio.ByteBuffer android.media.Image$Plane.
Read more >
FaceDetector fails when InputImage.fromBitmap() has non ...
I am trying to detect faces from a bitmap and my image rotation is set to 90, whenever that happens the detector fails....
Read more >
How to Develop a Face Recognition System Using FaceNet in ...
In this tutorial, you will discover how to develop a face detection system using FaceNet and an SVM classifier to identify people from ......
Read more >
On-Device Face Detection on Android using Google's ML Kit
After that, we call process on the face detector, which passes the input image as a parameter. We also use the onSuccessListener to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found