简体   繁体   English

在Android中将位图传递给Tesseract

[英]Passing bitmap to Tesseract in Android

I am trying to pass a bitmap to tesseract to get the read characters. 我正在尝试将一个位图传递给tesseract以获取读取的字符。 I have written the code in this way: 我以这种方式编写了代码:

TessBaseAPI baseApi = new TessBaseAPI();
baseApi.setImage(ReadFile.readBitmap(charscropped));
String capturedChars = baseApi.getUTF8Text(); // app crashes in this line

What is missing here? 这里缺少什么?

Logcat output: Logcat输出:

11-03 15:00:54.473: E/AndroidRuntime(5674): FATAL EXCEPTION: main
11-03 15:00:54.473: E/AndroidRuntime(5674): java.lang.NullPointerException
11-03 15:00:54.473: E/AndroidRuntime(5674):     at com.googlecode.tesseract.android.TessBaseAPI.getUTF8Text(TessBaseAPI.java:409)
11-03 15:00:54.473: E/AndroidRuntime(5674):     at com.elottery.ocr.Test$4.onClick(Test.java:110)
11-03 15:00:54.473: E/AndroidRuntime(5674):     at android.view.View.performClick(View.java:3567)
11-03 15:00:54.473: E/AndroidRuntime(5674):     at android.view.View$PerformClick.run(View.java:14224)
11-03 15:00:54.473: E/AndroidRuntime(5674):     at android.os.Handler.handleCallback(Handler.java:605)
11-03 15:00:54.473: E/AndroidRuntime(5674):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-03 15:00:54.473: E/AndroidRuntime(5674):     at android.os.Looper.loop(Looper.java:137)
11-03 15:00:54.473: E/AndroidRuntime(5674):     at android.app.ActivityThread.main(ActivityThread.java:4517)
11-03 15:00:54.473: E/AndroidRuntime(5674):     at java.lang.reflect.Method.invokeNative(Native Method)
11-03 15:00:54.473: E/AndroidRuntime(5674):     at java.lang.reflect.Method.invoke(Method.java:511)
11-03 15:00:54.473: E/AndroidRuntime(5674):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
11-03 15:00:54.473: E/AndroidRuntime(5674):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
11-03 15:00:54.473: E/AndroidRuntime(5674):     at dalvik.system.NativeStart.main(Native Method)

The error is not in that line it is in above line. 错误不在该行中,而是在上一行中。 Pass the Bitmap's object directly to baseApi.setImage(); 将位图的对象直接传递到baseApi.setImage();

Like Eg:- 例如:

Bitmap bmp; 位图bmp;
and then store the image in bmp 然后将图像存储在bmp中
baseApi.setImage(bmp); baseApi.setImage(bmp);

It worked for me. 它为我工作。

I got this working after referring to Gautam Gupta's blog: http://gaut.am/making-an-ocr-android-app-using-tesseract/ 在参考Gautam Gupta的博客后,我开始了这项工作: http//gaut.am/making-an-ocr-android-app-using-tesseract/

The problem was that language files were missing and I manually placed them in phone sdcard. 问题是语言文件丢失了,我手动将它们放在电话sdcard中。 Following are the lines of code: 以下是代码行:

TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init("/mnt/sdcard/tesseract", "eng"); 
baseApi.setImage(ReadFile.readBitmap(charscropped));
String capturedChars = baseApi.getUTF8Text();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM