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

前端之家收集整理的这篇文章主要介绍了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上的权限问题)

这是我正在使用的代码

  1. public void reads(View view) {
  2.  
  3. TextView textView = (TextView) findViewById(R.id.textView);
  4.  
  5. int rotation = 0;
  6.  
  7. try {
  8. ExifInterface exifInterface = new ExifInterface(mCurrentPhotoPath);
  9. int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL);
  10.  
  11. switch (orientation){
  12. case ExifInterface.ORIENTATION_ROTATE_90: rotation = 90; break;
  13. case ExifInterface.ORIENTATION_ROTATE_180: rotation = 180; break;
  14. case ExifInterface.ORIENTATION_ROTATE_270: rotation = 270; break;
  15. }
  16. } catch(Exception e) {
  17.  
  18. }
  19.  
  20. int w = imageBitmap.getWidth();
  21. int h = imageBitmap.getHeight();
  22.  
  23. if (rotation != 0) {
  24. Matrix matrix = new Matrix();
  25. matrix.preRotate(rotation);
  26.  
  27. imageBitmap = Bitmap.createBitmap(imageBitmap,w,h,matrix,false);
  28. } else {
  29. imageBitmap = Bitmap.createBitmap(imageBitmap,h);
  30. }
  31.  
  32. imageBitmap = imageBitmap.copy(Bitmap.Config.ARGB_8888,true);
  33.  
  34. TessBaseAPI ReadIt = new TessBaseAPI();
  35. ReadIt.init("/storage/emulated/0/","eng");
  36. ReadIt.setImage(imageBitmap);
  37.  
  38. String Text = ReadIt.getUTF8Text();
  39.  
  40. if (Text!=null) textView.setText(Text);
  41.  
  42. }

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

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

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

解决方法

你在用 tess-two吗?在你的代码中:
  1. TessBaseAPI ReadIt = new TessBaseAPI();
  2. ReadIt.init("/storage/emulated/0/","eng");

“/ storage / emulated / 0 /”路径应该指向您的数据文件.您必须有一个子目录
名为“tessdata”.看到
https://github.com/rmtheis/tess-two/blob/d7a45fd2e08b7ec315cd1e29d1a7e0c72fb24a66/tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java#L176

阅读更多:
Could not initialize Tesseract API with language=eng!

猜你在找的Android相关文章