【发布时间】:2019-03-28 07:48:56
【问题描述】:
我使用 Google OCR API 开发了一个可以从扫描图像中读取文本的应用程序。我想将文本存储在数据库中。我想要完整的代码从图像中读取文本并将其存储在数据库中。
【问题讨论】:
-
到目前为止,您是否尝试过任何方法来存储这些值? Stackoverflow 不是免费的编码服务。
我使用 Google OCR API 开发了一个可以从扫描图像中读取文本的应用程序。我想将文本存储在数据库中。我想要完整的代码从图像中读取文本并将其存储在数据库中。
【问题讨论】:
以下代码有助于从图像中提取文本
`implementation 'com.google.android.gms:play-services-vision:17.0.2'
TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();
Frame imageFrame = new Frame.Builder()
.setBitmap(bitmap)
.build();
String imageText = "";
SparseArray<TextBlock> textBlocks = textRecognizer.detect(imageFrame);
for (int i = 0; i < textBlocks.size(); i++) {
TextBlock textBlock = textBlocks.get(textBlocks.keyAt(i));
imageText = textBlock.getValue();
}`
$imageText 返回可以转储到数据库的文本
【讨论】: