Android汉字识别,tess_two Android图片文字识别

先看效果图

我主要是识别截图,所以图片比较规范,识别率应该很高。

cc9ae05423a8

![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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值