Android CameraX-ImageCapture返回的ImageProxy无效

Android CameraX-ImageCapture返回的ImageProxy无效,android,firebase,firebase-mlkit,android-camerax,Android,Firebase,Firebase Mlkit,Android Camerax,我使用CameraX拍摄图像,然后使用Firebase ML工具包识别文本 当我们拍摄照片时,CameraX从ImageCapture返回ImageProxy imageCapture.takePicture(Executors.newSingleThreadExecutor(), new ImageCapture.OnImageCapturedListener() { @Override public void onCapture

我使用CameraX拍摄图像,然后使用Firebase ML工具包识别文本

当我们拍摄照片时,CameraX从ImageCapture返回ImageProxy

imageCapture.takePicture(Executors.newSingleThreadExecutor(), new ImageCapture.OnImageCapturedListener() {
                @Override
                public void onCaptureSuccess(ImageProxy image, int rotationDegrees) {
                    super.onCaptureSuccess(image, rotationDegrees);

                    startTextRecognization(image, rotationDegrees);
                }

                @Override
                public void onError(@NonNull ImageCapture.ImageCaptureError imageCaptureError, @NonNull String message, @Nullable Throwable cause) {
                    super.onError(imageCaptureError, message, cause);

                }
            });
将该图像传递给Firebase-

public void startTextRecognizing(ImageProxy imageProxy, int rotationDegrees) {
    this.imageProxy = imageProxy;
    this.rotationDegrees = rotationDegrees;

    if (imageProxy == null || imageProxy.getImage() == null) {
        return;
    }

    Image mediaImage = imageProxy.getImage();
    FirebaseVisionImage firebaseVisionImage =
            FirebaseVisionImage.fromMediaImage(mediaImage, rotationDegrees);

    FirebaseVisionTextRecognizer detector = FirebaseVision.getInstance()
            .getOnDeviceTextRecognizer();

    Task<FirebaseVisionText> result =
            detector.processImage(firebaseVisionImage)
                    .addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
                        @Override
                        public void onSuccess(FirebaseVisionText firebaseVisionText) {
                            extractText(firebaseVisionText);
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Log.d("*Rahul", "Text Recognization Failed");
                        }
                    });

    //result.getResult();

}
你能帮忙吗,我哪里做错了?ImageCapture返回的图像格式无效。

当您调用super.onCaptureSccessImages,rotationDegrees时,它会关闭图像,因此可以在文本识别方法之后移动图像,或者删除该行,稍后通过调用image.close自己关闭图像

离题-你在用什么?我在最新的库版本中找不到ImageCapture.OnImageCapturedListener类。您应该使用可用的最新版本,因为它仍在alpha中,而且核心api正在更改,尽管开发人员说,当时最新的alpha 10已接近beta版,因此核心api现在应该不会有太大更改。

当您调用super.onCaptureSuccessuccessImage时,旋转度会关闭图像,因此,可以在文本识别方法之后移动它,也可以删除该行,稍后通过调用image.close自己关闭图像

离题-你在用什么?我在最新的库版本中找不到ImageCapture.OnImageCapturedListener类。你应该使用最新的版本,因为它仍然在alpha版本中,而且核心api正在变化,尽管开发人员说当时最新的版本alpha10已经接近beta版本,所以核心api现在应该不会有太大的变化

issue capture request for camera 0
2020-02-12 18:27:27.497 6788-6842/com.example.myapplication D/CaptureSession: Issuing capture request.
2020-02-12 18:27:27.786 6788-7173/com.example.myapplication D/*Rahul:  Success Fully Captured - 
2020-02-12 18:27:27.794 6788-6788/com.example.myapplication D/AndroidRuntime: Shutting down VM


--------- beginning of crash
2020-02-12 18:27:27.795 6788-6788/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 6788
java.lang.IllegalStateException: Image is already closed
    at android.media.Image.throwISEIfImageIsInvalid(Image.java:72)
    at android.media.ImageReader$SurfaceImage.getFormat(ImageReader.java:819)
    at com.google.firebase.ml.vision.common.FirebaseVisionImage.fromMediaImage(com.google.firebase:firebase-ml-vision@@24.0.1:6)
    at com.example.myapplication.TextRocognizationHelper.startTextRecognizing(TextRocognizationHelper.java:40)
    at com.example.myapplication.CameraActivity$3.run(CameraActivity.java:198)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)


--------- beginning of system