android eng,android – 无法使用language = eng初始化Tesseract API

我正在开发一款需要OCR的

Android应用.我决定使用

Tesseract作为API,但我一直在收到此错误:

E/Tesseract(native): Could not initialize Tesseract API with language=eng!

>我已将文件“eng.traineddata”复制到该位置.

>我使用的是Android Studio 2.1.2(SDK 23)

>使用API​​ 22 Android Lollipop 5.1.1在设备上进行测试(阅读Marshmallow上的权限问题)

这是我正在使用的代码:

public void reads(View view) {

TextView textView = (TextView) findViewById(R.id.textView);

int rotation = 0;

try {

ExifInterface exifInterface = new ExifInterface(mCurrentPhotoPath);

int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL);

switch (orientation){

case ExifInterface.ORIENTATION_ROTATE_90: rotation = 90; break;

case ExifInterface.ORIENTATION_ROTATE_180: rotation = 180; break;

case ExifInterface.ORIENTATION_ROTATE_270: rotation = 270; break;

}

} catch(Exception e) {

}

int w = imageBitmap.getWidth();

int h = imageBitmap.getHeight();

if (rotation != 0) {

Matrix matrix = new Matrix();

matrix.preRotate(rotation);

imageBitmap = Bitmap.createBitmap(imageBitmap,w,h,matrix,false);

} else {

imageBitmap = Bitmap.createBitmap(imageBitmap,h);

}

imageBitmap = imageBitmap.copy(Bitmap.Config.ARGB_8888,true);

TessBaseAPI ReadIt = new TessBaseAPI();

ReadIt.init("/storage/emulated/0/","eng");

ReadIt.setImage(imageBitmap);

String Text = ReadIt.getUTF8Text();

if (Text!=null) textView.setText(Text);

}

我在build.gradle依赖项中使用了这一行:

compile ‘com.rmtheis:tess-two:6.0.2’

另外,我已经通过在特定的目录下载直接复制了名为tessdata的文件夹中的“eng.traineddata”.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值