首页 > 解决方案 > 如何从图像中提取特定文本

问题描述

从下图中,我想提取文本 Arzt-Nr (654321161) 下方的数字。
我使用过 OCR 阅读器,但它不是按顺序随机提取文本,因此很难添加逻辑以在“Arzt-Nr”下方提取 no。

我使用了以下代码,但文本不是按顺序排列的。
有什么办法可以做到这一点?

 String text = "";
            for (int i = 0; i < detectedItems.size(); i++) {
                TextBlock item = detectedItems.valueAt(i);
                String detectedText = item.getValue();
                List<Line> lines = (List<Line>) item.getComponents();
                for (Line line : lines) {
                    List<Element> elements = (List<Element>) line.getComponents();
                    for (Element element : elements) {
                        String word = element.getValue();
                        text = text + " " + word;

                    }
                    text += "\n";
                }
            }

在此处输入图像描述

标签: androidocrgoogle-vision

解决方案


使用 tesseract 提取图像的 tsv 输出,并在关键字位置下方找到最近的文本。还可以查看 tesseract 的页面分割模式。

链接到生成 tsv 链接以使用页面分段


推荐阅读