gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:22:47 26 4
gpt4 key购买 nike

我正在开发一款需要 OCR 的 Android 应用。我决定使用 Tesseract作为 API,但我不断收到此错误:

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

  1. 我已经将文件 "eng.traineddata" 复制到该位置。
  2. 我正在使用 Android Studio 2.1.2 (SDK 23)
  3. 使用 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,0,0,w,h,matrix,false);
} else {
imageBitmap = Bitmap.createBitmap(imageBitmap,0,0,w,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'

此外,我通过在特定指定目录中直接下载,将“eng.traineddata”复制到名为 tessdata 的文件夹中。

最佳答案

Tesseract-two 没有使用最新版本的 OCR 引擎,它使用的是 3.05,因此我们不得不使用来自 here 的数据。 .新数据似乎使用了不同的模型,神经网络。 4.0 之前的模型工作方式不同。

我尝试使用来自 here 的数据和 here .这些数据集仅与最新版本的 tesseract 4.0 ( source ) 兼容,因此如果您使用的是旧版本的 tesseract,它将无法工作。

关于android - 无法使用 language=eng 初始化 Tesseract API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38291379/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com