gpt4 book ai didi

java - 具有相同格式的图像到文本 - MLkit firebase

转载 作者:行者123 更新时间:2023-12-02 08:49:01 26 4
gpt4 key购买 nike

我正在开发一个应用程序来从营养成分中提取文本。通过使用 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

我通过添加新行或选项卡尝试了不同的解决方案,但结果是相同的。

顺便说一句,我想用图像中的数字来做一些计算。

如果有人能帮助我,我将不胜感激。

最佳答案

ML Kit 目前不会自动检测布局。但每个检测到的文本都有自己的坐标。一种解决方案是使用 text coordinates手动检测决定布局。

假设“份量”和“1 jar ”具有相似的 X 轴,那么您可能需要将它们分组在一起。

关于java - 具有相同格式的图像到文本 - MLkit firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60905234/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com