1

i am trying to implement Google vision text recognizer to read text on image with camera in my app. The text recognition works for some times and returns this error on every read text code executed.

E/native: jni_helper.cc:760 No valid text recognizer: initialize the OCR engine before use, and make sure it has not been shut down.
D/skia: onFlyCompress
E/native: jni_helper.cc:760 No valid text recognizer: initialize the OCR engine before use, and make sure it has not been shut down.
D/skia: onFlyCompress
E/native: jni_helper.cc:760 No valid text recognizer: initialize the OCR engine before use, and make sure it has not been shut down.
D/skia: onFlyCompress

The Google vision text recognizer code

textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();

        if (textRecognizer.isOperational()) {
            cameraSource = new CameraSource.Builder(getApplicationContext(), textRecognizer)
                    .setFacing(CameraSource.CAMERA_FACING_BACK)
                    .setRequestedPreviewSize(1280, 720)
                    .setAutoFocusEnabled(true)
                    .setRequestedFps(2.0f)
                    .build();

            surface_view.getHolder().addCallback(new SurfaceHolder.Callback() {
                @Override
                public void surfaceCreated(SurfaceHolder holder) {
                    try {
                        cameraSource.start(surface_view.getHolder());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }

                @Override
                public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

                }

                @Override
                public void surfaceDestroyed(SurfaceHolder holder) {
                    cameraSource.stop();
                }
            });

            textRecognizer.setProcessor(new Detector.Processor<TextBlock>() {
                @Override
                public void release() {
                    Toast.makeText(getApplicationContext(), "surface released", Toast.LENGTH_LONG).show();
                }

                @Override
                public void receiveDetections(Detector.Detections<TextBlock> detections) {
                    final SparseArray<TextBlock> items = detections.getDetectedItems();
                    if (items.size() != 0) {

                        final StringBuilder stringBuilder = new StringBuilder();
                        for (int i = 0; i < items.size(); i++) {
                            TextBlock item = items.valueAt(i);
                            stringBuilder.append(item.getValue());
                            stringBuilder.append(",");
                        }


                        captured_txt.post(new Runnable() {
                            @Override
                            public void run() {

                                String[] sbuilerArray = stringBuilder.toString().split(",");


                                for (String s : sbuilerArray) {
                                    Log.d("Textarray", s);
                                    if (s.trim().length() >= 12 && s.trim().matches("[0-9 ]*")) {
                                     
                                        ScannedAirtime(s);

                                        cameraSource.stop();
                                    }
                                }

                            }
                        });
                    }
                }
            });
        } else {
            Log.d("Airtime Topup:", "Detector dependencies are not available");
        }
Daniel Nyamasyo
  • 2,152
  • 1
  • 24
  • 23
  • I think it was caused by some Proguard or Dexguard effect because it works fine in debug version and I got the same error in the release version. can you find any solution? – hkh114 Jul 10 '22 at 12:52

2 Answers2

0

I had a similar problem. For me, it was the order, when unloading.

MultiDetector.release();
CameraSource.stop();
FaceDetector.release();
BarcodeDetector.release();
TextRecognizer.release();

//here the loading process continues as if it were the first time

Then, the error woke me up.

skynetch
  • 722
  • 11
  • 21
0

I got the same error but I'm using DexGuard.

It was fixed for me by this DexGuard rules: -keepresourcefiles assets/mlkit*/**

hkh114
  • 162
  • 1
  • 3
  • 15