先看效果图
我主要是识别截图,所以图片比较规范,识别率应该很高。
![Screenshot_2017-03-17-16-53-25-879_com.sunlinlin..png](http://upload-images.jianshu.io/upload_images/2062943-5e205d16418fb691.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
简介什么都不说了,直接看简单的用法吧
首先肯定是引入依赖了
dependencies {
compile 'com.rmtheis:tess-two:6.2.0'
}
简单的用法其实就几行代码:
TessBaseAPI tessBaseAPI = new TessBaseAPI();
tessBaseAPI.init(DATAPATH, DEFAULT_LANGUAGE);//参数后面有说明。
tessBaseAPI.setImage(bitmap);
String text = tessBaseAPI.getUTF8Text();
就这样简单的把一个bitmap设置进去,就能识别到里面的文字并输出了。
但是真正用的时候还是遇到了点麻烦,虽然只是简单的识别。
主要是tessBaseAPI.init(DATAPATH, DEFAULT_LANGUAGE)这个方法容易出错。
先看一下这个方法的源码吧:
public boolean init(String datapath, String language) {
return init(datapath, language, OEM_DEFAULT);
}
/**
* Initializes the Tesseract engine with the specified language model(s). Returns
* true
on success.
*
* @see #init(String, String)
*
* @param datapath the parent directory of tessdata ending in a forward
* slash
* @param language an ISO 639-3 string representing the language(s)
* @param ocrEngineMode the OCR engine mode to be set
* @return true
on success
*/
public boolean init(String datapath, String language, int ocrEngineMode) {
if (datapath == null)
throw new IllegalArgumentException("Data path must not be null!");
if (!datapath.endsWith(File.separator))
datapath += File.separator;
File datapathFile = new File(datap