0

我正在尝试实现 Google 视觉文本识别器,以便在我的应用程序中使用相机读取图像上的文本。文本识别工作了一段时间,并在每次执行读取的文本代码时返回此错误。

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

Google 视觉文本识别器代码

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");
        }
4

1 回答 1

0

我有一个类似的问题。对我来说,这是卸载时的顺序。

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

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

然后,错误唤醒了我。

于 2020-12-23T14:12:46.997 回答