我正在使用Firebase ML Kit Text Recognition API并收到在文本识别期间添加的错误:
A/native: image_util_common.cc:2757 Check failed: 'out_pix' Must be non NULL
terminating.
A/native: image_util_common.cc:2797 Check failed: 'out_pix' Must be non NULL
A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 19193 (FirebaseMLHandl)
A/native: terminating.
当我按照建议将图像从转换jpg
为时bmp
,只是错误更改为:
E/zygote: The String#value field is not present on Android versions >= 6.0
E/native: jni_helper.cc:170 GetContents failed: /data/user/0/com.google.android.gms/app_vision/ocr/data/models/rpn_lstm_engine_tfmini.bincfg
E/native: jni_helper.cc:170 GetContents failed: /data/user/0/com.google.android.gms/app_vision/ocr/data/models/semanticlift_engine_0.2.bincfg
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 13092 (ocr_seg_4/13092)
以下是触发 API 的代码:
Uri uri = Uri.fromFile(file);
FirebaseVisionImage image = FirebaseVisionImage.fromFilePath(context, uri);
FirebaseVisionTextDetector detector = FirebaseVision.getInstance().getVisionTextDetector();
Task<FirebaseVisionText> result =
detector.detectInImage(image)
.addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
List<String> words = new ArrayList<>();
@Override
public void onSuccess(FirebaseVisionText firebaseVisionText) {
for (FirebaseVisionText.Block block: firebaseVisionText.getBlocks()) {
Rect boundingBox = block.getBoundingBox();
Point[] cornerPoints = block.getCornerPoints();
String text = block.getText();
Log.d(TAG, "Detected Text: " + text);
for (FirebaseVisionText.Line line: block.getLines()) {
for (FirebaseVisionText.Element element: line.getElements()) {
String textPart = element.getText();
words.add(textPart);
Log.d(TAG, "textPart: " + textPart);
}
}
}
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Task failed with an exception
// ...
}
});