Skip to content

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

Closed

Description

@rideflag-yankai-tian

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.

Activity

  1. thatfiredev commented on Jun 4, 2020

    @thatfiredev

    @rideflag-yankai-tian it would be helpful if you could provide a Minimum Complete Verifiable Example Code so that we can see how you're using fromMediaImage().

  2. added
    bug-library
    on Jun 6, 2020
  3. cs-googler commented on Jun 8, 2020

    @cs-googler

    Hi, could you provide some code snippets that show where you call image.close()? It is likely that you close the image too soon before mlkit is done with processing it.

  4. calren commented on Jun 16, 2020

    @calren
    Collaborator

    Hey @rideflag-yankai-tian, have you gotten a chance to follow up on this yet? This seems like a problem around when image.close() is called, so we were hoping you could provide the relevant code snippets to help us verify that.

  5. calren commented on Jul 17, 2020

    @calren
    Collaborator

    Hey @rideflag-yankai-tian , this issue hasn't had any activity for a month, so we'll consider it resolved for now! Feel free to reopen this issue if you are still able to reproduce it

  6. Byte-Snipper commented on Aug 20, 2020

    @Byte-Snipper

    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

  7. cs-googler commented on Jan 20, 2021

    @cs-googler

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    androidbug-library

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions