OCR的文本对齐问题

问题描述 投票:0回答:1

我创建了一个用于从图像扫描文本并将其写入textview的应用程序,该应用程序可成功用于单列数据,但是如果是多列,它将随机读取列,并且打印方式与表格视图不同,出现原始图像。我使用了Google视觉api并将文本解析为textblock(SparseArray<Textblock>)类型的SparseArray。

输出扫描图像的屏幕截图:“扫描图像的输出屏幕截图”

 Frame frame=new Frame.Builder().setBitmap(bitmap).build();
                SparseArray<TextBlock> textBlocks = recognizer.detect(frame);
                String blocks = "";
                String lines = "";
                String words = "";
                for (int index = 0; index < textBlocks.size(); index++) {
                    //extract scanned text blocks here
                    TextBlock tBlock = textBlocks.valueAt(index);
                    blocks = blocks + tBlock.getValue() + "\n" + "\n";
                    for (Text line : tBlock.getComponents()) {
                        //extract scanned text lines here
                        lines = lines + line.getValue() + "\n";
                        for (Text element : line.getComponents()) {
                            //extract scanned text words here
                            words = words + element.getValue() + ", ";
                        }
                    }
                }
                if (textBlocks.size() == 0) {
                    etresult.setText("Scan Failed: Found nothing to scan");
                } else {
                    etresult.setText(etresult.getText() + "Blocks: " + "\n");
                    etresult.setText(etresult.getText() + blocks + "\n");

                    saveToInternalStorage(bitmap);
                }

[我创建了一个用于从图像扫描文本并将其写入textview的应用程序,它成功地处理了单列数据,但是如果是多列,它会随机读取列,而不是...

android android-studio textblock
1个回答
0
投票
经过上面的代码后,我可以看到OCR应该扫描图像并检测文本,而不是像表及其列那样的文本对齐方式。但是你可以使用边界框识别对齐方式,边界框给出左上,右上,左下,右下坐标。请仔细阅读Google Cloud Vision API文档。 https://cloud.google.com/vision/docs/ocr
© www.soinside.com 2019 - 2024. All rights reserved.