您的位置首页生活百科

如何通过Tesseract开源OCR引擎创建Android

如何通过Tesseract开源OCR引擎创建Android

的有关信息介绍如下:

如何通过Tesseract开源OCR引擎创建Android

Tesseract Android Tools

要编译Android平台的Tesseract,需要使用Google提供的tesseract-android-tools。

代码获取方式:

构造函数中需要在存储卡上创建一个目录tessdata,如果不创建程序运行就会出错。因为源码中会检测这个目录,不存在就抛出异常:

public boolean init(String datapath, String language) {

if (datapath == null) {

throw new IllegalArgumentException("Data path must not be null!");

}

if (!datapath.endsWith(File.separator)) {

datapath += File.separator;

}

File tessdata = new File(datapath + "tessdata");

if (!tessdata.exists() || !tessdata.isDirectory()) {

throw new IllegalArgumentException("Data path must contain subfolder tessdata!");

}

return nativeInit(datapath, language);

}

就这么简单。现在通过三种方式获取图片做OCR:

在图库中选取一张图,选择发送或者分享,选择OCR应用

在AndroidManifest.xml中加入IntentFilter,让OCR应用出现在图库的分享列表中: