没有有效的文本识别器:在使用之前初始化OCR引擎,并确保它没有关闭Google vision



我正在尝试实现谷歌视觉文本识别器,以便在我的应用程序中使用相机读取图像上的文本。文本识别在某些时候起作用,并在执行的每个读取的文本代码上返回此错误。

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

谷歌视觉文本识别器代码

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

我也遇到了类似的问题。对我来说,这是卸货时的订单。

MultiDetector.release();
CameraSource.stop();
FaceDetector.release();
BarcodeDetector.release();
TextRecognizer.release();
//here the loading process continues as if it were the first time

然后,这个错误把我吵醒了。

我得到了同样的错误,但我使用的是DexGuard。

它是由DexGuard规则为我修复的:-keepresourcefiles资产/mlkit*/**

相关内容

  • 没有找到相关文章

最新更新