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