如何从图像Android应用程序提取文本 [英] How to extract text from image Android app

查看:105
本文介绍了如何从图像Android应用程序提取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的Android应用程序开发一项功能.我想从图片中读取文本,然后将该文本保存在数据库中.使用OCR是最好的方法吗?还有另一种方法吗? Google在其文档中建议仅在绝对必要的情况下才应使用NDK,但真正的缺点是什么?

I am working on a feature for my Android app. I would like to read text from a picture then save that text in a database. Is using OCR the best way? Is there another way? Google suggests in its documentation that NDK should only be used if strictly necessary but what are the downfalls exactly?

任何帮助都会很棒.

推荐答案

您可以使用谷歌视觉库将图像转换为文本,它将提供更好的图像输出. 在build gradle中添加以下库:

you can use google vision library for convert image to text, it will give better output from image. Add below library in build gradle:

   compile 'com.google.android.gms:play-services-vision:10.0.0+'

    TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();

Frame imageFrame = new Frame.Builder()

        .setBitmap(bitmap)                 // your image 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();                   // return string
}

这篇关于如何从图像Android应用程序提取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆