【发布时间】:2020-03-28 18:35:15
【问题描述】:
我正在开发一个应用程序来从营养事实中提取文本。通过使用 MLkit firebase 我实现了这一点,但我有一个问题是文本没有以与图像中相同的格式显示。这是我的文本识别代码。
// ----TextRecognizer START ---
BitmapDrawable bitmapDrawable = (BitmapDrawable) mPreview.getDrawable();
Bitmap bitmap = bitmapDrawable.getBitmap();
final FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
FirebaseVisionCloudTextRecognizerOptions options = new FirebaseVisionCloudTextRecognizerOptions.Builder()
.setLanguageHints(Arrays.asList("en", "ar"))
.build();
// [END set_detector_options_cloud]
// [START get_detector_cloud]
// Or, to change the default settings:
FirebaseVisionTextRecognizer detector = FirebaseVision.getInstance()
.getCloudTextRecognizer(options);
// [END get_detector_cloud]
// [START run_detector_cloud]
Task<FirebaseVisionText> result2 = detector.processImage(image)
.addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
@Override
public void onSuccess(FirebaseVisionText result) {
// Task completed successfully
// [START_EXCLUDE]
// [START get_text_cloud]
StringBuilder sb = new StringBuilder();
for (FirebaseVisionText.TextBlock block : result.getTextBlocks()) {
if (result.getTextBlocks().size() == 0){
mResultEt.setText("NO Text Found");
}else {
Rect boundingBox = block.getBoundingBox();
Point[] cornerPoints = block.getCornerPoints();
String text = block.getText();
for (FirebaseVisionText.Line line: block.getLines()) {
sb.append(line.getText());
sb.append("\n");
for (FirebaseVisionText.Element element: line.getElements()) {
}
}
}
}
mResultEt.setText(sb);
// [END get_text_cloud]
// [END_EXCLUDE]
This is an image I want to extract the text from this is the result but the format not as the image
我通过添加新行或标签尝试了不同的解决方案,但都是一样的。
顺便说一下,我想用图中的数字来做一些计算。
如果有人可以帮助我,我将不胜感激。
【问题讨论】:
标签: java android ocr firebase-mlkit