2013-11-03 62 views
0

我正在嘗試將位圖傳遞給tesseract以獲取讀取的字符。我用這種方式編寫了代碼:在Android中將位圖傳遞給Tesseract

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

這裏缺少什麼?

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) 

回答

0

我指的是釋迦摩尼Gupta的博客後得到了這個工作:http://gaut.am/making-an-ocr-android-app-using-tesseract/

的問題是語言文件失蹤,我手動把他們安置在手機的SD卡。以下是代碼行:

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

錯誤不在該行,它在上面的行。 將位圖的對象直接傳遞給baseApi.setImage();

例如: -

Bitmap bmp;
然後將圖像存儲在bmp中
baseApi.setImage(bmp);

它爲我工作。

相關問題