gpt4 book ai didi

java - 在 Android 中将位图传递给 Tesseract

转载 作者:行者123 更新时间:2023-12-01 13:53:52 25 4
gpt4 key购买 nike

我正在尝试将位图传递给超立方体以获取读取的字符。我是这样写代码的:

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)

最佳答案

错误不在该行,而是在上面一行。将Bitmap的对象直接传递给baseApi.setImage();

例如:-

位图bmp;
然后将图像存储为bmp
baseApi.setImage(bmp);

这对我有用。

关于java - 在 Android 中将位图传递给 Tesseract,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19751474/

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