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