【问题标题】:Image to text with same format - MLkit firebase具有相同格式的图像到文本 - MLkit firebase
【发布时间】: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


    【解决方案1】:

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

    假设“Serving Size”和“1 Can”具有相似的 X 轴,那么您可能希望将它们组合在一起。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 2019-02-25
      • 1970-01-01
      相关资源
      最近更新 更多