加载 tesseract-android-tools (android) 的训练数据
我正在开发 Android 应用程序。 我需要的是训练数据文件的直接路径(初始化超正方体)。 看起来最好的选择是将资源设置为原始。
我以这种方式获取资源 ID(文件名是:deu.traineddata):
int rID = resources.getIdentifier("deu", "raw", "my.code.package");
好的,'rID'> 0,现在得到 Stream :
InputStream is = resources.openRawResource(rID);
好的,'is'!= null。 但现在遇到问题,通过读取“is”IOException 已被抛出,没有堆栈跟踪:
byte[] bytes = new byte[is.available()];
is.read(bytes);
我也尝试从 asset 读取文件,但通过从 InputStream 读取也出现同样的问题。 我做错了什么,还有其他方法来获取资源路径吗? 谢谢 安德烈
I am working on android app.
What I need is directly path to traineddata file (to init tesseract).
Look like best option is to set the resource in raw.
I am getting resource ID this way (file name is : deu.traineddata):
int rID = resources.getIdentifier("deu", "raw", "my.code.package");
OK, 'rID' > 0, now getting Stream :
InputStream is = resources.openRawResource(rID);
ok, 'is' != null.
But now getting problem ,by reading 'is' IOException has been throw, with no stack trace :
byte[] bytes = new byte[is.available()];
is.read(bytes);
I try also to read file from asset , but is the same problem by reading from InputStream.
What i'am doing wrong, ist there any other way to get the resource path ?
thanx
andrej
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看 tesseract-android-tools 中的本机代码(在 jni 下),您将看到该库将访问一个文件。我现在也在同一条船上。经过一番挖掘后,我的计划是将训练好的数据文件作为资源与项目一起存储,并在加载时写入私有文件。
伪代码是这样的:
加载时,检查私有文件,
如果不存在,则从原始目录加载训练数据并写入私有文件。
使用私有文件初始化 tesseract。
参考:
http://developer.android.com/guide/topics/data /data-storage.html#filesInternal
http://developer.android.com/guide/topics/resources/providing-resources.html
干杯
If you look at the native code in tesseract-android-tools (under jni), you will see that the library will access a file. I am in the same boat at the moment. After some digging, my plan is to store the traineddata file as a resource along with the project, and write to the private file on load.
The pseudo code is something like this:
on load, check for private file,
if it doesn't exist, load the traineddata from raw dir and write to the private file.
initialize tesseract with the private file.
ref:
http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
http://developer.android.com/guide/topics/resources/providing-resources.html
Cheers